![]() |
A good time based way to program
Whenever my mentors ask me if I can program a motor to run for x seconds, I always feel it's not the best way to do that.
For example, press a button and the motor will run for x seconds and then stop. All I can think of to do that is simply using Timer() class, but then I feel using multiple timers, if else's for them is not just the best way to do it. Is there any other better way to do this or is using Timer() fine? All your thoughts are much appreciated! |
Re: A good time based way to program
Code:
import edu.wpi.first.wpilibj.Timer; |
Re: A good time based way to program
Quote:
If setForTime() is called from drive() and when Timer.delay() will be called, would the whole program stop for that much time or just setForTime()? This is what the javadoc says: Quote:
|
Re: A good time based way to program
How about you create a priority queue of sorts?
(Note that the following is a fake priority queue, it is O(n), while a sorted queue should have a much lower runtime cost) Code:
class TimerQueueThen you could simply schedule tasks and they will run after the certain time has passed, assuming you call update every "tick". I know threading can do the same things, but I do not trust neither myself nor the cRIO with threading. |
Re: A good time based way to program
Quote:
If you are going to stick with that style, you could try something like this Code:
// ButtonsUndocumented and untested quick example: Code:
public class TimedJaguar extends Jaguar{ |
Re: A good time based way to program
Look at the updated documentation for 2012 WPILib. I think the command based robot is exactly what you are looking for.
|
Re: A good time based way to program
Quote:
You might also check out the videos at http://youtube.com/user/bradamiller. It explains how to write the GearsBot sample program step by step. Brad |
Re: A good time based way to program
Thanks all for your suggestions. I'm trying to just stick with SimpleRobot for this year since I don't think we have enough time now to write it for CommandBased one, and to test, troubleshoot it.
Brad, does timeouts also work with SimpleRobot, I checked the cookbook and it only shows examples for the command-based bot. |
Re: A good time based way to program
Quote:
Brad |
Re: A good time based way to program
Thanks!
We'll probably just use Command Based Robot. Just started writing it again and looking through the cookbook and GearsBot. |
| All times are GMT -5. The time now is 11:21. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi