Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Bit of coding help (http://www.chiefdelphi.com/forums/showthread.php?t=93738)

SoulSaber1 18-03-2011 13:25

Bit of coding help
 
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.

Code:

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

Re: Bit of coding help
 
If you want the robot to move backwards, instead of using a while loop, replace with something like...

Code:

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

Re: Bit of coding help
 
For some reason this isn't working either. did you mean like this?

Code:

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);
                                                                }


JosephC 19-03-2011 13:06

Re: Bit of coding help
 
Quote:

Originally Posted by SoulSaber1 (Post 1041700)
For some reason this isn't working either. did you mean like this?

Code:

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

Re: Bit of coding help
 
Quote:

Timer.delay is generally in milliseconds
Timer.delay for wpilibj is in milliseconds, so 1 second would be
Code:

Timer.delay(1000);

Robby Unruh 21-03-2011 17:26

Re: Bit of coding help
 
Quote:

Originally Posted by Egg 3141592654 (Post 1043121)
Timer.delay for wpilibj is in milliseconds, so 1 second would be
Code:

Timer.delay(1000);

The javadoc only says this:

Quote:

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

Code:

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. :)


All times are GMT -5. The time now is 11:37.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi