Go to Post Picking up tetra's is going to be as easy as picking up a person of the opposite sex. While a select few will master it; others will be bumbling maroons.. - Elgin Clock [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 26-01-2016, 18:26
iSpotix iSpotix is offline
Registered User
FRC #4049
 
Join Date: Jan 2016
Location: Pittsburgh
Posts: 27
iSpotix is an unknown quantity at this point
[Vision] Multithreading?

What is the best way to have a vision loop that constantly updates numbers, but with a short sleep period but not hinder the normal teleop loop?

If I want to update the numbers every half second or so is there a way I can do that without making the whole teleop loop wait? I've looked at Runnables, but is there an easier way to do this?
Reply With Quote
  #2   Spotlight this post!  
Unread 26-01-2016, 18:39
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: [Vision] Multithreading?

as long as you're sure that this is what you want to do..

Code:
new Thread("Vision Processing Thread"){public void run(){
    while(true){
         camera.process()
         try{
               sleep(500);
         }catch(Exception e){}
    }
}}.start()
(apologies if syntax errrors i wrote this in the texte ditor)
__________________
FRC Team 1684 - Head Programmer (2013-2016)
FRC Team 5460 - Programming Mentor (2015-2016)

FIRST in Michigan - Technical Crew (2015-continuing)
Reply With Quote
  #3   Spotlight this post!  
Unread 27-01-2016, 09:34
iSpotix iSpotix is offline
Registered User
FRC #4049
 
Join Date: Jan 2016
Location: Pittsburgh
Posts: 27
iSpotix is an unknown quantity at this point
Re: [Vision] Multithreading?

Quote:
Originally Posted by Arhowk View Post
as long as you're sure that this is what you want to do..
Is there a better way to do this? What is the normal way to include vision processing?
Reply With Quote
  #4   Spotlight this post!  
Unread 27-01-2016, 21:41
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: 72
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: [Vision] Multithreading?

Something like this might work for you:

Code:
// Create a new Timer to schedule vision processing
Timer visionScheduler = new Timer("Vision Scheduler", true);

void doVisionProcessing() {
    // Your vision code here
}

public void autonomousInit() {
    ...
    // Perform vision processing every 50ms, starting in 0ms (i.e. now)
    visionScheduler.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                doVisionProcessing();
            }
        }, 0, 50);
}
Keep in mind that you'll need to do the normal threading stuff like locks/synchronization blocks and declaring shared variables volatile, but that applies for any multithreaded program.
__________________
WPILib
GRIP, RobotBuilder
Reply With Quote
  #5   Spotlight this post!  
Unread 29-01-2016, 11:15
JacobD's Avatar
JacobD JacobD is offline
Registered User
AKA: Jacob
FRC #1672 (Mahwah Robo T-Birds)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2013
Location: New Jersey
Posts: 90
JacobD is an unknown quantity at this point
Re: [Vision] Multithreading?

Otherwise you could put it in a periodic method.
__________________
2013-2014: Electrical, Mechanical
2014-2017: Team Captain
Reply With Quote
  #6   Spotlight this post!  
Unread 29-01-2016, 11:28
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,590
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: [Vision] Multithreading?

We have a utility in our github to do this. Send an e-mail to gixxy if you have any questions (he doesn't check CD daily).
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #7   Spotlight this post!  
Unread 31-01-2016, 18:24
JacobD's Avatar
JacobD JacobD is offline
Registered User
AKA: Jacob
FRC #1672 (Mahwah Robo T-Birds)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2013
Location: New Jersey
Posts: 90
JacobD is an unknown quantity at this point
Re: [Vision] Multithreading?

Code:
Thread cameraThread = new Thread()
{
	public void run()
	{
		//camera code goes here
	}
};
Then do...
Code:
cameraThread.sleep(timeInMillis);
or

Code:
cameraThread.stop(); //not sure if this is depreciated

java.util.Timer myTimer = new java.util.Timer();

myTimer.schedule(new TimerTask() 
{
       @Override
	public void run()
	{
		 cameraThread.run();
	}
}, 1000);
The difference between this and sleeping the thread is that the timer doesn't suspend the run-time of the program. I'm thinking that this is what you are looking for.
__________________
2013-2014: Electrical, Mechanical
2014-2017: Team Captain

Last edited by JacobD : 31-01-2016 at 18:27.
Reply With Quote
  #8   Spotlight this post!  
Unread 05-02-2016, 03:26
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: [Vision] Multithreading?

We have a vision target module in our library that will take care of the multi-threading stuff. It spawns a separate thread and will process each frame to look for objects for the specified criteria. If a new frame is processed, the new result will overwrite the old one. In other words, we always have the latest result cached. If the main robot thread wants to look for "targets", it gets the cached result from the vision targeting thread.
__________________
Reply With Quote
  #9   Spotlight this post!  
Unread 05-02-2016, 06:45
rich2202 rich2202 is offline
Registered User
FRC #2202 (BEAST Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Wisconsin
Posts: 1,184
rich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond repute
Re: [Vision] Multithreading?

We have it running as a separate program on the Driver Station. We use Network Tables to communicate with the RoboRio. It grabs the same picture that is being displayed on the DS for the driver.

when "picture" is 0, the vision program does nothing.
When "picture" is 1, it starts vision processing, and changes the value to "2" to indicate it is working.
When it is done calculating, it sets "Angle", and "Distance", and changes "picture" back to 0.

On the RoboRio, it waits for "picture" to go back to "0". when it sees that, it takes "Angle" and "Distance" and drives there (using NavX).

Rinse, repeat, until Angle and Distance are close enough to shoot.
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 06:10.

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