![]() |
How to time an action in teleop without delaying teleop.
So me and my team are programming in java, and as head of programming I kind of have to have it together. (I don't. I am a Sophomore and we are a 2nd year team.) What I'm trying to do is trigger a single solenoid, wait for a short time like 65-100 MS and then close the solenoid again, but I'm not sure how to do that without hitting my teleop routine with a 100 MS lag spike in which the whole teleop loop is delayed when the solenoid is opened up. Thanks!
-5683 Programming Dept. |
Re: How to time an action in teleop without delaying teleop.
Are you using the Command framework, or just SampleRobot?
If you are using commands, I would create a Command with a 100 ms timeout, which would open the solenoid in the initialize() method, and close it in the end() method. If you are just using a simple teleop loop, then it is a little more complicated. Here is some psuedo code that should give you an idea of how to do it: Code:
// Class variables (their values must persist between iterations of the loop) |
Re: How to time an action in teleop without delaying teleop.
You can use java.util.Timer and java.util.TimerTask to schedule something to happen in the future while your program still runs.
Code:
// local or class variables |
Re: How to time an action in teleop without delaying teleop.
Quote:
Also: Hi Sam! |
Re: How to time an action in teleop without delaying teleop.
Quote:
Solenoid methods are thread-safe. I'd be more worried about scheduling a close, doing some stuff, then opening the solenoid (and expecting it to stay open) before the scheduled close happens. In this case, the methods for opening/closing the solenoid should have checks to see if it's been claimed by a different call. Code:
private boolean claimed = false;But I don't think it's a problem for something this simple. |
Re: How to time an action in teleop without delaying teleop.
Definitely need to switch to command-based robot and don't forget to use requires(); with your commands and subsystems, otherwise your whole robot will still pause. WPIlib documentation should be able to take it from there.
|
Re: How to time an action in teleop without delaying teleop.
Quote:
|
| All times are GMT -5. The time now is 10:15. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi