Update explanation theory of joystick control authored by Jeffrey George Fisher's avatar Jeffrey George Fisher
# Explanation: Theory of Joystick Control
By: Jeffrey Fisher
<br/>For: [Joystick Control](/training/joystick-control)
By: Jeffrey Fisher, Alex Yelovich
<br/>For: [Module: Joystick Control](/training/joystick-control)
[[_TOC_]]
......@@ -16,7 +16,11 @@ Goals:
# Control schemes
## Tank control
### General idea
### Transformation
The `SDL` library returns joystick axes with the C type `int16_t`, which is a signed 16-bit integer. The range of that type is $[-2^15, 2^15 - 1] = [-32768, 32767]$.
## Arcade control
......@@ -24,10 +28,14 @@ Goals:
## Linear scaling
The simplest method of scaling is linear. You take the input domain and stretch or squish it (if necessary) to fit the desired output range. For example you could convert a number in $`[-2^{32}, 2^{32} - 1]`$ (joystick) to a number in $`[0, 1]`$ (percentage of thrust).
The simplest method of scaling is linear. You take the input domain and stretch or squish it (if necessary) to fit the desired output range. For example you could convert a number in $`[-255, 255]`$ (joystick) to a number in $`[-100, 100]`$ (percentage of thrust).
This is fine, but can be a bit "jumpy". It can be difficult to make small movements on a joystick, especially one on a relatively cheap controller (I'm sure airplane controls are a lot nicer mechanically). The linear scaling method leaves making precise movements up to the physical ability of the user and the controller.
## A better method: Cubic scaling
![scaling](uploads/26dfa9ba58e4b646d9d661b804649bf7/scaling.png){width=60%}
Working with percentages in the interval $[0, 1]$.
$(0)^3 = 0$ and $(1)^3 = 1$, so we can still easily go full throttle when we need to. But notice that the cubic grows more slowly than `y=x` (in the interval $[0, 1]$). This makes it easier to input precise movements, because the joystick is less reactive and jumpy for small inputs.