definitions.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #ifndef DEFINITIONS_MODULE
  2. #define DEFINITIONS_MODULE
  3. #import <Arduino.h>
  4. // CONST_PIN_TYPE types cannot change their values after first declartion
  5. // typedef static const unsigned int CONST_PIN_TYPE;
  6. #define CONST_PIN_TYPE static const unsigned int // typedef is not working, dedbug later
  7. typedef unsigned int PIN_TYPE;
  8. typedef int16_t ANGLE;
  9. typedef unsigned int LANE_ID;
  10. struct SensorTouched
  11. {
  12. bool change_happened;
  13. bool left_sensor;
  14. bool right_sensor;
  15. SensorTouched(bool left_touched, bool right_touched)
  16. {
  17. this->change_happened = false;
  18. this->left_sensor = left_touched;
  19. this->right_sensor = right_touched;
  20. }
  21. };
  22. struct SubjectLocation
  23. {
  24. bool block_detected;
  25. ANGLE angle;
  26. uint16_t x;
  27. uint16_t y;
  28. };
  29. struct Lane
  30. {
  31. LANE_ID lane_id;
  32. PIN_TYPE reward_sensor;
  33. ANGLE region_start_angle;
  34. ANGLE region_end_angle;
  35. };
  36. struct MotorDurationEntry
  37. {
  38. bool activated;
  39. PIN_TYPE motor_id;
  40. long int activation_time;
  41. long int timeout_period;
  42. };
  43. struct GlobalState
  44. {
  45. int Servo1_pos = 0;
  46. bool Servo1_dir = true;
  47. static const LANE_ID NUM_OF_LANES = 4;
  48. Lane lanes[NUM_OF_LANES];
  49. // Guaranteed bound value must be divisble by num of lanes
  50. static const int GUARANTEED_RANDOM_BOUND = NUM_OF_LANES*1;
  51. LANE_ID lane_shuffle_list[GUARANTEED_RANDOM_BOUND];
  52. size_t shuffle_list_index;
  53. bool was_inside_lane;
  54. LANE_ID current_lane;
  55. LANE_ID reward_lane_id;
  56. bool reward_direction;
  57. bool rotation;
  58. SubjectLocation last_subject_location;
  59. bool actuator_at_max_push;
  60. bool actuator_at_min_pull;
  61. static const long int MAX_PUSH_TIMEOUT = 1000;
  62. static const long int MAX_PUSH_WAIT = 100;
  63. static const long int ALLOWED_REWARD_TIMEOUT = 1000;
  64. static const long int NO_REWARD_TIMEOUT = 100;
  65. static const long int PEIZO_TIMEOUT = 1000;
  66. long int motor_timeout_duration;
  67. long int max_push_current_duration;
  68. bool actuator_duration_activated;
  69. bool chose_new_lane;
  70. bool reward_given;
  71. bool in_first_lane;
  72. MotorDurationEntry *peizo_motor_entry;
  73. LANE_ID last_reported_lane; // Initially report non existing lane
  74. byte last_reported_light_status; // Assign any random initial value
  75. byte last_reported_actuator_status; // It's type is Actuator::State
  76. bool reported_motor_max_distance;
  77. bool reported_motor_min_distance;
  78. bool reported_motor_max_wait;
  79. bool sensor_was_touched;
  80. // Change to fit the number of motors that you have in your system
  81. static const size_t MOTOR_DURATION_ENTERIES_SIZE = 6;
  82. MotorDurationEntry motor_duration_entries[MOTOR_DURATION_ENTERIES_SIZE];
  83. int actuator_max_pwm_distance = 700;
  84. static const long int SOLENOID_DURATION = 200;
  85. unsigned int trial_number;
  86. static const long int SAME_SENSOR_MAX_THRESHOLD = 5;
  87. static const long int FORCE_OTHER_SENSOR = 3;
  88. static const long int FEEDBACK_AUTOMATED_REWARD_THRESHOLD = 3;
  89. bool last_sensor_touched_left;
  90. unsigned int same_sensor_touch_count;
  91. bool in_force_sensor_mode;
  92. bool is_force_sensor_left;
  93. int miss_or_wrong_touch_count;
  94. bool is_automated_reward;
  95. long int delayed_report;
  96. };
  97. struct DistancesStruct
  98. {
  99. uint16_t x_threshold_min;
  100. uint16_t x_threshold_max;
  101. uint16_t y_threshold_min;
  102. uint16_t y_threshold_max;
  103. uint16_t y_motor_threshold;
  104. DistancesStruct ()
  105. {
  106. this->x_threshold_min = 100;
  107. this->x_threshold_max = 350;
  108. this->y_threshold_min = 2;
  109. this->y_threshold_max = 80;
  110. this->y_motor_threshold = 45;
  111. }
  112. } Distances;
  113. struct StatsMessage
  114. {
  115. byte event_id;
  116. char* msg;
  117. short parameter;
  118. StatsMessage(byte event_id, char* msg, short parameter)
  119. {
  120. this->event_id = event_id;
  121. this->msg = msg;
  122. this->parameter = parameter;
  123. }
  124. StatsMessage(byte event_id, char* msg)
  125. {
  126. this->event_id = event_id;
  127. this->msg = msg;
  128. this->parameter = -1;
  129. }
  130. };
  131. #endif