|
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
|