Logarithmically coding a gamepad java

I am new to Java and want to program the analog stick logarithmically can anybody send an example code any and all help will be greatly appreciated

1 Like

Programming a joystick to send scaled motor commands logarithmically is an interesting design choice. This means the joystick will have slightly more fine grain control when near its maximum input (but only slightly). This is usually the opposite of what many teams want. Take a look at the graph below. The X axis represents the value of the joystick and the Y axis represents the value sent to the motor. Both of these are -1 to 1 in WPILib but we will just look at the positive side for now.

Looking at this graph, what do you want your function from joystick input to motor output to be? Note that I have put the equations in order on the left hand side from the top most function to the bottom most function.


Thank you for the help

This isn’t quite what you asked, but if you use the default Differential Drive class, you can easily square the inputs: https://docs.wpilib.org/en/latest/docs/software/actuators/wpi-drive-classes.html?#squaring-inputs-input-deadband

This is what I did in labview a number of years back.

you can use it as a base to implement the same code in java. We have found that it improves driver control with things like acceleration. Don’t forget to implement deadzones properly
otherwise a lot of the benefit of non linear mapping is lost to just being cut off.

Thank you