rc_receiver_driving.ino 2.4 KB

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