Jump to content

Mechjeb - How to make SASS chill out, stop wasting RCS, and shaking things apart.


Traches

Recommended Posts

Disclaimer: PID tuning is a complicated field with entire textbooks devoted to it, of which I have read precisely zero. Everything here I learned from wikipedia, a rudimentary understanding of calculus, and some trial and error. My explanations probably range from "not quite right" to "exactly wrong". I'm making this thread because I can't find one that explains mechjeb's attitude adjustment window, which is complete gibberish to anyone who hasn't seen a PID controller before, and can go a long way towards giving sassy a little finesse when flying various ships.

Second disclaimer: Don't come here looking for a debate on the merits of mechjeb and how other people want to play a single player sandbox game. That topic has been adequately discussed on these forums.

Mechjeb's SASS is what's known as a PID controller. Wikipedia's article on the subject has most of what you need to know, but I'll hit the important parts as they pertain to KSP here. These days, Attitude adjustment is one of my most used windows when allowing her to fly.

Sassy is basically a running algorithm that calculates a control input based the difference between your current and desired attitude, both instantaneously and over time. The Kp, Ki, and Kd settings determine the size of that correction. The Tf window determines how frequently she will recalculate a control input (Time per frame? I'm not sure what it stands for), the Ki limit places a limit on the Ki (Integral) factor (more on that later), and the Factor, as best I can tell, is a multiplier for other terms.

Kp is your "Proportional" term. It's your instantaneous, "right now" error. I try to set it at the lowest value that will track my desired attitude without overshooting back and forth past it. Higher numbers will give you more aggressive corrections. If it's too high you'll get more wobble, too low and she'll overshoot back and forth or possibly not make it to your desired attitude at all. Bigger numbers work well for bigger, less maneuverable rockets. Spaceplanes get veery small numbers, sometimes as low as 1 with a factor of 100.

Ki is your "Integral" term. It's a correction that builds up over time from a small, constant error. It allows for correction of small errors that wouldn't be caught by your Kp term. I've never had a ship that needed a Ki term-- I pretty much always leave this at zero. If you do increase it, keep it very small compared to your Kp term or it will cause a lot of instability. There may be times when this is useful, I haven't played with it much. Perhaps combined with a low Ki_limit it could allow you to decrease your Kp term and wind up with a more stable rocket, but I haven't had much success with it.

Kd is your "Derivative" term. It's the slope of your error-- how quickly your error is changing. Once the Kp is set, I increase this value until the jiggling control inputs go away or until it's equal to your Kp term. Never set it higher than your Kp term or it'll get unstable. Frequently, for me, setting this equal to the Kp term gives the best results. This doesn't seem to help with overshooting-- usually that means that your Kd is too high or your Kp is too low.

Tf is how frequently she'll recalculate. .15 is a good middle ground value, but adjusting it can help when dealing with a ship that flexes, or with varyingly responsive ships. Basically, if your rocket flexes back and forth at approximately the same rate that sassy is figuring control inputs, they'll resonate and you'll get more and more flex. .05 is the lowest (fastest) I go, and .3 is the absolute highest (slowest). Play with it until the wobbles go away. It's kinda like caffeine and sleeping pills for Sassy- Too slow and she'll be sluggish, too fast and you'll get control inputs jiggling all over the place.

Ki_limit is a limit to your integral term.Since your Ki term builds up over time, this puts an upper limit to how much of a control input you'll get from it. Since I never use a Ki term, I never adjust this, and therefore can't provide much wisdom on setting it.

Factor is a multiplier for the Kp, Ki, Kd, and possibly the Ki_limit terms. (As best I can tell.) It can save you some zeros in the other boxes, or if you want to adjust things more precisely than I have patience for (i.e. closer than an order of magnitude) it can probably save you some time.

If you're tuning from scratch, I like to start with a Kp of 100000 or so, Ki and Kd of 0, a Tf of .15, and a factor of 100000. When adjusting Kp, Kd, and Factor, I just add or remove zeros until I get the result I want. The updates are instantaneous; as soon as you change a value in a box it's effective. You don't have to push enter or move the cursor anywhere. While tuning Sassy, I like to point her at a given direction (prograde, for example) and watch the control inputs she's making (staging mode, lower left corner). It can be helpful to move around to different aimpoints (normal + and -, etc.) to figure out how well you're doing. It takes a little practice, but eventually you can tune up a rocket pretty quickly. I usually set Kp first, adjusting factor as well if necessary, then set Kd, then adjust my Tf if necessary. You're obviously not locked into any specific order; as you get some terms close problems in others may become more apparent. If you want to do a super quick and dirty tuning, say because your rocket is shaking itself to pieces and you don't have time to do it properly, you can just adjust the factor and Tf windows to get approximately close.

Hope this is helpful, and input's appreciated!

Link to comment
Share on other sites

I use the builds Sarbian put out. No PID adjustables in it anymore, just Tf.

I experimented with chAnging PID values extensively before, way back whenand never saw any change in RCS usage. Only the Sarbian builds had any beneficial effect on that

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...