Quote:
Originally Posted by VelocityofGear
Any pointers would be greatly appreciated.
|
Here are
some pointers.
But all jokes aside, you're going to want to use a
PID Controller in order to get your turret to aim. A PID controller is a feedback control mechanism, which, simply put, means that it will calculate the error between your desired value (the "setpoint") and the current value (the "process variable"). So, since you have real-life feedback (your camera) as well as a desired value, you can use a PID controller to "lock onto" the target.
In LV, there's a PID palate, and you place PID.vi onto your block diagram. You will want to wire the offset between the center (x) of the target and the center of the image (
Code:
offset = xCenter - (xResolution/2)
) as the process variable to the PID controller, and put the setpoint at 0 (you want the center of target to be exactly in the center of your image). You will have to make sure that the output ranges are scaled properly, and also that the input ranges are both scaled to the same units (you shouldn't have to do any scaling in this case - both are a pixel offset).
Then comes the hard part. You'll have to tune the parameters of the controller. There are three parameters: P (proportional), I (integral), and D (derivative). See the links in my last post for some common approaches and read through
this section of the wikipedia page for how the gains work.
And if you can't get this to work, there is a simpler (but much less robust method). You could figure out the sign of the offset between target center and image center. This will tell you if your turret needs to move left or right to get centered. Then, you can either send a positive or negative value to your motor, depending on the direction and keep a constant value sending until the offset is within a threshold for the center, when you stop the motor. This is similar to the approach you started with.
I would recommend going with a PID solution because it's much more powerful and robust than the other way, but it does take some time and effort to get right. There are a lot of resources
out on the internet and
around ChiefDelphi for you to use. And as always, feel free to ask questions.