Skip to content

Instantly share code, notes, and snippets.

@carneeki
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carneeki/3d16952dcbd56d706352 to your computer and use it in GitHub Desktop.
Save carneeki/3d16952dcbd56d706352 to your computer and use it in GitHub Desktop.
Autonomous Robot Example demonstrating while(), Timers and Talons
public class Robot
{
/* There will be some code here to initialise the robot
* but I can't remember what it is off the top of my head.
* Eclipse will automatically generate it for us though. :)
*/
public void autonomous()
{
Talon leftTalon = new Talon(2);
Talon rightTalon = new Talon(3);
Timer t = new Timer();
// start the timer
t.start();
// drive forwards for 10 seconds
while(!t.hasPerioPassed(10))
{
leftTalon.set(1);
rightTalon.set(1);
}
// stop both talons
leftTalon.set(0);
rightTalon.set(0);
t.stop(); // stop the timer
t.reset(); // zero the timer
t.start(); // restart the timer
// drive backwards for 5 seconds
while(!t.hasPerioPassed(5))
{
leftTalon.set(-1);
rightTalon.set(-1);
}
// stop both talons
leftTalon.set(0);
rightTalon.set(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment