rc_receiver_driving.ino 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /////////////////////////////////////////////////////////////////////////
  2. // Configuration
  3. //////////////////////////////////////////////////
  4. #define MAX_POWER_PERCENT 90 // The maximum percentage on time, used to decrease average voltage to the motor.
  5. #define SCAN_DELAY 10 // Delay between updates in ms
  6. #define AVG_OVER_MILLIS 1500 // Number of milliseconds to average the speed over
  7. /////////////////////////////////////////////////////////////////////////
  8. // Output config
  9. /////////////////////////////////////////////////////////////////////////
  10. //#define SCAN_MODE // If set, output channel values rather than driving the robot.
  11. //#define DEBUG // If set, adjust timings and output debug lines
  12. #ifdef DEBUG
  13. #define SCAN_DELAY 1000
  14. #define AVG_OVER_MILLIS 3000
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////
  17. // Internal values
  18. /////////////////////////////////////////////////////////////////////////
  19. #define LEFT 0
  20. #define RIGHT 1
  21. #define OUTPUT_RANGE 255 // The maximum value for PWM output
  22. #define THROT_RANGE 1000 // Value output by throttle (-THROT_RANGE to THROT_RANGE), later constrained to OUTPUT_RANGE
  23. #define STEER_RANGE THROT_RANGE/2 // Value output by steering (-STEER_RANGE to STEER_RANGE) to adjust throttles
  24. #define AVG_PERIODS AVG_OVER_MILLIS/SCAN_DELAY // Number of periods to average the speed over (reduces random variances)
  25. /////////////////////////////////////////////////////////////////////////
  26. // Channel pins
  27. /////////////////////////////////////////////////////////////////////////
  28. #define LOW_CHANNEL 1
  29. #define NUM_CHANNELS 6
  30. // Channel pins. Using numbers 1-6 for clarity, so using a bad value in index 0.
  31. const byte channels[7] = {255, 8,9,10,11,12,13};
  32. // How long (in microseconds) the channel is being held high for.
  33. int channelVals[NUM_CHANNELS + 1];
  34. /////////////////////////////////////////////////////////////////////////
  35. // Channel values
  36. /////////////////////////////////////////////////////////////////////////
  37. #define DEAD_MAN_MILLIS 100 // Time to wait after last interrupt before figuring the controller turned off
  38. // Right horizontal (steering)
  39. #define STEER_CHANNEL 1
  40. #define STEER_LEFT 1300
  41. #define STEER_RIGHT 1690
  42. #define STEER_NONE 1500
  43. #define STEER_DEAD_ZONE 30 // 10% of the range is dead zone
  44. // Right vertical (throttle)
  45. #define THROT_CHANNEL 2
  46. #define THROT_MAX 1940
  47. #define THROT_MIN 1160
  48. #define THROT_NONE 1510// Halfway range
  49. #define THROT_DEAD_ZONE 30 // approx 10% of the range is dead
  50. #define THROT_OFF 0 // Anything below this means the throttle switch (upper right) is off
  51. #define CH_4_MIN 0
  52. #define CH_4_MAX 0
  53. // Right knob
  54. #define LIGHT_CHANNEL 5
  55. #define LIGHT_MIN 990
  56. #define LIGHT_MAX 1990
  57. // Left knob
  58. #define SPEED_CHANNEL 6
  59. #define SPEED_MIN 1000
  60. #define SPEED_MAX 2000
  61. /////////////////////////////////////////////////////////////////////////
  62. // Output pins
  63. /////////////////////////////////////////////////////////////////////////
  64. #define LEFT_MOTOR_DIRECT_PIN 4
  65. #define LEFT_MOTOR_PIN 5
  66. #define RIGHT_MOTOR_PIN 6
  67. #define RIGHT_MOTOR_DIRECT_PIN 7