View Full Version : Bit of coding help
SoulSaber1
18-03-2011, 13:25
So, for autonamous we are using a modified line tracker code, with certain cases for different scenarios. After this loop we want the robot to go backwards, but we can't seem to make it happen.
case 7: //ALL SENSORS ON *OR* MAYBE AT CROSS
if (time > stopTime)
{
atCross = true;
speed = 0;
gripper.set(false); //Closes gripper
gripper2.set(true); // " "
while (backCount < 5)
{
backCount++;
drive.arcadeDrive(-.5,0);
}
}
Any ideas?
Egg 3141592654
18-03-2011, 13:32
If you want the robot to move backwards, instead of using a while loop, replace with something like...
drive.arcadeDrive(-.5 , 0);
Timer.delay(/*insert time you want to go backwards in milliseconds*/);
drive.arcadeDrive(0 , 0);
To answer why your robot may not be moving backwards, the loop might be cycling too fast for you to actually notice, so 5 cycles would be instant. Remember to put the drive.arcadeDrive(0 , 0) or else your robot will keep driving backwards. Good luck out there!
SoulSaber1
18-03-2011, 14:04
For some reason this isn't working either. did you mean like this?
case 7: //ALL SENSORS ON *OR* MAYBE AT CROSS
if (time > stopTime)
{
atCross = true;
speed = 0;
gripper.set(false); //Closes gripper
gripper2.set(true); // " "
drive.arcadeDrive(-.5 , 0);
Timer.delay(1.0);
drive.arcadeDrive(0 , 0);
}
For some reason this isn't working either. did you mean like this?
case 7: //ALL SENSORS ON *OR* MAYBE AT CROSS
if (time > stopTime)
{
atCross = true;
speed = 0;
gripper.set(false); //Closes gripper
gripper2.set(true); // " "
drive.arcadeDrive(-.5 , 0);
Timer.delay(1.0);
drive.arcadeDrive(0 , 0);
}
Okay so I can see one clear problem here I think.
Timer.delay is generally in milliseconds so you have it going backwardsfor 1 millisecond then stopping. Try increasing Timer.delay to a greater value, say 500, then try it again.
Remeber if it goes berserk and doesnt stop for some reason you have a stop button. :)
Egg 3141592654
21-03-2011, 11:24
Timer.delay is generally in milliseconds
Timer.delay for wpilibj is in milliseconds, so 1 second would be
Timer.delay(1000);
Robby Unruh
21-03-2011, 17:26
Timer.delay for wpilibj is in milliseconds, so 1 second would be
Timer.delay(1000);
The javadoc only says this:
delay
public static void delay(double seconds)
Pause the thread for a specified time. Pause the execution of the thread for a specified period of time given in seconds. Motors will continue to run at their last assigned values, and sensors will continue to update. Only the task containing the wait will pause until the wait time is expired.
Parameters:
seconds - Length of time to pause
Note; "seconds". I'm pretty sure it's just in normal seconds. So one second would be
Timer.delay(1.0); // only accepts doubles as an argument
My team has had no problems using this, as opposed to using milliseconds(?).
However, when using other functions in the Timer class, like get(), it will return in microseconds. For our minibot deployment, we start a timer and have a condition timer.get()/1000000 > 110, if true it will deploy. If false, it'll let the user know you can't deploy yet. :)
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.