![]() |
Re: Autonomous Help
Quote:
|
Re: Autonomous Help
Quote:
|
Re: Autonomous Help
Hey guys I finally got the encoder going, my electrical guy said it was grounding on something. Anyway I am getting a nice reading on smart db however, when I run autonomous mode the robot turns about 180 stops and turns again and this never ends. I think I am stuck in an if loop and it's not entering the straight driving portion of the program...
Code:
public class Robot extends IterativeRobot { |
Re: Autonomous Help
Quote:
|
Re: Autonomous Help
Quote:
|
Re: Autonomous Help
Quote:
|
Re: Autonomous Help
Quote:
|
Re: Autonomous Help
Quote:
|
Re: Autonomous Help
Quote:
|
Re: Autonomous Help
Quote:
|
Re: Autonomous Help
Quote:
I hope that it is ok to jump in here... It looks like you started off with a Robot that extended SampleRobot and have now migrated to a class that extends IterativeRobot. The way that your autonomous code will be executed is very different in these two cases. SampleRobot When you extend SampleRobot, your autonomous method will get called for you once. You need to write loops in your code that keep running until you have completed your task. This is why you have the while loop: while( isAutonomous() and isEnabled() ) { //stuff } You also put your own calls to Timer.delay() in this type of robot because nothing is pausing your code (nothing is creating a timed structure for you). IterativeRobot When you extend IterativeRobot, your autonomousPeriodic() method will be called every 20 ms. If you put a loop in this method that runs for longer than 20 ms...well, that is bad. You also don't want to put calls to Timer.delay() in here as this will slow down the execution cycle. Since the code in autonomousPeriodic() is being executed every 20 ms, you want to avoid loops. Put the body of your loops in the method; since it is being executed every 20 ms, it is being looped for you. Also, be careful about resetting values in autonomousPeriodic() without checking a condition. Since the code gets executed repeatedly, you will be continuously resetting the value (e.g. the call to reset the gyro at the top of the method is constantly resetting the gyro). Proposed new method: Code:
Quote:
To find the correct value for setDistancePerPulse(), we typically:
Good luck and let me know if this did or didn't work...unfortunately, I didn't test the code :( |
Re: Autonomous Help
Quote:
|
Re: Autonomous Help
Quote:
If the code above makes sense, though, I would encourage you to explore the IterativeRobot template. The teleop code works in a similar fashion: teleopInit() gets called once when teleop is enabled and teleopPeriodic() gets called every 20 ms for you (so avoid loops that don't exit quickly and do not use Timer.delay() to pause your code). Also, the 20 ms is just a great approximation...the loop timing is reallllly close to every 20 ms (certainly close enough for what we're doing). If you do switch back to SampleRobot, then you will need the loops and the calls to Timer.delay(). Keep plugging away at it and keep asking questions. ChiefDelphi is full of people that want to help :) |
Re: Autonomous Help
Quote:
|
Re: Autonomous Help
Quote:
|
| All times are GMT -5. The time now is 10:30. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi