View Single Post
  #1   Spotlight this post!  
Unread 26-01-2012, 23:05
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: A good time based way to program

Code:
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.SpeedController;

...

/**
 * Sets a motor to a certain power value for a certain number of seconds
 * @param controller The speed controller of the motor to power.
 * @param power The desired power for the motor.
 * @param time The time to run in seconds.
 */
public void setForTime(SpeedController controller, double power, double time) {
    controller.set(power);
    Timer.delay(time);
    controller.set(0);
}
Would something like this work? Warning: that code is not tested.
Reply With Quote