View Single Post
  #24   Spotlight this post!  
Unread 18-02-2012, 13:08
ianonavy ianonavy is offline
Programming Mentor/Alumnus
AKA: Ian Adam Naval
FRC #3120 (RoboKnights)
Team Role: Mentor
 
Join Date: Dec 2010
Rookie Year: 2008
Location: Sherman Oaks
Posts: 32
ianonavy is an unknown quantity at this point
Re: How to get maximum output from a Jag?

Quote:
Originally Posted by Thundrio View Post
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).