we need help with limiting the speed of our robot when driving with a controller in java. The robot runs really quickly when the joysticks are moved and we need a way to limit how fast it will go.
There are a few things you can do. First is square your input that will make it accelerate less at the beginning of the stick movement so it won’t be so jumpy also apply a deadband. Use an exponent of 2 to start.
private static double modifyAxis(double value, int exponent) {
// Deadband
value = MathUtil.applyDeadband(value, ControllerConstants.DEADBAND);
value = Math.copySign(Math.pow(value, exponent), value);
return value;
}
Then you can limit acceleration with a SlewRateLimiter . The parameter is the number of units per second. IF you are dealing with axis inputs to percent output the unit is 100% so a 3 like we use is full throttle in 1/3 of a second
private SlewRateLimiter xLimiter = new SlewRateLimiter(3);
private SlewRateLimiter yLimiter = new SlewRateLimiter(3);
then apply the value with the calculate
x = xLimiter.calculate(modifyAxis(xSupplier.doubleValue(), 2) ;
Then if you wanted to limit the cap you could MathUtil.clamp the value at .8 or something but I think the SlewRateLimiter and axis modification will help you
That works, or you could do what my team does; we get the value of the joystick and multiply that value by how quickly we want the robot to go (ex. 50 percent = 0.5).
In the Drivetrain subsystem
public void teleopDrive (double Yspd, double Xspd) {
drive.arcadeDrive(Yspd, Xspd);
}
In the drive command:
public void execute () {
drivetrain.teleopDrive(Robot container.joystick.getRawAxis(1) * 0.5, RobotContainer.joystick.getRawAxis(0) * 0.5);
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.