Joystick recentering,scaling example code

The Code file repository is sometimes difficult to get to, so I’m reposting description and code (bugs1_c.txt) here, for discussion:

This example c code to make it easy to stop motors from humming when robot is stopped.

Push any vexnet shoulder button to set the “center” variable to the current joystick value.

Joystick scaling function subtracts “center” value from current joystick value. If it hasn’t moved from last centering operation, then value will be zero.

Other joystick scaling features include

  • minimum power (Jordan’s idea)
  • adjustable power law scaling,
    – Fabs() so Even powers (eg 2) will work correctly.
    – Pow() function, so Fractional powers (eg 1.3) also work correctly.
  • deadband

Does not include digital Gearup/Geardown from Simulink example, or Jordan’s “half-speed” mode.

Written in EasyCv4, but concepts apply everywhere.

I can’t find how to open main.h as text, so you’ll have to intuit all the variable declarations.
bugs1_c.txt (2.98 KB)