View Single Post
  #14   Spotlight this post!  
Unread 11-02-2005, 18:43
devicenull devicenull is offline
Robot? We need a robot?
no team
 
Join Date: Sep 2004
Rookie Year: 1234
Location: n/a
Posts: 359
devicenull is just really nicedevicenull is just really nicedevicenull is just really nicedevicenull is just really nicedevicenull is just really nice
Re: AUTO TRACKING!!!!!!:(

Quote:
Originally Posted by russell
The problem is that when it finds a color and I tell it to try to track the color the servos reset to the center position...
I had this same problem. Rather then spend a long time fixing it, I just control the servos right off of the RC.

It's working fine, and is legal (I had thought it wasn't at one point, but there is a question in the Q&A thing that says otherwise, ID 1480)

Here's the code that we are using.. it should be easily changed to other configurations
Code:
//Pan and tilt servos
#define cam_pan pwm01
#define cam_tilt pwm02
//Internal posistion variables
unsigned char cam_p=128;
unsigned char cam_t=128;

if (cam.x == 0 && cam.y == 0) {
		//cam_pan and cam_tilt control the servo's on the mount
		//cam_p and cam_t are our local variables
		cam_pan = cam_p;
		cam_tilt = cam_t;
		//Tell the camera where the servos are,
		//so we get useful values when it finds a target
		camera_set_servos(cam_pan,cam_tilt);
		//What color do we want to track?
		camera_find_color(GREEN);
		//This does all the panning
		cam_p += 10;		//X pan
		if (cam_p > 210) { //if we hit the x limit
			cam_p = 46;		//start over
			cam_t += 10;	//but change the tilt
		}
		//if we've tilted too much
		if (cam_t > 117) cam_t = 97;
	}
	else { 
		//sometimes we get nonsense packets, this fixes them
		if (cam_pan > 0 && cam_tilt > 0) {
			//update the servo and our var with new servo values
			cam_p = cam_pan = cam.pan_servo;
			//update the tilt servo with new tilt value
			cam_tilt = cam.tilt_servo;
		}
	}
The trick here is we fool the servo into thinking the servos are connected to it. We do that with the camera_set_servo command. After it finds a target, we update the servos with where the camera thinks it is. The only thing I wanted to do with this code is get rid of the internal variables that hold the servo posistions.