View Single Post
  #3   Spotlight this post!  
Unread 12-02-2015, 13:29
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 575
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
Re: Multithreading in Java

Here's what I'd do.

1. Make a new type -- say ImageAnalyzer -- that is a Runnable. This type will do the image analysis.

2. Create another new type ImageAnalyzerResult that has properties:

estimatedToteDistance
estimatedToteAngle

This type is used to return the results of the analysis to your main robot logic.

3. The ImageAnalyzer.run() method would have a loop that would repeatedly run your image analysis, likely with some delay between runs to not completely eat a CPU.

Your image analysis code would look like this:

a. Acquire an image from the camera
b. Perform some analysis of the image to determine the robot's angle relative to the vision target on a tote.
c. Create a new ImageAnalyzerResult, and set the two properties to the calculated values from your image analysis. You want to make a new one of these each time you do your image analysis, so that you don't have synchronization issues with the analyzer and the code that uses the result.

4. Add a method to ImageAnalyzer named something like getResult() that returns the current ImageAnalyzerResult if you're seeing a tote, and null if not.

5. When your robot is starting, say:

(new Thread(new ImageAnalyzer())).start();
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Reply With Quote