View Single Post
  #7   Spotlight this post!  
Unread 09-02-2012, 22:24
plnyyanks's Avatar
plnyyanks plnyyanks is offline
Data wins arguments.
AKA: Phil Lopreiato
FRC #1124 (The ÜberBots), FRC #2900 (The Mighty Penguins)
Team Role: College Student
 
Join Date: Apr 2010
Rookie Year: 2010
Location: NYC/Washington, DC
Posts: 1,113
plnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond repute
Re: Extrapolating Direction From Images

Quote:
Originally Posted by VelocityofGear View Post
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.
__________________
Phil Lopreiato - "It's a hardware problem"
Team 1124 (2010 - 2013), Team 1418 (2014), Team 2900 (2016)
FRC Notebook The Blue Alliance for Android

Last edited by plnyyanks : 09-02-2012 at 22:28.
Reply With Quote