Thread: Java Threads
View Single Post
  #10   Spotlight this post!  
Unread 22-02-2011, 20:47
Robby Unruh's Avatar
Robby Unruh Robby Unruh is offline
*insert random dial-up tone here*
FRC #3266 (Robots R Us)
Team Role: Coach
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Eaton, OH
Posts: 338
Robby Unruh will become famous soon enough
Re: Java Threads

Quote:
Originally Posted by Aaron V View Post
So I have experience in programming - but one thing I haven't really looked into in detail are threads - I've always just let the compiler deal with them for me. I understand the concept of threads. The different parts of a programmer running essentially at the same time (alternating fast enough so that it doesn't really make a difference). I just don't understand what parts of a program constitutes as a difference thread. I've written a few additional classes for organisational purposes - do they have any effect?

Basically my main problem is that I need to pulse solenoids. It's simple to set it open or closed based on other input, but I don't know how to use time as an input. I figure I need threads because I don't want to stop everything else in the code.

Finally I've both seen the wait() function in the object class and the delay() function in the Timer class - I'm not sure which is better to use and which thread it effects.
Pulse solenoids, eh? Take a closer look at the Timer class, more notably getFPGATimestamp(). What I'd do is create a double to store a current timestamp using getFPGATimestamp(). Then in my code I'd make another more recent one that checks for a change in time. If the time has changed, I'd simply set the solenoid to false. Put that baby in a loop and bam!

Now if you'd prefer putting it in a thread than a loop, just make a Runnable interface and thread it.

Hope I helped.
__________________
[Robots R Us #3266]
2015: Georgia Southern Classic (Winners / Thanks 1319 & 1648!), Queen City
2014: Crossroads, Queen City
2013: Buckeye, Queen City, Crossroads
2012: Buckeye, Queen City

2011: Buckeye
2010: Buckeye
Reply With Quote