View Single Post
  #16   Spotlight this post!  
Unread 15-02-2005, 19:27
Code\\Pilot Code\\Pilot is offline
< Only smart people see my avatar
AKA: Rafael Estrada
FRC #1065 (Tatsu)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Florida
Posts: 53
Code\\Pilot is an unknown quantity at this point
Send a message via AIM to Code\\Pilot Send a message via MSN to Code\\Pilot
Re: AUTO TRACKING!!!!!!:(

Quote:
Originally Posted by devicenull
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.
when do you tell it to stop and go for the tetra??
__________________
Join the Red revolution, give me some RED rep!!!!
if it doesn't work, don't force it. Go get a bigger hammer.

int run = 0;
int robot_chasing_you = 1;

if (robot_chasing_you)
{
run = 254;
}

I got 48 Gmail invites left, pm me with your e-mail so i can send you one.