View Full Version : Autonomous Time Delay
abilash123
17-02-2016, 21:30
Ok so im trying to figure out how to get an autonomous for work. I tried to get the robot to drive forward with the code below:
drive.tankDrive(1.0,1.0);
Time.delay(3);
drive.tankDrive(0.0,0.0);
When i run the autonomous the robot just jerks forwards quickly and sometimes it won't even give a response. I tried changing the number in the time delay but it made no difference. Any ideas?
em202020
17-02-2016, 22:42
What code is in the Time.delay function? Through my quick 10 second look, there is no Time.delay() function is Java...
Could it be doing time in milliseconds?
Mark McLeod
17-02-2016, 22:52
It might be due to a motor safety if you are using one and it hasn't been Disabled.
That will shutdown the motors during time delays longer than about .1 seconds.
Time.delay(3) should be Timer.delay(3.0)
I'd recommend using a CommandGroup and using its timeout function.
Let's say you have a command for AutoDriving called AutoDrive that takes parameters for left and right speeds.
In the CommandGroup, you'd write something like this:
addSequential(new AutoDrive(1.0,1.0), 3.0);
You can also use Wait(). For example, Wait(2.0) to wait 2 seconds. Like Mark said, you need to disable safety, or the motors wont run.
myRobot.SetSafetyEnabled(false);
abilash123
18-02-2016, 21:47
Thanks disabling safety fixed it :D
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.