Jump to content

[0.20] Trimmable ASAS


MajorNr01

Recommended Posts

This Plugin allows the player to change the parameters of the PID-Controler, namely the values of Kp, Ki and Kd. Additionally it seperates the algorithm so that there are different Kp, Ki and Kd for pitch, yaw and roll respectively.

I originally made this plugin for myself and it has become invaluable as it enables using ASAS on any ship. Any ship whatsoever. With correctly trimmed values and a proper Damping value you can even have the ASAS control a vessel on RCS without wobbling or wasting any RCS fuel.

Get it from the Space Port: http://kerbalspaceprogram.com/trimmable-asas/

Link to comment
Share on other sites

They are just variables that determine the weights of the present error (P), accumulated error (I), and prediction of future error (D) in determining how to respond with the controls. E.g. do you want to respond to what it's doing now, what has happened so far, or what you think is about to happen.

Follow the directions here for manual tuning: http://en.wikipedia.org/wiki/PID_controller#Manual_tuning

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.

Link to comment
Share on other sites

Doesn't Mechjeb 2 allow exactly the same functionality (Attitude Adjustment pad)?

omg, almost every equation on that page contains an integral...

Edited by m4ti140
Link to comment
Share on other sites

This mod and this thread seriously need some attention from a smart person who both understands PID controllers and knows how to communicate that understanding to the rest of us. Explain it to me like you're teaching a fresh KSP rookie how to rendezvous and dock.

Link to comment
Share on other sites

Ok, so a PID-Controler is a concept for controling a process or a value.

The value controled by the ASAS is the ship's angular momentum (basically the rotational speed). The values of Kp, Ki and Kd determine, how strongly it should respond to this value (Kp), the integral of this value (Ki) and the derivative (Kd).

Practically speaking:

Kp determines, how strong the ASAS responds to the ship actually spinning fast. The larger Kp, the stronger the control input of the ASAS as the ship is spinning.

Ki is about the integral: The integral of angular momentum is actually your orientation (!). Change Ki to 0 and you will notice that the ASAS will actually no longer hold your orientation, but just kill rotation (the normal, old SAS works exactly the same way as the ASAS, but it has a Ki of 0). So the larger Ki, the stronger the ASAS will respond to your ships orientation wandering off the orientation that it had, when ASAS was turned on.

Kd is about the derivative: The derivative of angular momentum is, well angular acceleration, or the change of your angular momentum over time. So the larger Kd the more the ASAS responds to your angular velocity changing.

Some examples:

Ki = 1, Kp = 0, Kd = 0 will try to hold your ship's orientation, without attempting to actually kill velocity. This will cause oscillations around the target orientation (the ship will turn back and forth (up and down, whatever) continuously).

Ki = 0, Kp = 1, Kd = 0 will try to kill your ship's rotation. This might work, as long as the actual input is not too strong. However it does not respond to accelerations. Might work in empty space, but e.g. for atmospheric flight, this won't hold long.

Ki = 0, Kp = 0, Kd = 1 will try to hold your ship's angular momentum (rotation speed) constant. This produces no input in empty space, because the rotational rate of your ship usually does not change in space.

Combinations of these values will eventually produce something that will properly hold your orientation, without oscillations. However, one thing I experienced is, that a too large value for Ki will cause unstable oscillations, which means that it will turn up and down further everytime. If you have a large Ki, you usually need to compensate for it with a sufficiently large Kp.

Finally, the setup that I use the most is the following:

Kp = 0.3

Ki = 0.2

Kd = 1.5

I found out, that a large Kd helps to kill rotation quickly, without the ship oscillating up and down too much, before it stops.

Also, you can adjust a Damping value, which simply determines, how strong the control input of the ASAS is. With certain larger ships, you might want to turn it down to 0.5 or 0.1. Low Damping values help make a controler that produces less wobbling and will actually hold your orientation.

Link to comment
Share on other sites

All seems very interesting. I wanted a way to maintain orientation without using RCS, this seems like the ticket. Does manual input change the orientation ASAS is trying to maintain? i.e. can I have ASAS on, change orientation manually and have the ASAS keep the new orientation or will it revert?

Link to comment
Share on other sites

@John FX You will have to turn SAS off and back on again, otherwise it will revert to the original orientation. The reason for this is, that the part internally stores an integral value, which determines the orientation that ASAS is trying to maintain, and this value only resets, when SAS is turned off and on again.

Also keep in mind, that all which ASAS does is use the control inputs to steer the craft for you. I am not sure, what you were trying to say, but you still need a means of actually controlling your space craft, such as a torque providing part or RCS thrusters.

You can, however, trim the ASAS appropriately to basically (almost) stop using RCS fuel, once your ship is pointing in the target direction.

Link to comment
Share on other sites

This sounds very interesting, even if it will take a bit of work to figure out good values, I assume. I really hate the "jitter" that RCS and ASAS introduce on light space probes, continuously trying to (over)correct orientation/velocity even without any input by me (so it should just keep still...). Especially annoying during docking maneuvers...

Link to comment
Share on other sites

Ok, so a PID-Controler is a concept for controling a process or a value.

The value controled by the ASAS is the ship's angular momentum (basically the rotational speed). The values of Kp, Ki and Kd determine, how strongly it should respond to this value (Kp), the integral of this value (Ki) and the derivative (Kd).

Practically speaking:

Kp determines, how strong the ASAS responds to the ship actually spinning fast. The larger Kp, the stronger the control input of the ASAS as the ship is spinning.

Ki is about the integral: The integral of angular momentum is actually your orientation (!). Change Ki to 0 and you will notice that the ASAS will actually no longer hold your orientation, but just kill rotation (the normal, old SAS works exactly the same way as the ASAS, but it has a Ki of 0). So the larger Ki, the stronger the ASAS will respond to your ships orientation wandering off the orientation that it had, when ASAS was turned on.

Kd is about the derivative: The derivative of angular momentum is, well angular acceleration, or the change of your angular momentum over time. So the larger Kd the more the ASAS responds to your angular velocity changing.

Some examples:

Ki = 1, Kp = 0, Kd = 0 will try to hold your ship's orientation, without attempting to actually kill velocity. This will cause oscillations around the target orientation (the ship will turn back and forth (up and down, whatever) continuously).

Ki = 0, Kp = 1, Kd = 0 will try to kill your ship's rotation. This might work, as long as the actual input is not too strong. However it does not respond to accelerations. Might work in empty space, but e.g. for atmospheric flight, this won't hold long.

Ki = 0, Kp = 0, Kd = 1 will try to hold your ship's angular momentum (rotation speed) constant. This produces no input in empty space, because the rotational rate of your ship usually does not change in space.

Combinations of these values will eventually produce something that will properly hold your orientation, without oscillations. However, one thing I experienced is, that a too large value for Ki will cause unstable oscillations, which means that it will turn up and down further everytime. If you have a large Ki, you usually need to compensate for it with a sufficiently large Kp.

Finally, the setup that I use the most is the following:

Kp = 0.3

Ki = 0.2

Kd = 1.5

I found out, that a large Kd helps to kill rotation quickly, without the ship oscillating up and down too much, before it stops.

Also, you can adjust a Damping value, which simply determines, how strong the control input of the ASAS is. With certain larger ships, you might want to turn it down to 0.5 or 0.1. Low Damping values help make a controler that produces less wobbling and will actually hold your orientation.

I actually wonder if the PID controller is controlling the angular velocity.

I thought it should be controlling the orientation instead of angular velocity.

And thus,

P: describe how strong the control system is trying to rotate the ship into a fixed orientation (the orientation is set when you activate the SAS by pressing T).

I: describe how strong the control system is trying to apply extra control input to overcome some other counter-rotation momentum which causes the vessel not being able to turn to the fixed orientation in a period of time. The integral part will grow with time until it reach some limit (usually there will be a limit for that).

D: describe how strong the control system is trying to kill the derivative of the orientation (which is angular velocity actually).

the Damping value may be for the control output, which can avoid too rapid changes of control so that it wont says "RIGHT! LEFT! RIGHT! LEFT! ...", but will be more like "RIGHT! SLIGHTLY LEFT! SLIGHTLY RIGHT!". However, if the damping is set too high, the control output will be lagging too much and this itself will result to oscillation.

So a pure D controller will be more like a simple rotation killer which won't try to point to a fixed orientation, but just kill your angular velocity. Adding the P component will allow it to try pointing to the fixed orientation. Adding the I component will enhance its adaptability to external rotation momentum. (usually due to aero-forces or inbalanced CoM, etc. )

For anyone who has played the game "Orbiter", the KillRot option in that game is just like a pure D controller, (may or may not have the I component) which only kills rotation but won't help you to point to a certain direction.

A more simple example:

Suppose you are trying to maintain the position of a ball on a flat sheet of iron.

if you want to keep it at the mid of the sheet, you usually will try to tilt the sheet towards the direction, that is the P component.

but you will tilt the sheet into the opposite direction when the ball is getting closer to the destination (to avoid overshooting), that is the D component.

and suppose there is a electric fan nearby, pushing the ball to aside, you will start to tilt the sheet gradually to counter it, and finally you can balance out the fan's influence. This is the I component.

Edited by HoneyFox
Link to comment
Share on other sites

  • 2 weeks later...

Would it be possible to have the option to change all three settings at once or even have it remember what the settings were on the last launch?

Loving the part, it's made my ships so much more controllable but it is annoying setting it up for each launch.

Link to comment
Share on other sites

Oh! This is perfect. Neither mechjeb nor the default ASAS modules seem to work well with vtol craft. What I really need is a roll, pitch controller that ignores yaw, and this does just that!

Hmm... would it be possible to add a z controller?

Link to comment
Share on other sites

  • 2 weeks later...

Oh... I just had to register and say.

Fortunately, I have an explanation to all of this misunderstanding with PID and ASAS!

Both MajorNr01 and HoneyFox are right!

HoneyFox, I see, you understand the work of a PID controller well.

MajorNr01, you've definitely tested the ASAS in game.

The thing is, I think, that the PID parameters are MESSED UP in the game!

I've thought about making some kind of ability to adjust ASAS, but since I don't know anything about plugins, I've made 3 parts with redacted parameters of the .cfg file, just stacked them together to get different combinations and forces and tested them with a balancing on one end stick with mounted RCS...

I've read the wiki page and other stuff. I think, I've understood it quite well.

Kp defines on what angle the counteracting thrust will become 100%

(ie proportional component = the actual deviation value * kp)

Kd defines at what angular velocity (speed of rotation, like rpm or degres per second) the counteracting thrust will become 100%

(ie differential component = inclination of the graph of the deviation value (= speed of rotating) * kd)

Ki adjust the thrust proportionaly a number, that rises or decreases correspodning to how long and strongly the deviation lasts

(ie integral component = the area under the graph (shows, which way the ship is tending to tilt) * ki)

so...

Kp returns the ship to the initial position, but it will overshoot a lot in space, where no drag can slow the spinning, cause your ship to oscillate badly.

Kd will try to stop any rotation, it is the way how turned on SAS works without the actual ASAS module.

Ki helps to keep slighly unbalanced ship pointig in one direction while firing the engines, but there is a limit, based on the maximum gimballing or power of all RCS

but... what we have in game's .cfg is:

Ki behaves as Kp

Kp behaves as Kd

Kd behaves as Ki

I think they were just missconected with actual equations in the game's phisics engine!

I've tried my best to figure that out, and it makes sense for me, so if you don't agree, give me your arguments.

If you agree, we must definitely tell it to the developers!

(please, excuse me for any stupid grammar or spelling mistakes, I haven't had enough practice in english yet)

*edit*

I've said almost the same thing as HoneyFox about a PID controller in common,

but my statement about ASAS in particular I still consider true.

Edited by Absolute Human
Link to comment
Share on other sites

nifty little addon, never liked having to pack an entire planets worth of RCS to get anywhere, but if i understand the explanations, its something to tide us over until the reaction wheels get here in KSP 0.21.0 if anybody has seen that video

Link to comment
Share on other sites

Oh... I just had to register and say.

Fortunately, I have an explanation to all of this misunderstanding with PID and ASAS!

Both MajorNr01 and HoneyFox are right!

HoneyFox, I see, you understand the work of a PID controller well.

MajorNr01, you've definitely tested the ASAS in game.

The thing is, I think, that the PID parameters are MESSED UP in the game!

I've thought about making some kind of ability to adjust ASAS, but since I don't know anything about plugins, I've made 3 parts with redacted parameters of the .cfg file, just stacked them together to get different combinations and forces and tested them with a balancing on one end stick with mounted RCS...

I've read the wiki page and other stuff. I think, I understood it quite well.

Kp defines on what angle the counteracting thrust will become 100%

(ie proportional component = the actual deviation value * kp)

Kd defines at what angular velocity (speed of rotation, like rpm or degres per second) the counteracting thrust will become 100%

(ie differential component = inclination of the graph of the deviation value (= speed of rotating) * kd)

Ki adjust the thrust proportionaly a number, that rises or decreases correspodning to how long and strongly the deviation lasts

(ie integral component = the area under the graph (shows, which way the ship is tending to tilt) * ki)

so...

Kp returns the ship to the initial position, but it will overshoot a lot in space, where no drag can slow the spinning, cause your ship to oscillate badly.

Kd will try to stop any rotation, it is the way how turned on SAS works without the actual ASAS module.

Ki helps to keep slighly unbalanced ship pointig in one direction while firing the engines, but there is a limit, based on the maximum gimballing or power of all RCS

but... what we have in game's .cfg is:

Ki behaves as Kp

Kp behaves as Kd

Kd behaves as Ki

I think they were just missconected with actual equations in the game's phisics engine!

I've tried my best to figure that out, and it makes sense for me, so if you don't agree, give me your arguments.

If you agree, we must definitely tell it to the developers!

(please, excuse me for any stupid grammar or spelling mistakes, I haven't had enough practice in english yet)

o_o Oh... Ki behaves as Kp? Kp behaves as Kd? Kd behave as Ki? ... Well maybe it's Squad's decision. Or is it a PID controller of angular velocity? no i don't think so... because it won't be able to keep pointing to a certain direction if it's a controller of angular velocity.

If your statement is true, a pure D controller (read as rotation killer) should only need Kp (which actually behaves as Kd) without Ki/Kd. have you tested that?

BTW, mechjeb's autopilot system (and some other flight control plugins) is using the original way (Ki behaves as Ki, Kp behaves as Kp, Kd behaves as Kd)... I think i've read some codes of that project sometimes ago...

Edited by HoneyFox
Link to comment
Share on other sites

I'm not quite sure...

A PID controller of angular velocity is possible, but it is maybe useful in some kind of motors/wheels/propellers, not in directing a cpacecraft.

It must be the angle of rotation, that is being messured and adjusted, otherwise it doesn't make any sense.

Yes, i tested it like you said. For a differential asas i wrote

Ki = 0

Kp = 1

Kd = 0

for proportional

Ki = 1

Kp = 0

Kd = 0

for integral

Ki = 0

Kp = 0

Kd = 1

and then it began to work like i think it should:

Kd asas was killing rotation

Kp asas was trying to point the ship in a specific direction. (but realy was making it a kind of pendulum)

Kd + Kp combo worked like an ordinary asas without gravity,

but slighly failed to return exactly in the initial position, when my 'stick' like craft was balancing standing on the ground, aimed about 30 degrees from vertical. It was always missing few degrees up to the intended position.

Ki asas did almost nothing without others, but Kd + Kp + Ki worked nice, and, i think, it cleared those few degrees properly.

I've tested different values too, it was responding properly, like if I decreased the values, then

Kp was firing less furiosly on the same degrees, and came to 100% on greater angles,

Kd was firing less on the same speed,

Ki changed less noticeably, but I assume it lengthened the time to correct those errors in positioning caused by constant unbalanced force.

what i'm saying, is when you want to create an ajustable asas, you should match those coefficients with:

P- degrees (of the angle when the correcting thrust becomes 100%)

D- degrees / second (of the speed of rotation on which the correcting thrust becomes 100%)

I- degrees * seconds (equals the time of lasting 1 degree error or the number of degrees of error that lasts 1 second to make the correcting thrust 100%)

(Yes, the Ki is tricky, but it is how the integral works- calculates the area of the graph, which is equal to the sum of multiple values of a function)

Of course if I remember the math right :confused:

So the numbers, that MajorNr01 chose, mean

Ki = 0.2 - soft active correcting to avoid oscillation

Kp = 0.3 - a bit tougher killrot to kill oscillation

Kd = 1.5 - higher value to not very sensitive constant correcting.

I find the tuning correct, but I think my way to explain it makes more sense,

and he has just done it by trial and error, not to offend his skills, he might done the plugin well, i don't know about them anything :P

I realy think it is just an occasional mistake of the devs!

Oh, and yes, that isn't likely their intention, it is just the cfg file value, that is hardly ever changed, being set once (probably just by trial and error by the devs themselves)

Edited by Absolute Human
Link to comment
Share on other sites

Ok,ok, some edit!

I reread what MajorNr01 has posted...

It makes some sense, because if the input value is agular velosity,

then Kd of it will actually work like Kp of angle, because the differential of angle is agular velosity,

and Ki of it will work like Kp, because the integral of agular velosity is angle.

But Kd doesn't make any sense... why the hell do you need your angular acceleration? It is totally useless... I can't imagine a situation, where it is needed.

You more likely need Kii- integral of integral of your rotation = integral of your angle, which, as I stated, will help you to counteract a constant side force ie wind, more weight on one side, not exactly simmetrical engine thrust, etc. And it actually has this ability. I don't think it is somehow related to the angular acceleration of your ship, it can't realy have any angular acceleration caused by any noticeable external forces at all.

It is only caused by the torque of command pods and rcs, which you don't use while your asas is turned on. So, yeh, it is useless.

It could be at some point intentionaly made by the devs, but, really, they should fix it anyway!

I know, they are doing something with asas due to the next update, but i won't be surprised, if they just stick with what they have and make some unnecesary complex systems of auto adjusting, and not even notice the issue at all.

They've made that crazy system of adjusting fuel consumption with Isp instead of changing thrust, so I'm prepared for everything.

Another update...

I repeated the testing to finally check those things.

I again approve that Kp is killrot and Ki is hold orientation. But Kd is very unclear. I'm not sure if it realy behaves as Ki...

Maybe I was too fast about it, maybe it is realy an angular acceleration controller. I mean, It is very difficult to definitely guess what it is doing just by wathing it, it makes almost none difference in behavior. If Squad really did it as a PID controller of angular velocity, it might be a really strange decision, but they must have some reasons (I hope). And if we wait till the next update, they will hopefully fix everything by themselves. Untill then, I'm done with it.

But,still it would be great to actually replace the coefficients of the Trimmable-ASAS with some precise units of measurement,

I think it is possible, yet not very clear how to figure the numbers out.

Edited by Absolute Human
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...