Motor Programming help

Hey I’m using java to control 3 cim ball shifter motors and I’m running into a problem where when I move the joystick forward they work but they keep rolling instead of hard stopping when letting go of the joystick. We are using arcade drive btw

You’re controlling a system with inertia, so it’ll behave that way. If you want to hard stop, you’ll have to use closed loop velocity control, with something like PID (encoders necessary). Putting your motor controller into brake mode will help a bit, but it’ll simply increase drag while coasting, as opposed to immediately stopping.

I think you’re probably right, but the original post doesn’t give very much information, so I’m going to add on with another possibility; that the joystick is suffering from drift. There are a few solutions to this problem. #1, recalibrate the joystick in the Windows “Set up USB Game Controllers” wizard. Secondly, I recommend adding a deadband to prevent the system from moving unless the joystick is out of a “area of error”, where it is possible the joystick is returning values when you aren’t touching it. This can be done very easily, as I’ll show below.

//Get the value of the joystick's forward-backward axis
double joyVal = joystick.getRawAxis(1);

//Check if the abosolute value is above a deadband number (in this case .05, or 5%)
if(Math.abs(joyVal) > .05){
    //If it is outside the deadband, set our motors to output that value.
    spark.set(joyVal);
    talon.set(ControlMode.PercentOutput, joyVal);
}
else{
    //Otherwise, set our motor speeds to zero
    spark.set(0);
    talon.set(ControlMode.PercentOutput, 0);
}

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.