View Single Post
  #2   Spotlight this post!  
Unread 20-11-2015, 12:01
SamCarlberg's Avatar
SamCarlberg SamCarlberg is offline
GRIP, WPILib. 2084 alum
AKA: Sam Carlberg
no team
Team Role: Mentor
 
Join Date: Nov 2015
Rookie Year: 2009
Location: MA
Posts: 103
SamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to behold
Re: How to time an action in teleop without delaying teleop.

Quote:
Originally Posted by lopsided98 View Post
This method would work in this case (assuming the Solenoid methods are thread-safe), but I would be worried about possible race conditions if more complicated logic were to later be added in the TimerTask.

Also: Hi Sam!
Hey Ben!

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;

public void openSolenoid() {
    if (!claimed) {
        claimed = true;
        // open it
    }
}

public void closeSolenoid() {
    if (claimed) {
        claimed = false;
        // close it
    }
}

But I don't think it's a problem for something this simple.
__________________
WPILib
GRIP, RobotBuilder
Reply With Quote