View Single Post
  #2   Spotlight this post!  
Unread 05-02-2007, 13:31
JBotAlan's Avatar
JBotAlan JBotAlan is offline
Forever chasing the 'bot around
AKA: Jacob Rau
FRC #5263
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2004
Location: Riverview, MI
Posts: 723
JBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond repute
Send a message via AIM to JBotAlan Send a message via Yahoo to JBotAlan
Re: Desperate for help in camera tracking

Quote:
Originally Posted by itsme View Post
*snip*
The rotation is 255-value because the value and the rotation's x axle are upside down (correct me if I'm wrong). All this works pretty fine, (it moves a bit too little, but I think it's correct). Now, the big problem is the tilt direction. I set the rotation of the tilt direction to be the 255-centroid_y value (that means it has to rotate to the PWM value). But the problem is: it just goes up and down and running crazy. Our team doesn't have any idea what's the problem
Our code goes something like this:*snip*
The problem is that the servos are absolute, unlike motors. If you have a servo connected to pwm01, a
Code:
SetPWM(1, 127)
will send the servo to approximately its center point. Instead of measuring how far off you are and adding a small number to that PWM until you have the target centered, you are using 255-centroid y. That is not a magic formula:

Say your camera is happily centered on the target, with (for simplicity's sake) the X and Y servos both at 127 (which will most likely never, ever happen). The camera's FOV (field of view) is 159 pixels wide by 239 pixels tall; therefore the center of it is at about (80, 120). With your formula, the camera would report that the centroid is at (80, 120), and your code would send the Y servo off to 255-120=135 just on the first cycle.

What you really need to do is say (in Jacob-ese pseudo-code):
Code:
if ((centroid_y - 120) > 3) {
move the camera up/down--depends on how it's mounted
}
else if ((centroid_y - 120) < 3) {
Do the opposite of ^ that ^
}
else {
your camera is lined up.
}
Tweak these values if needed. The "< 3" part can be tweaked if you want your camera to be more accurate, but if this number is too small, the camera could end up bouncing back and forth as it overshoots one direction and then the other in rapid succession...

If you need some real code made up, post back and I'll see what I can do; I just think it's better for you to program it. You learn a lot more doing it yourself.

Good luck,
JBot
__________________
Aren't signatures a bit outdated?