Go to Post If I'm going to mentor someone, I'm going to be involved in their life as a positive force. - Mechvet [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #5   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
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:50.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi