View Single Post
  #4   Spotlight this post!  
Unread 22-12-2008, 15:25
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Program Axis Camera in c++

Note that I've never done this, I'm just giving somewhat-informed advice.

Ok, if you turn to page 53, there's a bit more detail about the processing step (I'm guessing you've read that too).
Here's the code
Code:
TrackingThreshold tdata = GetTrackingData(BLUE, FLUORESCENT);
This line declares a TrackingThreshhold structure. Based on the comments on the PDF and the way it is used in the code, this appears to be a block of settings that is later used by the FindColor function to do its image analysis. In this case, it appears that they are filling it with pre-set defaults for a generic blue color.

Code:
ParticleAnalysisReport par;
This declares a ParticleAnalysisReport structure. This structure is filled with many useful image-analysis results by the FindColor function.


Code:
if (FindColor(IMAQ_HSL, &tdata.hue, &tdata.saturation, &tdata.luminance, &par)
This is where the magic happens. The FindColor function uses the Hue, Saturation, and Luminance (another way of specifying a color, it is like RGB) from the TrackingThreshhold object to tell it what to look for, then returns its results in the ParticleAnalysisReport structure. Note that they use an if statement here. This is because FindColor returns 1 on success, 0 on failure. I haven't found definitions for what it considers success of failure, but I'd guess (just a guess) that it returns failure if it can't find a good enough blob.

Code:
{ 
  printf(“color found at x = %i, y = %i", par.center_mass_x_normalized, par.center_mass_y_normalized); 
  printf(“color as percent of image: %d", par.particleToImagePercent); 
}
This is where you would act on the results. The center_mass_x_normalized variable tells you where the best match (the biggest blue blob, in this case) is on the x axis. -1.0 means it is on the edge of the camera's vision to the left, and 1.0 means it is on the edge of the camera's vision to the right.

So if I understand your question, you would want your robot to turn left if you see a value less than 0.0, turn right if you see a value more than 0.0, and remain still if the camera value is at 0.0. It would be a good idea to use a PID loop to control this, however, because you'd get big oscillations if you had a simple algorithm like that.

Last edited by Bongle : 22-12-2008 at 15:31.