Quote:
Originally Posted by Thundrio
My idea is that just have limitedJoystick created as a joystick in slot 3 (a virtual joystick). Then I basically take the above code and put it right before my robotdrive (which calls the fake limitedJoystick). But it is not working (I didn't suspect it to) even after I created change/limit as a double.
|
Using pseudo-Java, this would go in an IterativeRobot:
Code:
Joystick joystick = new Joystick(1);
double lastJoystickValue = 0;
// Limit the Joystick to a change of 1% every iteration of the robot. Basically,
// limit the acceleration of the robot.
final double MAX_CHANGE_PER_ITER = 0.01;
public void teleopPeriodic() {
double currentJoystickValue = joystick.getMagnitude();
double magnitude = limitRate(currentJoystickValue, lastJoysitckValue);
drive(magnitude); // pseudo method
lastJoystickValue = magnitude;
}
/**
* Uses the value from the last iteration to limit how much the Joystick can
* change in one iteration.
* @param goalValue The ideal value that we ultimately want to reach.
* @param lastJoystickValue The value of the joystick from the last iteration.
*/
public double limitRate(double goalValue, double lastJoystickValue) {
double difference = goalValue - lastJoystickValue;
if (difference > MAX_CHANGE_PER_ITER) {
return lastJoystickValue + MAX_CHANGE_PER_ITER;
} else if (difference < -MAX_CHANGE_PER_ITER) {
return lastJoystickValue - MAX_CHANGE_PER_ITER
} else {
return goalValue;
}
}
I hope this helps and makes sense. You will need to modify it for your purposes (port to C++, change for your DriveTrain Subsystem, modify for Mecanum drive, or whatever else).