Joystick deadband calibration centering work-around

Re-quoting this from tail of the 269 vs 393 discussion, to put in its own thread.
This code is a work-around for the common problem of Vexnet Joysticks -
The imperfect centering of analog joysticks.
Common symptoms of this problem:

  • Motors hum when they should be stopped and quiet.
  • Motors slowly turn at startup when they should be stopped.
  • Jiggling the stick is required to stop the motors.
  • Large deadband settings required to stop the motors without jiggling the stick.

Overview:
Record current position of joystick as “center” when some button is pressed.
When reading joystick values, subtract off the recorded “center” value.

These example EasyCv4 code chunks also demonstrate a coding style that uses predefined Constants like ‘Joy1=1’ to make the code more self-documenting.
EG: GetJoystickAnalog(1,2); does that mean joystick1, stick2, or joy2, stick1?
New: GetJoystickAnalog( JOY1, STK_2); // much more clear

Also demonstrated is RCScaling code, which is easier to understand visually if you copy the math to a spread sheet and plot the shape of the output vs input, for different parameters.

Potential Bugs/pitfalls:

  • Doesn’t work for EasyC provided JoysticktoMotor or Arcade/Tank/Holo functions, so you’ll have to write your own; (thats a feature!)
  • Didn’t write it as a wrapper eg: myGetJoystickAnalog(), just provided this example
  • Doesn’t include limit check, so center-corrected values can be out of (-127,+127) range. (that would be good to put into a wrapper)
  • Not as good as “real” joystick calibration method, which also sets min,max limits correctly, (but this is simpler to trigger in the middle of a game)
  • Pressing “center” button when joysticks are deliberately NOT centered may have unexpected consequences when the joysticks become centered again.

Let me know if you have questions on the code.