Tank Drive - Joystick Control
In tank drive, one or two joysticks can be used, but typically two joysticks are used - one joystick is use to control the left half of the drivetrain, and the other joystick is used to control the other half. Only forward and backwards motions of the joystick are used for affecting the drivetrain.
There are a few different control mappings to affect how a certain amount of joystick movement is needed to change the requested speed of the drivetrain:
- Linear The simplest and most straightforward of the control mappings.
- Quadratic Designed to give much finer control over slow movements.
- Linear/Quadratic Average An averaging of linear and quadratic.
- S-Curve Finer control than linear in first half of travel, faster control than linear in second half.
Important Note Regarding Reverse
The equations given are of the form y = f(x), where x is the joystick position, and y is the output value. As most of these equations are not symmetric through the Origin, the expected input is from 0 to 1 (inclusive) - that is, for when the joysticks are pushed forward. The equations will not work directly for negative (reversing) input (when the joysticks are pulled backwards).
In order to accomodate negative values, absolute values will need to be used in most cases (except linear). These functions should take the following form.
if (x < 0) x1 = abs(x); y1 = f(x1); y = -1 * y1 end if;
or condensed to
if (x < 0) y = -1 * f(abs(x)); end if;
Linear
The simplest and most straightforward of the control mappings.
- y = x
- Advantages: Simple, linear response, easy to program, easy to drive
- Disadvantages: Does not give fine control for slow movements
Quadratic
Designed to give much finer control over slow movements.
- y = x2
- Advantages: Gives very fine control over slow movements
- Disadvantages: Drivers have complained that it feels too dead and sluggish when getting started.
Image: Comparison of Linear, Quadratic, and Linear Quadratic Average
Linear/Quadratic Average
An averaging of linear and quadratic.
- y = (x2 + x) / 2
- Advantages: Gives finer control over slow movements compared to linear, without feeling dead like quadratic. (At least in theory.)
- Disadvantages: Overall slower feeling compared to linear
Note: if desired, you can bias the curve more towards linear or quadratic. Instead of giving equal weights and dividing by 2, you can use percentage multipliers (remove the ‘/ 2’). For example, to give a 70% weighting to linear, use the following:
- y = (0.3 * x2 + 0.7 * x)
S-Curve
Finer control than linear in first half of travel, faster control than linear in second half.
S-Curve 1
- For 0 <= x <= 0.5
- y = ((2x2) + x) / 2
- For x > 0.5
- y = 1 - ((2(x-1.5)2) + (x-1.5)) / 2
- For 0 <= x <= 0.5
- Advantages: Gives finer control for slow movements, without feeling dead like quadratic. Gives faster control than linear in second half. Feels zippy when past about 1/3 or 1/2 travel.
- Disadvantages: Does not feel linear. Could be an issue in feel for driver. They may love it. They may hate it.
Image: S-Curve 1 Mapping
S-Curve 2
Slightly more curvey - more control (slower) down low
- For 0 <= x <= 0.5
- y = ((6x2) + x) / 4
- For 0 <= x <= 0.5
- For x > 0.5
- TBD (part 1 inverted) or same as S-Curve 1
- For x > 0.5