Heres the code we're using for target tracking, using the color values from the TwoColorTrackDemo. All variables are doubles declared before the While loop, and pan and tilt are servos.
Code:
if (FindColor(IMAQ_HSL, &redData.hue, &redData.saturation,
&redData.luminance, &aRed) && FindColor(IMAQ_HSL,
&greenData.hue, &greenData.saturation,
&greenData.luminance, &aGreen)) {
redX = aRed.center_mass_x_normalized;
redY = aRed.center_mass_y_normalized;
greenX = aGreen.center_mass_x_normalized;
greenY = aGreen.center_mass_y_normalized;
centerX = (redX + greenX)/2;
centerY = (redY + greenY)/2;
panMove = (tan((PI/4)*centerX))/8;
tiltMove= (tan((PI/4)*centerY))/8;
pan->Set(pan->Get()+panMove);
tilt->Set(tilt->Get()-tiltMove);
}
__________________
2007 Davis/Sacramento Regional Winner (100, 997,
1458)
2008 Davis/Sacramento Regional Gracious Professionalism Award Winner