Last active
August 29, 2015 14:15
-
-
Save carneeki/3d16952dcbd56d706352 to your computer and use it in GitHub Desktop.
Autonomous Robot Example demonstrating while(), Timers and Talons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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