Coasting Problems

This summer, I switched my team’s robot over from LabView to Java and have successfully moved everything over except for steering. When I attempt to drive with and then release the joysticks, the robot will began crawling in the direction it was previously moving.

From what I can tell, it’s an issue reading in joystick values, for which I’ve set up some wiggle room with a pair of if statements. Unfortunately, the end values of the joysticks keep changing making it near impossible for me to set up a threshold.

Any help is appreciated.

Thanks in advance,
Matt_4505

You could post your code so others could help you troubleshoot, but first I suggest:

  • Use the console or dashboard to display the value of the stick, and “let go” a few times. Take note of the range of values it can be and make that your deadzone (the range in which the input shouldn’t cause the motors to move).
  • Make sure that when you are in the deadzone, that you are sending a command of 0.0 (“stop”), not just “do nothing”. Sending no command would cause the motor to move at the last known value (this one sounds like your issue).
  • Your joystick may just be loose?

The following assume you are using the RobotDrive VIs in LabVIEW and the robotDrive object in Java.

LabVIEW, by default, squares the inputs joystick inputs. This makes a small input value even smaller and might account for what you are seeing. The Java library also squares the joystick inputs by default, but makes it easier to change to not squaring. Which are you using?

In the Java library, robot drive objects declare jaguars unless speed controller objects are passed to it. If you are using a different type of speed controller (eg Victor or Talon), you may see weird behavior like neutral offsets. In LabVIEW, it’s more obvious how to change to the appropriate speed controller type.

I’m using the Java Library. My inputs are from the .getY() values of the joysticks. The motors are being controlled through: tankDrive(leftJoystickValue, rightJoystickValue). I have the values from the Joystick.getY() being fed to the dashboard to view them. They always seem to read between *.1<->.*3 when the joystick is released. Should I be using the route of the .getY() value to drive the robot?

Can you elaborate more by what you mean by this:

for which I’ve set up some wiggle room with a pair of if statements.

To me that sounds like you’re trying to set a deadzone, but I’m not sure.

My team also had this problem but it ended up just being the fact that our talons weren’t zeroed, I know they should be fine on shipment, but for some reason that fixed our problems! The information for zeroing talons was in the 2013 control system pdf if i remember correctly

Yep, that code is to set a deadzone, although since I have to keep increasing it’s size, I’m losing a lot of mobility.

It might be an issue with zeroing the motor controllers, although, it works fine with Labview.

Heres the code:

public class DriveControl {
double leftJoystickValue = 0;
double rightJoystickValue = 0;

/**
 * Controls the Joystick Read-in.
 * Reads the joystick values and directs values to the motors.
 */
public void driveRobot() {

    if(Math.abs(Hardware.leftJoystick.getY()) &gt; .25){
        leftJoystickValue = Hardware.leftJoystick.getY();
    }
    if(Math.abs(Hardware.rightJoystick.getY()) &gt; .25){
        rightJoystickValue = Hardware.rightJoystick.getY();
    }
    
    SmartDashboard.putNumber("leftJoystickValue", leftJoystickValue);
    SmartDashboard.putNumber("righttJoystickValue", rightJoystickValue);

    //decrease values by 3/4 for each trigger pressed
    if (Hardware.leftJoystick.getRawButton(1)) {
        leftJoystickValue = leftJoystickValue * (.75);
        rightJoystickValue = leftJoystickValue * (.75);
    }
    SmartDashboard.putBoolean("leftJoystickTrigger Pressed", Hardware.leftJoystick.getRawButton(1));
    //reduces values even more
    if (Hardware.rightJoystick.getRawButton(1)) {
        leftJoystickValue = leftJoystickValue * (.75);
        rightJoystickValue = leftJoystickValue * (.75);
    }
    SmartDashboard.putBoolean("rigbhtJoystickTrigger Pressed", Hardware.rightJoystick.getRawButton(1));        //sends signal to bot with the adjusted drive values
    
    Hardware.chassis.tankDrive(leftJoystickValue, rightJoystickValue);
    }

This code will make the speed controllers run at about 0.25 when the joystick ramps down.

Imagine the following scenario

joystick output
1        1
0.75     0.75
0.5      0.5
0.3      0.3
0.26     0.26
0.25     0.25
0.1      0.25
0.0      0.25

You need to explicitly set the value back to 0 when it is <= 0.25. The initialize to 0 at the top only occurs once.

Thank you for your help! I added to the code so the values are zeroed. I’m amazed that I missed that earlier.

Just for future reference, my favourite deadzone code looks something like this:

float deadZ (float val) {
	return val > 0.6 || val < -0.6? val: 0;
}

Then you would simply say something like ‘tankDrive(deadZ(leftStick), deadZ(rightStick));’
To me this is the most aesthetically pleasing. But to each his own :stuck_out_tongue: One thing I noticed that would also make it look better (my apologies, I’m really picky about these things) would be to assign ‘Hardware.leftJoystick.getRawButton(1)’ to a boolean somewhere in the beginning of your code so that you don’t have to type that mess every time you need to check it. You could also make a similar method to the one above that takes your boolean as an input as well as a joystick value and clean up the code even more (there’s currently a lot of code involved in just getting it to drive). Just my $0.02 :stuck_out_tongue: Take it with a grain of salt

Thanks, I will definitely give those a try.