PS4 Controller?

We are trying to use a PS4 controller to drive our robot but we are getting weird values from it.

What sort of weird values? What code are you using to get those values?

We are just using the WPIlib joystick code to get them. When the joystick is not pressed it bounces from 0.1-0.2.

This is not uncommon for many controllers. You need to program in a deadband - perhaps a wrapper class for the controller could implement this - to ignore values below the threshold (and perhaps scale the joystick output across the rest of the range). This is an issue common to several controllers: PS4, Xbox 360, etc.


I just created a class DeadBand and put this in it. Which I’m sure I copied from CD. My Java Kung Fo is not strong, but getting better.

package frc.robot;

  • A class to try to tone down the deadband in the joysticks to make

  • the robot less jumpy.

  • Takes in the axis from a joystick, checks if it’s under the deadBandrate

  • set the axis to 0.0 and return it.
    public class DeadBand {

    public static final double deadBandrate = 0.15; //<-- Change this up and down to a setting that works best for your controller.

    public double SmoothAxis(double joyStickAxis){

    if (Math.abs(joyStickAxis) < deadBandrate) {
    joyStickAxis = 0.0;
    else {
    if (joyStickAxis>0.0) {
    joyStickAxis = (joyStickAxis - deadBandrate) / (1.0 - deadBandrate);
    else {
    joyStickAxis = (joyStickAxis - -deadBandrate) / (1.0 - deadBandrate);
    }// ******** end if > *******
    }// ****** end if <

    return joyStickAxis;

    } // *********************** end of SmoothAxis **********************

}// ************************ end of Class DeadBand *********************

Then in my Teleop I have


Again, sorry for the bad Java. Hope this helps in someway, and you and your team have a great season.