I'm trying to implement the PID Autotune library into my quadrocopter project, since I' struggling to find the correct values of the tuning parameters for PID.
The functions in the Autotune library are not too complicated and I guess I understand the example. As far as I understand, I call the .Runtime() function until it returns 1. Then I overwrite the parameters and let the PID do its thing.
But now: I have the quadrocopter (only one axis for the moment) on something that the axis in question can be turned and the PID has something to do, but the rest is fixed. But what will the Autotuner do while it is tuning? You know, I just can't let the Copter do what it wants, there are fast propellers on it and this can get dangerous. Since the Autotuner doesn't have a target value it can't be trying to stabilize. And further, I'm not sure how to handle the situation, if I just let go of the roboter, it will tip to the side. I guess this will give the Autotuner false information. So could you advise me how to use the Autotuner?
Can you set a bit the context, and explain what you want to regulate with the PID ? What are your current values ?
You would be best off if you can make something to keep the quad under control. Possibly, make a jig by hanging the copter from above with fishing line. On RC helicopters, they use a hula hoop to enlarge the base with a light weight object.
I would think trying to tune the P&ID loops, either manually or with a auto-tune function(s), on a fully functional aircraft and powered platform would be fraught with danger and damage. You must somehow restrain the platform with external mechanical limits and such, ropes, bungy cables, etc. At least that is my thinking on the task.
The context: I have a quadrocopter (a roughly 50cm cross made of aluminium with a brushless motor on each end, with a propeller) and for the moment I'm trying to stabilize one axis (so just two motors are connected).
A fusion out of a gyro- and a accelerometer calculates very accurate the attitude, which is the input from for the PID. The PID may adjust a variable, which is added to one and deducted from the other motor (it may of course be negative).
At the moment a different algorythm overrides the PID and does make sure the rotation speed doesn't get too high.
Unfortunately I don't even have any satisfying parameters. I tried to follow a wiki-article (all the parameters to 0, raise KP until it oscillates, divide it by two and so on) but I didnt take me further. I have no idea, especially for the KI and KD values, since people speak of values of 0.01 and 40 for the same parameter.
So i wanted to use the Autotune Library, but yeah...Not sure how to use it right now.
I'm very rusty on this but I did set up a PID a few decades ago. In that case we modeled the system dynamics and calculated the PID parameters from that, but as a control we also set it up by trial and error and that seemed to work OK (and gave me much less of a headache).
Is the system small / light enough that you can hold it and move it around and feel how the control system behaves? In that case I think you should be able to set it up by simulating a disruption from equilibrium, starting with all gains set to zero and then introducing proportional, derivative and then integral feedback in that order. The crucial thing is to have the vehicle attitude under your control while you do this, not letting it move around unrestrained.
The more I think about it, I’m back to tuning it manually. My problem is, I really have no idea in which range I have to be tuning the values. But I guess I will play with it more. Unfortunately I don’t have any potentiometers here so I have to change the code every time which makes it very complicated.
Probably you experienced guys can me help something: If I tune the parameters, what exactly does change? All the values to 0, raising KP: The motos turn slowly, steady as I raise the value, until I reach something over 1 and it begin oscillating like hell. What are the values really changing? I found some explanations but I can’t mentally take those over to my project.
I visualise it as a classic mass-spring-damper system (a spring and damper in parallel, solidly mounted at one end with a mass attached at the other).
The proportional element is equivalent to the spring - the more deflection (error) there is, the harder this element will try to push the system in the opposite direction.
The derivative element is equivalent to the damper - the faster the deflection is increasing, the harder it will try to oppose it; the faster the deflection is decreasing, the harder it will try to maintain it.
The integral element is like a ride-height controller - if the system is held away from the desired position then it will slowly try to push it back towards the desired position.
When tuning the PID controller, I suggest you tackle the elements in that order: you need to have the proportional element about right to give the system enough authority to correct deflections. On its own this will probably be unstable (unless the system you're controlling is inherently stable) since the correction always lags the error slightly to oscillations will tend to be amplified. Then add damping until the system does not spontaneously oscillate or overshoot - you want the minimum damping necessary to achieve that. Then add the integral element to deal with any tendency to drift or settle away from the desired position.
This approach addresses one degree of freedom. I'd try to deal with each one independently in turn if possible, but you may find that there is cross-talk between them that has to be addressed when you try to combine them - but getting each DoF controlled in isolation is a starting point.