Go to Post The pen [may be] mightier than the sword, but the bandsaw can chop them both. - Marc P. [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

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-02-2015, 13:09
jagow100's Avatar
jagow100 jagow100 is offline
Registered User
FRC #3539 (Byting Bulldogs)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Romeo, Michigan
Posts: 13
jagow100 is an unknown quantity at this point
Multithreading in Java

Me and my team all understand multithreading, but we're all confused on how you would attempt multithreading with this control system. We wish to put the camera on a separate thread so it doesn't slow down the rest of the code. We have the camera code set up as well but since it has to wait for the camera to update its picture, it has a huge amount of input lag from the controller. Any help would be appreciated.
- 3539 Programming Team
Reply With Quote
  #2   Spotlight this post!  
Unread 12-02-2015, 13:10
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Multithreading in Java

Quote:
Originally Posted by jagow100 View Post
Me and my team all understand multithreading, but we're all confused on how you would attempt multithreading with this control system. We wish to put the camera on a separate thread so it doesn't slow down the rest of the code. We have the camera code set up as well but since it has to wait for the camera to update its picture, it has a huge amount of input lag from the controller. Any help would be appreciated.
- 3539 Programming Team
We just created a thread and started it in robotinit() for vision processing.
Reply With Quote
  #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
  #4   Spotlight this post!  
Unread 12-02-2015, 13:30
ozrien's Avatar
ozrien ozrien is offline
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 521
ozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant futureozrien has a brilliant future
Re: Multithreading in Java

1. Creating a thread
http://www.tutorialspoint.com/java/j...ithreading.htm
The first example demonstrates creating a class type that creates a thread to do work in.

2. How to share information between thread and your main program flow
The next step is to take the results of the camera logic and save them to some member variables in the class type, so that the "main" thread in Robot can safely poll them out using sychronized accessors.
http://docs.oracle.com/javase/tutori.../syncmeth.html
Reply With Quote
  #5   Spotlight this post!  
Unread 12-02-2015, 13:39
jagow100's Avatar
jagow100 jagow100 is offline
Registered User
FRC #3539 (Byting Bulldogs)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Romeo, Michigan
Posts: 13
jagow100 is an unknown quantity at this point
Re: Multithreading in Java

We got it working, thanks guys.
Reply With Quote
Reply


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 10:53.

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