# Camera track and drive integration code

After 3 years of frustration, broken cameras, and bad programming, I finally got the camera to track the light. (Kevin Watson, you are a god!) Now that a third of our autonomous code is done, all we have left to do is get the bot to move towards the light once the camera has locked on, and then have it operate our arm mechanism. I pretty much know how to write the code to operate the arm, but I have no idea how to go about getting the bot to track to the color.

From what I’ve been reading, I’m under the impression that Kevin’s code has a function that does this, but I haven’t been able to find it. Then again, I could be completely wrong about this. If I’m correct, which function would it be? And if I’m not, could someone point me towards where I could find the code that does this or a resource that will teach me how to (preferably the former). Any help is much appreciated.

I have not read through Kevin’s code completely but I have yet to see code that will align the robot for you. Given the wide range and style of drivetrains I wouldn’t think that would be practical.

Kevin’s code does however give you convient access to the pan and tilt angles and using what you know about trigonometry you should be able to work out a way to figure out what you need the robot to do. Another thing to consider is when you have a large blob size then you know you are either tracking two green lights or have a green light very close to the camera (unlikely in a competition). Using that data you should be able to work out how far you need to go forward before you can play your peice.

Basically,

pwm01 = 124; // camera’s PAN servo
pwm09 = 127; // left wheel
pwm10 = 127; // right wheel

if (pwm01 > 127)
{
pwm09 = 0; //turn left
pwm10 = 254;
}
else if (pwm01 < 127)
{
pwm09 = 254; // turn right
pwm10 = 0;
}

Now … this way is simple! but its not effective… again… u have to use trig and some math as well to calculate where the object is… either way… it works… and this year… u will not have to worry about the camera tracking more then 1 light at a time… thats a majorly different story and takes too long to understand and program… so first focus on allowing the robot to align itself, then drive forwards and backwards.

EDIT: WOW… ok … i am not thinking today! its like 2am… for my code… i got really lazy … i just point the TILT to the target is that the values would be centered… if it was greater then that number… move backwards… …else if it was less then that number… move forwards,… very simple…

Also in my code… for it to drive forwards, backwards, left and right. i just pasted my values into the 1 joystick drive code.

pwm09 = Limit_Mix(2000 + PAN + TILT - 127)
pwm10 = Limit_Mix(2000 + TILT - PAN + 127)

Also keep in mind that the height of the camera effects all ur values… have fun…