I’ve been working on a way to increase precision of the analog playstation 2 controller inputs.
I’ve got a rover with an arm on top, and my goal here is to drastically slow down, for example, the base rotate. while it’s easy to just slow down the entire thing by a factor, this would also decrease the maximum speed when the controller is pushed fully outward. If one would manage to get the input scale exponentially, you’d get a much bigger band of slow movement and still retain maximum speed when pushing the stick outward fully.
This comes straight out of Rover_v1.2. (Edit: fixed problem)
IF ABS(Dualshock(3) - 128) > DeadZone THEN ;Right Stick L/R
;BaseAngle1 = BaseAngle1 -(Dualshock(3) - 128)/4 ;Base Rotation, this is the original.
IF (Dualshock(3) - 128) >= 0 THEN
BaseAngle1 = BaseAngle1 -(((Dualshock(3) - 128)*(Dualshock(3) - 128))*128/16129)/4 ;Base Rotation, exponential positive
ELSE
BaseAngle1 = BaseAngle1 -(-((Dualshock(3) - 128)*(Dualshock(3) - 128))*128/16384)/4 ;Base Rotation, exponential negative
ENDIF
ENDIF
You’ll already notice a big increase in the sensitive area of your stick, and you still keep the maximum speed at full extension.
However, I’d suggest using a combination of both exponential and linear for the best effect:
IF ABS(Dualshock(3) - 128) > DeadZone THEN ;Right Stick L/R
;BaseAngle1 = BaseAngle1 -(Dualshock(3) - 128)/4 ;Base Rotation, this is the original.
IF (Dualshock(3) - 128) >= 0 THEN
BaseAngle1 = BaseAngle1 -(((Dualshock(3) - 128)*(Dualshock(3) - 128))*128/16129)/6 ;Base Rotation, exponential positive
ELSE
BaseAngle1 = BaseAngle1 -(-((Dualshock(3) - 128)*(Dualshock(3) - 128))*128/16384)/6 ;Base Rotation, exponential negative
ENDIF
ENDIF
Now, the entire range has been decreased, thus slowing everything down linearly. Your maximum speed is less now, AND your range is exponential. I reckon this bit of programming can be further tweaked until your only limit is your servo’s precision.