View Single Post
  #2   Spotlight this post!  
Unread 20-11-2015, 09:10
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
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)
boolean solenoidOpen = false;
long solenoidOpenTime;

// Runs on each iteration of the teleop loop
if (!solenoidOpen) {
    if(solenoidShouldBeTriggered) {
        openSolenoid();
        solenoidOpened = true;
        solenoidOpenTime = System.currentTimeMillis();
    }
} else {
    if (System.currentTimeMillis() - solenoidOpenTime > 100) {
         closeSolenoid();
         solenoidOpen = false;
    }
}
If you want more clarification, just ask.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists

Last edited by Ben Wolsieffer : 20-11-2015 at 11:28. Reason: Clarification
Reply With Quote