Go Down

Topic: Controlling an animatronics bust (Read 5 times) previous topic - next topic

Retroplayer

Thanks, given that I now know a bit more about this thanks to you guys, I will have another look at the PID library. I may come back with some questions, of course.

Retroplayer

They definitely need better examples for the PID library! Grr!! I do understand it a little better now, though.

The library takes these values:

input
output
setpos
Kp
Ki
Kd
and mode? I think I want to use DIRECT


So, for each motor, I create an instance of the class (I'll call it just motorPID)


My inputs the current position from the feedback source
My output is just a variable that I use (not sure exactly how yet)
my setpos is the position I want my motor to equal when it is done moving
Kp
Ki
Kd

those are probably going to be different for each motor, aren't they?

The output is going to be a double? And my input is expected to be a double? I have to completely change this library if you know I am not going to be using doubles anywhere, unless I just don't care about the RAM it eats up (which I do.)

I can use the SetInputLimits to 0-255 which is what I will be using for position, except for two which will be 32 and 64

I can use the SetOutputLimits to umm... still not exactly sure what I am doing with the output...

Logically, I need direction which will control a different pin and speed.

Is someone willing to work through setting this up with me?

Retroplayer

Once I get this all going and understand it, I think I might have to write up a much better example for the PID library since controlling motors like this is probably the number one use for it.

laadams85

#28
Feb 07, 2013, 09:42 pm Last Edit: Feb 07, 2013, 10:13 pm by laadams85 Reason: 1
I'm not very good with the electronics side of this as I am more of a numerics nut, but I will help out at much as I can.  How do you control the motors regularly without PID, what outputs do you send.  How is the motor connected to the arduino.  I know you mentioned this earlier but what are you using to measure position and what is the range of values you get from these.

Edit:  I'll let you figure out the electronics side if it but, it basically comes down to tuning your K parameters.  However you switch the direction of your motor depends on if the output is positive or negative.  I have attached two screenshots showing the calculations with just the P(error) term.  As you can see if I overshoot the set point my output is then negative, this is when you'd switch motor direction.  So you just need to tune your system to give you the desired outputs for your motor.

From wiki
Quote
If the system must remain online, one tuning method is to first set KI and KD values to zero. Increase the KP until the output of the loop oscillates, then the Kp should be set to approximately half of that value for a "quarter amplitude decay" type response. Then increase KI until any offset is corrected in sufficient time for the process. However, too much KI will cause instability. Finally, increase KD, if required, until the loop is acceptably quick to reach its reference after a load disturbance. However, too much KD will cause excessive response and overshoot. A fast PID loop tuning usually overshoots slightly to reach the setpoint more quickly; however, some systems cannot accept overshoot, in which case an over-damped closed-loop system is required, which will require a KP setting significantly less than half that of the KP setting that was causing oscillation.


Retroplayer


I'm not very good with the electronics side of this as I am more of a numerics nut, but I will help out at much as I can.  How do you control the motors regularly without PID, what outputs do you send.  How is the motor connected to the arduino.  I know you mentioned this earlier but what are you using to measure position and what is the range of values you get from these.


Perfect, because I am an electrical engineer, so the electronics are always easy for me, but the code is the devil that haunts me! I am also a bit of a mechanical guru. I would happy to return my help with anything electronic you need!

The H-bridges have two inputs for each motor (all 10 are identical) there is a forward and a reverse pin. A logic high on either of these will move the mechanisms L/U or R/D respectively. 0 and 0 do nothing, 1 and 1 is bad, it will short out the power supply. I am trying to think of a clever way to always control these in a way that they are never high at the same time. If you look at the truth table:

0 0 = No movement
0 1 = Left or Up
1 0 = Right or Down
1 1  = Invalid

You can see that is an XOR, so if I have a way to always tie these two pins together within the code, I can use an XOR operator on them to ensure they are never high at the same time. But that is separate from what we are trying to accomplish at the moment.

As for position, 8 motors have potentiometers connected to them and 2 of them use an optical tach and limit switches.

The potentiometers are straightforward. The tachs and limits are slightly more complex. If you need to know the details of them, just ask, but I am using an interrupt from the tachs in my code already to count between 0 and 32 for one motor and 0 and 64 for another. These numbers align to 1mm of linear travel per step. That work is done.

So, pots will give a position value between 0 and 255 and the linear actuators will give values between 0 and 32 and 0 and 64. I could also just scale the linears to make them also 0 and 255. Not a really big deal.

Go Up