View Single Post
  #4   Spotlight this post!  
Unread 02-03-2014, 20:26
ProgrammerMatt ProgrammerMatt is offline
Programmer-Electrical-Mechanical
FRC #0228 (Gus)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Southington
Posts: 138
ProgrammerMatt is just really niceProgrammerMatt is just really niceProgrammerMatt is just really niceProgrammerMatt is just really nice
Re: ASAP HELP FOR AUTONOMOUS PROGRAMMING

Quote:
Originally Posted by lineskier View Post
I assume you're trying to score the 5 points for driving forward. We helped one of our alliance partners at week zero do this. Now it may vary a bit if your using simplerobot or iterative robot, but the approach is the same regardless. When your autonomous starts, store the current time. Then on each loop of autonomous check to see if the time is > 5 seconds. If it is stop the drive, otherwise drive forward slow.

Code:
private long startTime = 0;

//the first time autonomous executes (i.e. autonomous init)
startTime = System.currentTimeMills();

//on each loop/iteration
if(System.currentTimeMills() - startTime < 5000){
      //drive forward slow (.1 or .2 for a start)
}else{
      //stop the drive
}

Why not do something like this:

in autonomous function:
Code:
drive.tankDrive(0.5,0.5); //set drive motors to 50%
Timer.delay(time); //time to wait in seconds
drive.tankDrive(0.0,0.0); //stop drive motors
Because public void autonomous() {} only runs once there's no need for a loop it will simply execute in order.
__________________
2015-2016 CSA
Software Engineering Student @ Johnson & Wales University
Team 228, Gus Robotics Inc.
Facebook
FLL Mentor for 1107, Edison Eagles!
2015- CT State Champions
2012- WPI Finalist(Thanks 1884 and 549), Spirt, Best Website
2011- WPI Chairman's award winners!
2010- WPI Champions! (thanks 230 & 20), WPI Engineering Inspiration, CT Best Website, CT VEX Champions (VRC228, VRC228b) (21-1-0)
2009- QCC VEX Champions (VRC228) (11-0-0), Innovate Award (VRC228)

Last edited by ProgrammerMatt : 02-03-2014 at 20:29.
Reply With Quote