|
Re: Shooter Targeting with Camera
The camera defaults to using a coordinate system where 0,0 is in the top right of the image and the sizeX,sizeY is in the bottom right. Since this is pretty meaningless for driving a robot, the example code scales it to be 0,0 in the center with negative 1 at the top edge and positive 1 at the bottom edge.
Since this is somewhat like a joystick, it or the inverse of it should work better to move motors or servos.
The first thing I'd do is hold it by hand and plot the position on a chart or at least display it on the screen. Get a sense of what it outputs. Then pretend to be the motor, moving it according to the output number. This helps you to learn the relative magnitude, directions, and numeric signs of the values involved.
To control the motor, you have several options.
Bang-bang control- Your camera is either above, below, or on target. If below, turn motor at a fixed speed to move it up. If above, move the other way at a fixed speed. If on target (generally less than delta away), leave it there.
Proportional- Similar, but you use the distance away from the target to scale your motor speed to get there faster and slow down as you approach.
PID and other variations - An even more complex method of approaching the target faster but trying not to overshoot and trying to overcome nonlinear elements like stiction. I don't think it is necessary here.
My recommendation is to choose a slow to moderate speed and start with bang-bang or proportional.
Greg McKaskle
|