reporter.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef REPORTER_MODULE
  2. #define REPORTER_MODULE
  3. #import <Arduino.h>
  4. #include "definitions.h"
  5. #define PWM_(INDEX, TOTAL) (byte)((255.0/TOTAL)*INDEX)
  6. void reportPWM (PIN_TYPE pwm_pin, byte value)
  7. {
  8. #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) // If Arduino Mega is used
  9. analogWrite(pwm_pin, value);
  10. #endif
  11. }
  12. struct CurrentLaneNumPWM { enum : byte
  13. {
  14. Unknown = 0,
  15. Lane1 = PWM_(1,4),
  16. Lane2 = PWM_(2,4),
  17. Lane3 = PWM_(3,4),
  18. Lane4 = PWM_(4,4)
  19. };};
  20. struct CorrectLaneNumPWM { enum : byte
  21. {
  22. Unknown = 0,
  23. Lane1 = PWM_(1,4),
  24. Lane2 = PWM_(2,4),
  25. Lane3 = PWM_(3,4),
  26. Lane4 = PWM_(4,4)
  27. };};
  28. struct LaneStatePwm { enum : byte
  29. {
  30. Unknown = 0,
  31. InsideLane = PWM_(1,2),
  32. OutsideLane = PWM_(2,2),
  33. };};
  34. // Copied from "TPixy.h"
  35. // Pixy x-y position values
  36. #define PIXY_MIN_X 0L
  37. #define PIXY_MAX_X 319L
  38. #define PIXY_MIN_Y 0L
  39. #define PIXY_MAX_Y 199L
  40. struct PixyXPwmStruct
  41. {
  42. byte convert (float x) /*x is uint16_t*/
  43. {
  44. return (byte)((x / PIXY_MAX_X) * 255);
  45. }
  46. } PixyXPwm;
  47. struct PixyYPwmStruct
  48. {
  49. byte convert (float y) /*y is uint16_t*/
  50. {
  51. return (byte)((y / PIXY_MAX_Y) * 255);
  52. }
  53. } PixyYPwm;
  54. struct PixyAnglePwmStruct
  55. {
  56. byte convert (int angle) /*angle is int16_t*/
  57. {
  58. angle = (angle + 360) % 360;
  59. return (byte)((angle / 360.0) * 255);
  60. }
  61. } PixyAnglePwm;
  62. struct LaneLedPwm { enum : byte
  63. {
  64. Off = PWM_(0,1),
  65. On = PWM_(1,1),
  66. };};
  67. struct RotationDirectionPwm { enum : byte
  68. {
  69. Unknown = 0,
  70. Clockwise = PWM_(1,2),
  71. AntiClockwise = PWM_(2,2),
  72. // MIXED = PWM_(3,3),
  73. };};
  74. struct LickDirectionPwm { enum : byte
  75. {
  76. Unknown = 0,
  77. Untouched = PWM_(1,3),
  78. Right = PWM_(2,3),
  79. Left = PWM_(3,3),
  80. };};
  81. struct DecisionResultPwm { enum : byte
  82. {
  83. Unknown = 0,
  84. Correct = PWM_(1,3),
  85. Wrong = PWM_(2,3),
  86. Miss = PWM_(3,3),
  87. };};
  88. struct RewardResultPwm { enum : byte
  89. {
  90. Unknown = 0,
  91. Given = PWM_(1,3),
  92. NotGiven = PWM_(2,3),
  93. AutomatedGiven = PWM_(3,3),
  94. };};
  95. struct RewardStatePwm { enum : byte
  96. {
  97. Unknown = 0,
  98. Normal = PWM_(1,3),
  99. ForcedLeft = PWM_(2,3),
  100. ForcedRight = PWM_(3,3),
  101. };};
  102. struct PiezoAlarmPwm { enum : byte
  103. {
  104. Off = PWM_(0,1),
  105. On = PWM_(1,1),
  106. };};
  107. struct SolenoidPwm { enum : byte
  108. {
  109. Unknown = 0,
  110. LeftOpen = PWM_(1,3),
  111. BothOff = PWM_(2,3),
  112. RightOpen = PWM_(3,3),
  113. };};
  114. struct ActuatorPwm { enum : byte
  115. {
  116. Unknown = 0,
  117. MaxDistance = PWM_(1,4),
  118. Pushing = PWM_(2,4),
  119. Retracting = PWM_(3,4),
  120. MinDistance = PWM_(4,4),
  121. };};
  122. #endif