rc_receiver_driving.ino 2.4 KB

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