# PID Tuning Help

### Help Support The Rocketry Forum:

#### Yukon@K-9 Rocket Tech

##### Just a teen who likes building rockets
TRF Supporter
Hi everyone, I am rather in experienced with PID tuning and PID in general, and need some help. I want to tune PID for a model rocket I built with active fin stabilization, and another one with a gimbaled motor. I want to know what is the best way to tune the PID, and what experience anyone has with tuning PID.

I have looked into drone PID tuning, but it was just flying your drone around and tweaking it depending on the drone’s reactions. I wouldn’t want to fly a rocket a ton of times to tune it every time I built a new one (would be expensive too LOL). The method I was thinking of building a simple rocket and buying a bunch of motors, then tweaking it until I reach a good PID value. Then I would proceed to measuring the Mass Moment of Inertia of the rocket, and from there getting a PID value to MOI ratio. Would this work? And does anyone have or know any better ways?

Lastly, I would like to mention the Integral value. If the rocket is sitting on the pad, the I value would only see a rocket at standstill. Then when it launches, probably the system would go crazy. So the trick I was thinking of was a pad system that would boot up the flight computer maybe 30 seconds or so before liftoff. With proper tuning is this even necessary?

Thanks for all your help! Everyone here is so helpful and amazing.

#### jderimig

Assuming you have a stable rocket without the stabilization and a very good gyro do a test flight and program a step change correction in each degree of freedom and see how the rocket responds. Then you can create a crude dynamic model that can get you close to starting values. After that its trial and error.

#### Voyager1

##### Well-Known Member
TRF Supporter
There several threads on the forum and net discussing thrust vector control of gimballed motors and canard control. Here are a few:

https://www.rocketryforum.com/threa...the-help-of-thrust-vector-control-tvc.150285/

https://bps.space/

There are many more if you do a search on “active stabilisation of rockets”.

Good luck, it’s a fascinating topic. John’s suggestions are a great place to start to get a feel for the rocket’s flight behaviour and the corrections necessary for stabilisation.

Last edited:

#### OverTheTop

##### Well-Known Member
TRF Supporter
Keep the gains low. You don't want neck-snapping corrections. I think, based on my experience, the gains required are lower than you might expect, especially anything related to roll.

If you don't expect absolute precision to the vertical vector you can just use proportional gain to keep it simple, and dual in some integrator later.

Derivative can introduce noise into the loop if the filtering is not reasonably right, so is probably more trouble than it is worth. PI works well most of the time.

#### Serac

##### Well-Known Member
You've received a lot of good suggestions: be sure to mitigate integrator windup, start with low proportional values, and only add derivative feedback if your velocity measurements are fairly noise-free (filtering them will smear them and introduce lag which is not your friend).

You mentioned relating the gains to the moments of interia, which is a good idea. Also consider scaling/normalizing your gains by the aerodynamic force of your fin. Generally, your controller is going to need larger fin deflections at lower speeds, and smaller fin deflections at higher speeds. The aerodynamic force of the fin deflection is a function of the dynamic pressure and the aerodynamic lifting and drag coefficients of the fin. You can compute/estimate the dynamic pressure in your controller. The aero coefficients are a lot more difficult. If you constrain yourself to small deflections with small angles of attack, textbook references may still apply because you'll generally stay in a linear region. Beyond that, it is trial and error (or if you have access to a wind tunnel, lots of experiments).

Keep up posted of your progress! I would like to do something similar. I'm trying to get more high power experience first, though.

#### Yukon@K-9 Rocket Tech

##### Just a teen who likes building rockets
TRF Supporter
https://en.wikipedia.org/wiki/PID_controller#Loop_tuning

Note that the resulting gains apply only to that particular configuration. Change the rocket and the gains change.

Keep the integrated error pegged at zero until you detect launch. Or enable control. See also windup.
Assuming you have a stable rocket without the stabilization and a very good gyro do a test flight and program a step change correction in each degree of freedom and see how the rocket responds. Then you can create a crude dynamic model that can get you close to starting values. After that its trial and error.
Thank you very much! Will check all of them out!

#### Yukon@K-9 Rocket Tech

##### Just a teen who likes building rockets
TRF Supporter
Okay, so there is no real way to get PID values right on the money except with trial and error correct? And lower values are generally better then too high values so the vehicle over corrects.

#### jderimig

If your dynamic model is correct then you calculate them. The problem is you will not have ideal actuators.

#### OverTheTop

##### Well-Known Member
TRF Supporter
And lower values are generally better then too high values so the vehicle over corrects.
Use lower P & I coeffecients. That keeps the loop gain down and bahaviour less oscillatory. You just want a nice over-damped response so you are not wasting energy with oscillations. Under-correction is the way to go!

#### Alan15578

##### Well-Known Member
Okay, so there is no real way to get PID values right on the money except with trial and error correct? And lower values are generally better then too high values so the vehicle over corrects.
Of course there are ways of setting PID gains "right on the money". It is called control system analysis and design. There are many books on the subject. You could even take some college courses. You can actually make a fine career of setting gains and wiggling fins. Even if you don't master the subject you could at least become acquainted with the nomenclature.

Continuous linear time invariant systems are the easiest, but you can use what you learn about them to help understand more complicated systems. Root locus is the classic tool to set gains, and you can do that with pencil and paper, although a Spirule can speed things up. In general, you can look at input/output response; Consider an input command or disturbance and see what the output result is. Inject a small or unit sinusoidal signal and sweep the frequency. Plot the output amplitude ratio and the phase shift. This is the frequency response or Bode Plot and it can give you the gain and phase margin, or where you have stability problems. Consider the response to a step input: What is your rise time, peak overshoot, and steady state error? Or consider an optimal control approach, the Linear Quadratic Regulator, LQR. You could for example pick some weighting factors to try and minimize induced drag and battery power consumption. You will have to solve an Algebraic Matrix Riccati Equation, but that is a solved problem, and it will determine the optimal gains that you seek.

PID control is often ideal for a regulator. That is, to hold a system at some desired condition in the face of disturbances. Consider the step input response: to decrease the rise time increase the Proportional gain (and or increase the control fin size). If the peak overshoot is too high, increase the Derivative gain. Add some Integral gain to control steady state error. Repeat the adjustment or tuning until you get a response "right on the money."

Now a rocket is not a linear time invariant system. You could do a number of LTI point designs to find suitable gains over the range of flight conditions and smoothly change the gains over the flight as q, mass, CG, and inertia change. Most likely you have purchased some black box components that you do not have complete specifications and analytical models for. They are likely sample data subsystems and they may not even use the same sample rate or synchronicity. Your actuators will undoubtedly have rate, power, and position limits, as well as gear backlash, stiffness, linkage slop, etc. You could have a limit cycle oscillation, overheating problems, and a thousand other problems. You probably don't have the time and expertise to work through problems. On the other hand, plug and pray may work.

A rocket is also not a typical drone. Rockets bodies are flexible with mode shapes and frequencies. You want to put accelerometers at the first bending node, and gyros at the antinode. You will want an analog bandpass filter to attenuate sensor response beyond the sampling frequency, and you may need notch filters at the mode frequencies as well. Isolating the sensors with foam can also help.

It's almost like this is rocket science or something. In any event, dogs are better than cats.

#### Dan Griffing

##### Well-Known Member
TRF Supporter
you can just use proportional gain to keep it simple

I took numerous process control classes while working on my engineering degree in the 70's and spent a significant part of my career applying PID controls. PID is still the bedrock of feedback process control and tuning the controller algorithm is not a trivial thing.

Applying PID's to rocketry fin stabilization is quite difficult because its such a fast and temporal process with changing dynamics that control stability. The general advice is to start with proportional gain only and to increase it gradually. But this is difficult when each trial is a launch and precise measurements are difficult.

The (I) integral mode applies correction by summing the error over time so too much of this parameter results in "wind-up" which causes over-control. For such a fast event as a rocket flight it would be hard to have this work right.

The (D) derivative mode applies correction in proportional to the change in error in each time interval, so its really sensitive to any error in measurement. Even in the best situation, derivative control act like Mick Jagger on acid, so I'd not recommend it.

But PID control works with high speed processes like motor control, as well as glacially slow processes like temperature control, so if you get the timing for the speed of controlling any process right, you can use all three modes. But for anyone but a real rocket control engineer, with dynamic modeling tools, it would be difficult to get this figured out.

Good luck.

#### Dan Griffing

##### Well-Known Member
TRF Supporter

I took numerous process control classes while working on my engineering degree in the 70's and spent a significant part of my career applying PID controls. PID is still the bedrock of feedback process control and tuning the controller algorithm is not a trivial thing.

Applying PID's to rocketry fin stabilization is quite difficult because its such a fast and temporal process with changing dynamics that control stability. The general advice is to start with proportional gain only and to increase it gradually. But this is difficult when each trial is a launch and precise measurements are difficult.

The (I) integral mode applies correction by summing the error over time so too much of this parameter results in "wind-up" which causes over-control. For such a fast event as a rocket flight it would be hard to have this work right.

The (D) derivative mode applies correction in proportional to the change in error in each time interval, so its really sensitive to any error in measurement. Even in the best situation, derivative control act like Mick Jagger on acid, so I'd not recommend it.

But PID control works with high speed processes like motor control, as well as glacially slow processes like temperature control, so if you get the timing for the speed of controlling any process right, you can use all three modes. But for anyone but a real rocket control engineer, with dynamic modeling tools, it would be difficult to get this figured out.

Good luck.
On second thought, when you analyze the rocket itself, it already has a built-in proportional feedback stability control loop with the static fins. and its over-damped when the stability margin is over 1.0.

With this as the default innermost nested loop of feedback control, the next layer out can be a controller that has unity proportional gain, and just a little integral gain to adjust the vertical direction that the rocket is going, or a slight adjustment of the fins to reduce rocket rotation around its principle axis.

The integral mode control parameter should be just sufficient to nudge the rocket towards vertical, (if that’s the control objective) at a rate that’s over the time of the rocket’s vertical flight, but if it’s too aggressive a nudge, it will cause an over-correction from what control engineers call integral mode “wind-up”.

To begin estimating the value for the integral mode control parameter use a graph of the vertical height and horizontal distance of a flight versus time. This is the total error correction that integral control must adjust for, and the time frame over which the integral correction must occur.

Now this is only the starting point of the analysis because it doesn’t take into account how you would measure the error variable of the divergence from vertical, or how much to adjust the fins, but process control can be a very difficult thing to do successfully, even when its not part of rocket science.

#### UhClem

##### Well-Known Member
On second thought, when you analyze the rocket itself, it already has a built-in proportional feedback stability control loop with the static fins. and its over-damped when the stability margin is over 1.0.
Hmmm. It is usually considered to be underdamped and this is the preferred condition. Not depending very much on CP/CG margin since this is dynamic stability.

#### Dan Griffing

##### Well-Known Member
TRF Supporter
Hmmm. It is usually considered to be underdamped and this is the preferred condition. Not depending very much on CP/CG margin since this is dynamic stability.
If the margin is close to zero, it’s not damped much at all and it’s “squirrelly” and close to being unstable.

#### UhClem

##### Well-Known Member
You are confusing static and dynamic stability.

#### OverTheTop

##### Well-Known Member
TRF Supporter
On second thought, when you analyze the rocket itself, it already has a built-in proportional feedback stability control loop with the static fins. and its over-damped when the stability margin is over 1.0.
As others have said the response is normally under-damped. Keeping the stability margin at one calibre is just a rocketry rule of thumb and does not relate directly to over/critical/under damping. There is normally a some overshoot and allowing this condition results in the least energy loss for the rocket. Critical damping or overdamping actually increases time at non-zero AoA thus dissipating more energy.

#### JimJarvis50

##### Well-Known Member
I haven't used anything but proportional control for my system. I'm not trying to turn the rocket very fast, with adjustment to vertical over a period of maybe 2-5 seconds, so more elaborate control might be helpful for more rapid adjustments. Several examples of the response I've seen are attached. The one that oscillates was a very tall rocket.

Jim

#### Attachments

• 188.1 KB Views: 8
• 106.8 KB Views: 5
• 68.9 KB Views: 5
• 69.1 KB Views: 4

#### Dan Griffing

##### Well-Known Member
TRF Supporter
As others have said the response is normally under-damped. Keeping the stability margin at one calibre is just a rocketry rule of thumb and does not relate directly to over/critical/under damping. There is normally a some overshoot and allowing this condition results in the least energy loss for the rocket. Critical damping or overdamping actually increases time at non-zero AoA thus dissipating more energy.
While a unity stability margin is only a rule of thumb, a larger one is more stable than a lesser one, and zero is unstable.

Damping is a mathematical engineering concept, and overdamped means that oscillations decay with time. A larger stability margin means a more overdamped and stable system, just like a longer arrow is more stable than a short one. Look at the Wikipedia article for the actual definition.

#### OverTheTop

##### Well-Known Member
TRF Supporter
While a unity stability margin is only a rule of thumb, a larger one is more stable than a lesser one, and zero is unstable.
If you are talking about damping ratio then one is critically damped, less is underdamped, more is overdamped. The confusion is creeping in above as people seem to be confounding this with the one caliber rule for static stability.

Damping is a mathematical engineering concept, and overdamped means that oscillations decay with time. A larger stability margin means a more overdamped and stable system, just like a longer arrow is more stable than a short one. Look at the Wikipedia article for the actual definition.
I am aware of the definition as I am an engineer by profession. My comment about damping still stands. A mildly oscillatory behaviour during damping of AoA towards zero during flight results in less energy being dissipated in maneuvering to vertical.

#### Dan Griffing

##### Well-Known Member
TRF Supporter
If you are talking about damping ratio then one is critically damped, less is underdamped, more is overdamped. The confusion is creeping in above as people seem to be confounding this with the one caliber rule for static stability.

I am aware of the definition as I am an engineer by profession. My comment about damping still stands. A mildly oscillatory behaviour during damping of AoA towards zero during flight results in less energy being dissipated in maneuvering to vertical.
If you are talking about damping ratio then one is critically damped, less is underdamped, more is overdamped. The confusion is creeping in above as people seem to be confounding this with the one caliber rule for static stability.

I am aware of the definition as I am an engineer by profession. My comment about damping still stands. A mildly oscillatory behaviour during damping of AoA towards zero during flight results in less energy being dissipated in maneuvering to vertical.
Really a red herring and beside the point.

I was talking about the fins and Cd being behind a Cg as acting like the inner most loop of an inherent, natural proportional control system were an additional outer loop wouldn’t have to focus as much about stability so it could use the integral mode instead.

This has nothing directly to do with energy dissipation with the level of the damping that already exists.

Instead it was about using an additional level of integral mode control to gradually steer a rocket more vertically to reduce the horizontal component of velocity at apogee.

Incidentally, and only incidentally, the addition of an Integral element of control slows down the system frequency response as demonstrated on the system response P-A diagram, and this actually dissipates less energy. But that is advanced control engineering arcana, and not even the purpose for the additional level of control.

(Engineers by profession, which both of us are, often disagree because there are many specialized areas within engineering where all engineers are not equally qualified. But hopefully we won’t mislead the less technically educated by letting the argument between us drift into confusing and irrelevant jargon that no one else understands.)

#### OverTheTop

##### Well-Known Member
TRF Supporter
I see no fish, pickled or otherwise .

I was talking about the fins and Cd being behind a Cg as acting like the inner most loop of an inherent, natural proportional control system were an additional outer loop wouldn’t have to focus as much about stability so it could use the integral mode instead.
That is effectively an aerodynamic control loop as you have said, stabilising the craft along the flight axis. The damping will depend on static and dynamic characteristic of the vehicle during the flight.

Yes, you could use just an integrator to achieve control to vertical, but integrator gains are usually small, thus slow as you have pointed out. That is why a proportional component in the loop is generally used. It can be given reasonable high gain and and frequency response, thus control quickly, and with an addition of integral the steady-state errors can be driven to zero.

And I think you will still find that the most efficient way to restore a rocket to a vector (ending up with zero AoA on the fins) is to allow a somewhat under-damped response. I have read it somewhere in my Missile Aerodynamics or other aerodynamics texts. It is a little counter-intuitive but it is IMHO a fact. I have done some research along this path as part of my building and flying a vertical trajectory system over the past couple of years.

#### Dan Griffing

##### Well-Known Member
TRF Supporter
I see no fish, pickled or otherwise .

That is effectively an aerodynamic control loop as you have said, stabilising the craft along the flight axis. The damping will depend on static and dynamic characteristic of the vehicle during the flight.

Yes, you could use just an integrator to achieve control to vertical, but integrator gains are usually small, thus slow as you have pointed out. That is why a proportional component in the loop is generally used. It can be given reasonable high gain and and frequency response, thus control quickly, and with an addition of integral the steady-state errors can be driven to zero.

And I think you will still find that the most efficient way to restore a rocket to a vector (ending up with zero AoA on the fins) is to allow a somewhat under-damped response. I have read it somewhere in my Missile Aerodynamics or other aerodynamics texts. It is a little counter-intuitive but it is IMHO a fact. I have done some research along this path as part of my building and flying a vertical trajectory system over the past couple of years.
I don’t think there’s much of a disagreement separating us on that issue.

But this has gotten far beyond simply giving PID tuning advice to a teenage rocket enthusiast from Georgia for his rocket fin control system.

To recap, we had first agreed on advising our Georgia junior rocketeer to use proportional only and to keep it simple.

Then on reconsidering the stabilization by rocket’s stationery fins as a natural, innermost proportional control loop, I remembered what I had first learned over four decades ago in a AIChE seminar on complex nested loop control systems that the inner loop needed to be the fastest, and have proportional only for stable rapid response while the outer loop could have an integral mode for slowly steering the process. The gist of this part of the seminar, which was for chemical engineering control systems in places like oil refineries, was to understand the behavior of nested loops, and not to have them fighting each other, which makes tuning impossible.

I agree with you that while an integrator is one of the features needed in this “outer loop”. I wasn’t at all implying that there wouldn’t be any proportional mode as well.

And I also agree that finishing out and control system correction with the fins having a zero angle of attack (AoA) would be ideal in reduce friction and energy loss, I don’t think that this can be predetermined, a priori, simply by tuning the PID parameters.

Our Georgia rocketeer most likely doesn’t have a dynamic simulator to simulate the behavior of his rocket with various control system parameters, and every trial and error launch is rather expensive, so whatever advice he gets needs to be something he can actually use, and that will give him information he can use to home in on better control.

Because of this, I’m not sure that any of our discussion has been anything but esoteric from his perspective.

#### kbRocket

##### Well-Known Member
TRF Supporter
Of course there are ways of setting PID gains "right on the money". It is called control system analysis and design. There are many books on the subject. You could even take some college courses. You can actually make a fine career of setting gains and wiggling fins.
I am one who has a shelf of controls books, the training of multiple college courses, and at least a decade of my career spent setting gains of mechatronic control systems. I have not yet tried to control rockets though. As my friend and I progress towards multi-stage I am increasingly considering adding a little control to stay within the cylinder and encourage the upper stage to launch at a good angle.

Does anyone know where to find good materials on modeling the dynamic response of a rocket? In order to practice any of the design techniques posted by Alan you need to start with some sort of dynamic model. I'm haven't yet run across information on how to turn the physical properties of the rocket, control surfaces, velocity, air density, etc. into a dynamic model/transfer function/state space model. Thanks in advance.

Lacking a good model that can provide insight into the types of controller structure and gains that may be best, some trial and error probably the best you can do.

Yukon: the suggestion others have made of with a small P gain is prudent. If you subsequently add in an integral term use low gains and if your controller allows you to clamp the integrated error to within a range it would be best. This would hep with the windup error. Booting up the controller 30 seconds ahead of time will not help. Your integrator would still saturate prior to takeoff. Most likely the time to apogee in your rocket is between 5 and 30 seconds. If your integrator cannot act on a time scale somewhat quicker than this it will do no good.

You may first want to try stabilizing the roll of the rocket about it's own axis. Then later mix in pitch/yaw. This decouples your problem and it is probably safer initially working with a rocket that will likely just spin fast about it's own axis when something goes wrong.

#### UhClem

##### Well-Known Member
Does anyone know where to find good materials on modeling the dynamic response of a rocket?
Topics in Advanced Model Rocketry does that. Not state space but enough differential equations to make your eyes glaze over. Sadly once again out of print.

But this may be overthinking the matter. Dispersion Cotrol System for Sounding Rockets certainly doesn't get carried away.

#### kbRocket

##### Well-Known Member
TRF Supporter
I think I may need to find Topics in Advanced Model Rocketry. Pages 24 and 25 of dispersion control start towards something resembling modeling, but don't really get there.

I'm impressed with the TDY-52B. $300 in 1977, up to 65 k of RAM, and fixed point multiply in 174 microseconds. Just imagine what they would have done with a TeleMega. #### OverTheTop ##### Well-Known Member TRF Supporter Does anyone know where to find good materials on modeling the dynamic response of a rocket? I have an eBook somewhere that goes right through developing simulation of rockets for flight. I will try to dig it up. #### Alan15578 ##### Well-Known Member I think I may need to find Topics in Advanced Model Rocketry. Pages 24 and 25 of dispersion control start towards something resembling modeling, but don't really get there. I'm impressed with the TDY-52B.$300 in 1977, up to 65 k of RAM, and fixed point multiply in 174 microseconds. Just imagine what they would have done with a TeleMega.
I was going to suggest any good university library with an engineering department, especially Aerospace Engineering. Try to talk to a professor, they are much better at assessing where you are and where you want to go, and can suggest a more appropriate book. I could suggest some books in my bookcase, but they may be out of print or in much later editions. Topics in Advanced Model Rocketry is not a bad place to start within the Model rocketry literature.

You might be surprised how much real missile guidance you could do with an old CPU and about 16K of RAM. The real geniuses were the engineers that developed missile guidance systems using analog circuits and discrete components. They might have 1/3 of the missile taken up by guidance.

While I recommend the system modelling approach, there are rules for tuning PID controllers to control black box plants, where the only thing you know are the inputs and outputs.

#### kbRocket

##### Well-Known Member
TRF Supporter
I did a little searching for online articles on the equations governing rocket dynamics and control of rockets. I found a number of links to pertinent documents for download. Here they are for your perusal:

Rocket Control
Original Barrowman and extensions
Some good technical publications that try to explain these techniques to hobbyists
Misc:
I haven’t found “Topics in advanced model rocketry” yet. I did find a link within MIT press where I requested a copy https://dspace.mit.edu/handle/1721.1/1701. It isn’t clear if this would be free or \$ or what format it would come in. I will probably not be successful in obtaining a copy this way: “Access is limited to MIT faculty, students and staff.”

After skimming these articles and thinking a little more, it seems like even uncorrected Barrowman should be enough to predict the forces and torques from a movable fin that has been adjusted to a nonzero alpha angle. Then it is simply forces and torques on a rigid body with a motor.

An extension of a simulator such as Rocksim/RASAero/OpenRocket with a way to control fins according to a control law would be an awesome way to explore and gain insight without burning AP. 95% of what is needed is already there. Anyone feel like making that?

#### Dan Griffing

##### Well-Known Member
TRF Supporter
You may first want to try stabilizing the roll of the rocket about it's own axis. Then later mix in pitch/yaw. This decouples your problem and it is probably safer initially working with a rocket that will likely just spin fast about it's own axis when something goes wrong.
An advanced topic in control theory is multi-variable control. This is applicable because the three or four controllable fins on a rocket — can be used to control both the rotation around the rocket’s principle axis, and to steer the rocket towards the vertical.

But on each time-slice iteration the slight change in each controlled fin’s AoA controlled variable needs to be the result of the solution of a matrix of control equations that link the measured rotation and angular tilt with the relevant fins at that point in time.

The whole rocket launch takes place so fast that there might not be sufficient time to do the individual rotation and tilt controls sequentially.