View Single Post
  #22   Spotlight this post!  
Unread 19-01-2009, 17:47
laultima laultima is offline
Registered User
FRC #1458 (Danvillans)
Team Role: Alumni
 
Join Date: Feb 2007
Rookie Year: 2005
Location: Danville, CA
Posts: 87
laultima is on a distinguished road
Send a message via AIM to laultima
Re: Two Color Tracking Demo

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