View Single Post
  #2   Spotlight this post!  
Unread 02-09-2016, 12:14 PM
Oromus's Avatar
Oromus Oromus is offline
Lead Programmer, Community Liason
AKA: Ryan
FRC #1902 (Exploding Bacon)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Florida
Posts: 80
Oromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to behold
Re: Autonomous in iterative robot

One of the simplest and easiest ways to have logic for autonomous not run at the same time is to use Thread.sleep(). It lets you run code, have the code halt for a set amount of milliseconds/seconds, then proceed with more code. An example:

Code:
public void autonomousInit() {
    try {
        leftMotor.set(1);
        rightMotor.set(1);
        Thread.sleep(1000); //Thread.sleep() takes milliseconds, so 1000 milliseconds = 1 second
        leftMotor.set(0);
        rightMotor.set(0);
    } catch (InterruptedException e) { //Thread.sleep() can throw an InterruptedException, so we have to catch it
        e.printStackTrace();
    }
}
This code makes the robot drive forward for one second and then stop. The only potential issues with this is that Thread.sleep() halts all code execution on that Thread, so if there is other code that needs to be called constantly you'll either need to not use Thread.sleep() or do multi-threading. In a simple autonomous like this, though, Thread.sleep() should fit your needs perfectly. Just remember that no code after Thread.sleep() will be called until after the delay. Hope this helps!

Also, in the event you want to do multi-threading, let me know and I'll help you out there
__________________


2016 Roles: Manipulator, Strategy Co-Lead, Programmer
2016 Orlando Regional: Quarterfinalist (Captain w/ 1557, 5557 and 4352)
2016 Rocket City Regional: Quarterfinalist (w/ 283 and 34), Regional Chairman's Award Winner
2016 Championship: N/A (had fun and was inspired, that's what counts)
-------------
2015 Role: Programmer
2015 GSCR: Quarterfinalist (w/ 4189 and 4026), Regional Chairman's Award Winner
2015 Orlando Regional: Semifinalist (w/ 456 and 86), Imagery Award Winner
2015 Championship: Pit Safety Award Winner
Reply With Quote