|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Autonomous
Quote:
Your autonomous function should look like Code:
public void autonomous() {
while(isAutonomous()){ //Place everything in a loop.
robotDrive.drive(0.5,0.0);//drive at 50% speed 0% turn
Timer.delay(5.0);//wait 5 seconds
}
|
|
#2
|
||||
|
||||
|
Re: Autonomous
Quote:
Try the following instead: Code:
public void autonomous() {
robotDrive.setSafetyEnabled(false);
robotDrive.drive(0.5,0.0);//drive at 50% speed 0% turn
Timer.delay(5.0);//wait 5 seconds
}
Last edited by NWChen : 18-02-2014 at 22:40. |
|
#3
|
||||
|
||||
|
Re: Autonomous
Another option would be to use the system clock:
We used similar code on an alliance partner's robot at week 0 and it worked flawlessly. Code:
public void autonomous() {
long startTime = System.currentTimeMills();
while(isAutonomous()){ //Place everything in a loop.
long timePassed = System.currentTimeMills() - startTime;
if(timePassed < 5000){
//in the first 5 seconds of auto
robotDrive.drive(0.1,0.0);
}else {
robotDrive.drive(0,0.0);
}
Timer.delay(.05);
}
Also you'll noticed I chanced the speed to .01, you only need to cross the line, so I would slowly increment the speed until it matches your needs. Driving at half speed for 5 seconds could have some unintended consequences. Last edited by mwtidd : 18-02-2014 at 22:54. |
|
#4
|
||||
|
||||
|
Re: Autonomous
It's important to actually tell your motors to stop after commanding the drivetrain to move forward for 5 seconds. Otherwise your code will go on its merry way, but the drivetrain will continue to be commanded.
Regardless of how you end up implementing the code you need to explicitly command the motors to 0. lineskier's code does this: Code:
robotDrive.drive(0.0, 0.0); |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|