# PID control system, with Min and Max outputs

This topic is 4762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm working on a Lunar Lander type spaceship. And have been using PID (well actually PD) controllers to fire the attitude jets and control spacecraft rotation. So far it works great, however I would like to change it so that in addition to giving thruster's a maximum force, Id like them to now have a minimum as well. So that you can't have infinitesimally small thrust forces. Currently thrusters only have a max force, which means that when stopping a rotation, I often see them use a small gradual force that gets infinitesimally small as the ship stops rotating. Which seems unrealistic, since I'm sure most real thrusters would have a minimum force or minimum burn time precision. So my question is, How can I do this? What kinds of modifications will be needed to the control scheme? I'm not sure a simple PID will cover this situation anymore....It might end up with occilation problems ie: PID requests thrust below Min range command gets ignored by thruster spacecraft rotates beyond goal PID requests big thrust to correct orientation spacecraft spins the other direction Repeat Is that situation (theoretical for now) going to be a big pitfall with Min thrust forces? and how do I adapt the PID control scheme to handle that as well? I suspect that additional kjnowlege is needed. I only know rudimentary PID stuff from experimentation, I dont have a full knowlege of Control Systems. Advice please? Thanks

##### Share on other sites
Unfortunately, if you're using the basic feedback equations all they give you is the theoretical feedback necessary to satisfy the control. They don't really take into account any of the practical or physical constraints of the actual system. So you're going to be stuck just clamping the desired feedback to your min/max range. As you mentioned this will produce an oscillatory response if the desired feedback is less than the minimum, however there's not much you can do besides lowering the minimum thrust. You could also modify your gains, but by increasing them too much you'll potentially induce oscillatory or unstable responses for thrusts that are within range. How are you determining which gain constants to use at the moment? Do you have a specific response time in mind or are you just experimenting with values that produce nice-looking results?

##### Share on other sites
I just keep trying different values till it seems to work; I dont have a formal understanding of the mathematical background, I just try to recognize correlations between behaviour and the P, D values I put in.

How do real spacecraft deal with this kind of limitaiton?
Occilate but keep trying to fix it?
Switch to Reaction Wheels and gyroscopes for small adjustments?

##### Share on other sites
not sure if I understand, but do you just want the output to be within a limit?

do this:
Quote:
 output = m_last_out + m_Kp_gain * (error-m_last_error) + m_Ki_gain * (error+m_last_error)*0.5f + m_Kd_gain*(error - (2*m_last_error) + m_last_error2); if (output>m_max) output=m_max; if (output

Here is a good explananation of PID and a little bit about tuning:
http://www.engin.umich.edu/group/ctm/PID/PID.html

##### Share on other sites
Quote:
Original post by aboeing
not sure if I understand, but do you just want the output to be within a limit?

do this:
Quote:
 output = m_last_out + m_Kp_gain * (error-m_last_error) + m_Ki_gain * (error+m_last_error)*0.5f + m_Kd_gain*(error - (2*m_last_error) + m_last_error2); if (output>m_max) output=m_max; if (output

Here is a good explananation of PID and a little bit about tuning:
http://www.engin.umich.edu/group/ctm/PID/PID.html

Putting the output into a limit check is easy.
The question is, now that you've done that, how do you get the spacecraft to behave nicely?
truncating the outputs introduces potential occilation problems that will now need to be solved.

I suspect that this question goes Beyond PID controllers and requires intervention from other areas of Control Systems, which I dont know about yet.

##### Share on other sites
I believe my last response was a little incomplete. On a real rocket thruster you'd have a minimum thrust plus zero thrust, when the rocket is off. So there's a small gap between no thrust and the minimum amount of thrust that the rocket can provide due to the nature of the combustion. In a real spacecraft you'd have thrusters on both sides of the ship to counterbalance each other, and you'd want to control the net thrust. Since the net thrust is the difference between the two individual thrusts, you establish a possible thrust range of [0, MAX_THRUST - MIN_THRUST]. To get zero thrust, either turn both rockets off or turn both rockets on at the same power. Then adjust them appropriately so that the net thrust is what you want. If one thruster is on maximum power and the counteracting thruster is on minimum power, you get the maximum net thrust of MAX_THRUST - MIN_THRUST. Turn the counteracting thruster off and you get a maximum of MAX_THRUST, but then there's a gap of MIN_THRUST at the top end of your range. With multiple thrusters things get interesting, as the thruster turning the spacecraft toward the desired heading will want to use a proportional controller while the thruster counteracting the rotation will want to use a derivative controller. At least I think, I don't really have any experience designing rocket controls for spacecraft [smile] But it makes sense, as the first thruster is "interested" in getting the spacecraft to its goal while the second thruster is "interested" in keeping it there and minimizing drift.

##### Share on other sites
Quote:
 Original post by haphazardlynamedI just keep trying different values till it seems to work; I dont have a formal understanding of the mathematical background, I just try to recognize correlations between behaviour and the P, D values I put in.How do real spacecraft deal with this kind of limitaiton?Occilate but keep trying to fix it?Switch to Reaction Wheels and gyroscopes for small adjustments?

It's a bitch trying to randomly tune a PID controller. You have to know what the parameters do. The P term gets the system to the state you desire, the D term removes oscillations, and the I term removes constant or steady-state error.

The simple way to tune a PID:
1. Set I and D to zero. Adjust P until the control system responds at the rate you want(ignore oscellation or constant error/offset)
2. Slowly increment D until oscellations are minimized. If this affects the way that the P term works, stop adjusting the D (but don't reset to zero), and adjust the P again until the P part works.
3. Finally, slowly increment the I term until the system works as desired. If you've done the P and D terms correctly, you should have no problems. If you do, then stop adjusting the I term and fix the P term, then the D term. Unless you have a really, really quickly responding system, the I term should be very small.

There are three solutions to the problem of "infinitesimally small forces":
1. If the thrust force gets below a certain threshold, set it to zero. This will accomplish what you desire but you will have large steady-state error that is not fixed with an I term increase(because it is after the PID)
2. Simply force all thrust values to be multiples of a particular value, such as 0.5 or 1, the latter being integral values. This suffers from the same problem as above, but may be simpler to fix with a low-pass filter or such on the output. Still a hack.
3. Use a non-linear controller. You are asking a PID, a linear controller, to accomplish a non-linear task(by having the control effort have a discontinuity at your minimum force threshold)

So sorry, if you want it to work well theoretically you need a non-linear controller. That's what astronautical engineers("rocket scientists") use. They learn a helluva lot of math to do it too. But you might find a hack that works well with a PID.

##### Share on other sites
zipster's idea of pairs of thrusters using Net force to get force values below their limits is interesting
Not sure if thats what a real spacecraft does or not, but should look pretty graphically with all the jets firing
might try that

ethothex -
whats a low pass filter?
can you point me to resources on learning about non-linear controllers?
I'm not necesarailly 'married' to using a PID controller, its just well... 'when all you have is a hammer...'

##### Share on other sites
Quote:
 Original post by haphazardlynamedethothex -whats a low pass filter?can you point me to resources on learning about non-linear controllers?I'm not necesarailly 'married' to using a PID controller, its just well... 'when all you have is a hammer...'

A low pass filter is something which processes a signal (like a control signal) and allows "low" or small changes through, but blocks "high" or fast changes. wikipedia can provide more info. It is a useful tool if you want to "smooth" out something that is jerky or noisy.

On second thought a non-linear controller is not a good idea. The topic of non-linear control is beyond my scope, which makes since because it is typically a graduate level topic. The only free info I could find were research papers and you do not want to learn from those.

The whole problem with non-linear control is that regular linear control, which is well known, is based on estimation theory - which in turn is based on linear algebra, which does not (strictly) apply in non-linear case. However we can approximate a linear case since you only have one discontinuity area.

I think having larger than usual D value might be enough...you could also use two controllers, one for normal use and one for when you are particularly close to the goal point. That way, it would use the normal controller to get close then switch over to the special controller which would be tuned to prevent oscillations (but is slow). Finally you could somehow use one controller but "trick" it into thinking that the minimum thrust value is zero. You won't get oscillations but you will have some constant error in the direction because the thruster shuts off early.

Those are maybe the easiest ways to get non-linear control out of linear controllers.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 12
• 15
• 14
• 46
• 22
• ### Forum Statistics

• Total Topics
634054
• Total Posts
3015275
×