Go to Post Cut it out with the paper airplanes! Frank hath spoken! - cgmv123 [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 08-02-2012, 00:09
2869Robotics 2869Robotics is offline
Registered User
FRC #2869
 
Join Date: Jan 2012
Location: Bethpage
Posts: 18
2869Robotics is an unknown quantity at this point
Camera Vision Processing

Hi,

in my code i have
Code:
public void operatorControl(){
  while(isenabled() && isOperatorControl()){

         ColorImage img = Camera.getImage();
          .....and then i do a bunch of processing after i get the image.

  }
}
How do I get the camera to only take a picture 5 times per second? Doesn't the loop repeat like once every 10ms? So wouldn't that mean that the code I have now would take a picture once every 10ms?

Last edited by 2869Robotics : 08-02-2012 at 20:34.
Reply With Quote
  #2   Spotlight this post!  
Unread 08-02-2012, 09:44
dbeckwith's Avatar
dbeckwith dbeckwith is offline
Lead Programmer
AKA: Daniel Beckwith
FRC #3205 (The Patriots)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: USA
Posts: 84
dbeckwith is an unknown quantity at this point
Re: Camera Vision Processing

You can't rely on the loop being executed every 10ms, it's bound to change as you put in more code (especially image processing). If you wanted to do something every 200ms, you might do something like this:
Code:
import edu.wpi.first.wpilibj.Timer;

public void operatorControl() {
  double time = Timer.getFPGATimestamp();
  
  while(isEnabled() && isOperatorControl()) {
    if (Timer.getFPGATimestamp() - time >= 0.2) {
      // CAMERA IMAGE PROCESSING HERE
      time = Timer.getFPGATimestamp();
    }
    // OTHER CODE HERE
  }
}
__________________
q = (2*b) | ~(2*b);

if (life.getLemons() != null) this.lemonade = new Drink(life.getLemons());
else throw new NoLemonsException("What now?");


Reply With Quote
  #3   Spotlight this post!  
Unread 08-02-2012, 19:05
jesusrambo jesusrambo is offline
Self-Proclaimed Programmer Messiah
AKA: JD Russo
FRC #2035 (Robo Rockin' Bots)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2010
Location: Carmel, CA
Posts: 114
jesusrambo is an unknown quantity at this point
Re: Camera Vision Processing

You might try running the image capture in a separate thread. I've had sketchy luck with threads and FRC Java, but your mileage may vary.
Reply With Quote
  #4   Spotlight this post!  
Unread 10-02-2012, 07:18
IisMathwizard's Avatar
IisMathwizard IisMathwizard is offline
Programming Mentor
AKA: Mathwizard
FRC #1248 (Titanium Allies)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Berea-Midpark High school
Posts: 60
IisMathwizard is an unknown quantity at this point
Re: Camera Vision Processing

Like what jesusrambo said, running in a seperate thread might actually be a good idea... (Thanks rambo! ill try it). I don't think that overhead would be a problem as long you aren't using a seperate thread for each motor or something unsynchronized as that... If you need help on image tracking ill be more than happy to help. I haven't used the javacv that everyone seems to be raving about but with the image processing functions tat FRC gave us i was able to successfully track imagery.
__________________

jRIO 2013 Project
Reply With Quote
  #5   Spotlight this post!  
Unread 10-02-2012, 12:19
2869Robotics 2869Robotics is offline
Registered User
FRC #2869
 
Join Date: Jan 2012
Location: Bethpage
Posts: 18
2869Robotics is an unknown quantity at this point
Re: Camera Vision Processing

Im not sure what you guys mean by running it in a seperate thread
Reply With Quote
  #6   Spotlight this post!  
Unread 10-02-2012, 15:18
Patrick Chiang Patrick Chiang is offline
Programming
FRC #3070 (Team Pronto)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Seattle
Posts: 162
Patrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to all
Re: Camera Vision Processing

Quote:
Originally Posted by 2869Robotics View Post
Im not sure what you guys mean by running it in a seperate thread
Having a separate thread makes it so that your code won't be stuck on some piece of code until it finishes running. It makes it so that it can run multiple pieces of code (technically no on the low level, but for all practical purposes yes).

If you don't stick a piece of particularly long running loop in a thread (say, one that deliberately waits for 5 seconds before it finishes executing), the rest of your program will get stuck on it, and your other code, like your drive/shoot code will stop executing until the 5 seconds is done.

Read this piece of documentation on how you can implement this in Java: http://docs.oracle.com/javase/tutori...l/concurrency/
Attached Thumbnails
Click image for larger version

Name:	loopingthreading.png
Views:	19
Size:	18.3 KB
ID:	11833  
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 12:51.

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