-
Notifications
You must be signed in to change notification settings - Fork 3
/
definitions.h
196 lines (161 loc) · 6.47 KB
/
definitions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#ifndef DEFINITIONS_MODULE
#define DEFINITIONS_MODULE
#import <Arduino.h>
// CONST_PIN_TYPE types cannot change their values after first declartion
// typedef static const unsigned int CONST_PIN_TYPE;
#define CONST_PIN_TYPE static const unsigned int // typedef is not working, dedbug later
typedef unsigned int PIN_TYPE;
typedef int16_t ANGLE;
typedef unsigned int LANE_ID;
struct SensorTouched
{
bool change_happened;
bool left_sensor;
bool right_sensor;
SensorTouched(bool left_touched, bool right_touched)
{
this->change_happened = false;
this->left_sensor = left_touched;
this->right_sensor = right_touched;
}
};
struct SubjectLocation
{
bool block_detected;
ANGLE angle;
uint16_t x;
uint16_t y;
};
struct Lane
{
LANE_ID lane_id;
PIN_TYPE reward_sensor;
ANGLE region_start_angle;
ANGLE region_end_angle;
};
struct MotorDurationEntry
{
bool activated;
PIN_TYPE motor_id;
long int activation_time;
long int timeout_period;
};
struct GlobalState
{
static const LANE_ID NUM_OF_LANES = 4;
Lane lanes[NUM_OF_LANES];
// Guaranteed boind value must be divisble by num of lanes
static const int GUARANTEED_RANDOM_BOUND = NUM_OF_LANES*1;
LANE_ID lane_shuffle_list[GUARANTEED_RANDOM_BOUND];
size_t shuffle_list_index;
bool was_inside_lane;
LANE_ID current_lane;
LANE_ID reward_lane_id;
SubjectLocation last_subject_location;
bool actuator_at_max_push;
static const long int MAX_PUSH_TIMEOUT = 3000;
static const long int MAX_PUSH_WAIT = 100;
static const long int ALLOWED_REWARD_TIMEOUT = 2500;
static const long int NO_REWARD_TIMEOUT = 100;
static const long int PEIZO_TIMEOUT = 1000;
long int motor_timeout_duration;
long int max_push_current_duration;
bool actuator_duration_activated;
bool chose_new_lane;
bool reward_given;
MotorDurationEntry *peizo_motor_entry;
LANE_ID last_reported_lane; // Initially report non existing lane
byte last_reported_light_status; // Assign any random initial value
byte last_reported_actuator_status; // It's type is Actuator::State
bool reported_motor_max_distance;
bool reported_motor_max_wait;
bool sensor_was_touched;
// Change to fit the number of motors that you have in your system
static const size_t MOTOR_DURATION_ENTERIES_SIZE = 4;
MotorDurationEntry motor_duration_entries[MOTOR_DURATION_ENTERIES_SIZE];
static const int actuator_max_pwm_distance = 870;
static const long int SOLENOID_DURATION = 120;
unsigned int trial_number;
static const long int SAME_SENSOR_MAX_THRESHOLD = 500;
static const long int FORCE_OTHER_SENSOR = 3;
static const long int FEEDBACK_AUTOMATED_REWARD_THRESHOLD = 3;
bool last_sensor_touched_left;
unsigned int same_sensor_touch_count;
bool in_force_sensor_mode;
bool is_force_sensor_left;
int miss_or_wrong_touch_count;
bool is_automated_reward;
};
struct DistancesStruct
{
uint16_t x_threshold_min;
uint16_t x_threshold_max;
uint16_t y_threshold_min;
uint16_t y_threshold_max;
uint16_t y_motor_threshold;
DistancesStruct ()
{
this->x_threshold_min = 100;
this->x_threshold_max = 350;
this->y_threshold_min = 2;
this->y_threshold_max = 90;
this->y_motor_threshold = 35;
}
} Distances;
struct StatsMessage
{
byte event_id;
char* msg;
short parameter;
StatsMessage(byte event_id, char* msg, short parameter)
{
this->event_id = event_id;
this->msg = msg;
this->parameter = parameter;
}
StatsMessage(byte event_id, char* msg)
{
this->event_id = event_id;
this->msg = msg;
this->parameter = -1;
}
};
struct StatsStruct
{
StatsMessage ENTERED_LANE(short lane) {return StatsMessage(0, "Entered lane\0", lane + 1);}
StatsMessage EXITED_LANE(short lane) {return StatsMessage(1, "Exited lane\0", lane + 1);}
StatsMessage MOTOR_PUSHED() {return StatsMessage(10, "Motor is pushed\0");}
StatsMessage MOTOR_PULLED() {return StatsMessage(11, "Motor is pulled\0");}
StatsMessage MOTOR_MAX_RANGE() {return StatsMessage(12, "Motor is at max distance\0");}
// Next one is not reported yet
StatsMessage MOTOR_MIN_RANGE() {return StatsMessage(13, "Motor is at min distance\0");}
StatsMessage MOTOR_WAIT_DONE() {return StatsMessage(14, "Motor wait time is is done.\0");}
StatsMessage ENTERED_LANE_RANGE(short lane) {return StatsMessage(20, "Entered rotation range of lane\0", lane + 1);}
StatsMessage CORRECT_SENSOR_TOUCHED() {return StatsMessage(30, "Correct sensor touched\0");}
StatsMessage WRONG_SENSOR_TOUCHED() {return StatsMessage(31, "Wrong sensor touched\0");}
StatsMessage RIGHT_SENSOR_TOUCHED() {return StatsMessage(35, "R-located sensor touched\0");}
StatsMessage LEFT_SENSOR_TOUCHED() {return StatsMessage(36, "L-located sensor touched\0");}
// Next one is not reported yet
StatsMessage OTHER_SENSOR_TOUCHED(short sensor) {return StatsMessage(37, "Other sensor touched - Sensor nr.\0", sensor);}
StatsMessage REWARD_GIVEN() {return StatsMessage(40, "Giving reward\0");}
StatsMessage REWARD_NOT_GIVEN() {return StatsMessage(41, "Not giving reward\0");}
StatsMessage MISS_DECISION() {return StatsMessage(42, "No Decision was made in time\0");}
StatsMessage NEW_LANE(short lane) {return StatsMessage(50, "New lane chosen\0", lane + 1);}
StatsMessage NEW_TRIAL(short trial) {return StatsMessage(55, "Trial number\0", trial);}
StatsMessage LIGHT_ON() {return StatsMessage(60, "Cue light turned on\0");}
StatsMessage LIGHT_OFF() {return StatsMessage(61, "Cue light turned off\0");}
StatsMessage SOLENOID_RIGHT_ON() {return StatsMessage(70, "R-located solenoid turned on\0");}
StatsMessage SOLENOID_RIGHT_OFF() {return StatsMessage(71, "R-located solenoid turned off\0");}
StatsMessage SOLENOID_LEFT_ON() {return StatsMessage(72, "L-located solenoid turned on\0");}
StatsMessage SOLENOID_LEFT_OFF() {return StatsMessage(73, "L-located solenoid turned off\0");}
StatsMessage FORCE_SENSOR_ON(bool is_left)
{
char* msg = is_left ? (char*)"Force sensor mode on (left)\0" :
(char*)"Force sensor mode on (right)\0";
return StatsMessage(80, msg, is_left);
}
StatsMessage FORCE_SENSOR_OFF() {return StatsMessage(81, "Force sensor mode is off\0");}
StatsMessage FEEDBACK_AUTOMATED_ON() {return StatsMessage(82, "Feedback automated on\0");}
StatsMessage FEEDBACK_AUTOMATED_OFF() {return StatsMessage(83, "Feedback automated off\0");}
} Stats;
#endif