Quote:
Originally Posted by neal
I can't test that either until Saturday, but wouldn't that delay the whole main operatorControl() while loop?
|
Oh, I see. You're using the SimpleRobot class. I recommend that you really look into the command-based robot implementation. It makes everything a lot more object-oriented, and it's really nice.

There should be a sample project called GearsBot if you've updated your NetBeans FRC plugins for this year's competition.
If you are going to stick with that style, you could try something like this
Code:
// Buttons
final int MOVE_ARM = 1;
// Constants
final int ARM_PWM = 1;
final double ARM_SPEED = 1.0;
final int ARM_TIME = 1.0; // seconds
// Should be instance fields
Timer armTimer = new Timer();
Jaguar arm = new Jaguar(ARM_PWM);
Joystick joystick = new Joystick(1);
armTimer.reset();
armTimer.stop();
while (isOperatorControl() && isEnabled()) {
if (joystick.rawButton(MOVE_ARM)) {
armTimer.start();
}
if (armTimer.get() / 1e6 < ARM_TIME) {
arm.set(ARM_SPEED);
} else {
arm.set(0);
armTimer.stop();
armTimer.reset();
}
}
I don't know that it's the best way of approaching it. There's probably some better way of putting them into separate functions. Essentially, you're going to have separate Timer objects for each motor. You could extend the Jaguar class and make something like a TimedJaguar.
Undocumented and untested quick example:
Code:
public class TimedJaguar extends Jaguar{
Timer timer;
public TimedJaguar() {
timer = new Timer();
timer.reset();
}
public void setForTime(double power, double time) {
// Implement here.
}
}