View Single Post
  #2   Spotlight this post!  
Unread 26-01-2012, 23:14
neal's Avatar
neal neal is offline
Neal
FRC #1777 (Viking Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2009
Location: United States
Posts: 56
neal is an unknown quantity at this point
Re: A good time based way to program

Quote:
Originally Posted by ianonavy View Post
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.
I can't test that either until Saturday, but wouldn't that delay the whole main operatorControl() while loop?

If setForTime() is called from drive() and when Timer.delay() will be called, would the whole program stop for that much time or just setForTime()?

This is what the javadoc says:
Quote:
Pause the thread for a specified time. Pause the execution of the thread for a specified period of time given in seconds. Motors will continue to run at their last assigned values, and sensors will continue to update. Only the task containing the wait will pause until the wait time is expired.
"Only the task containing the wait will pause.." seems like that only setForTime() will be paused. So if that's the case, does everything else work normally?

Last edited by neal : 26-01-2012 at 23:21.
Reply With Quote