RimWorld

RimWorld

Not enough ratings
Rimatomics PID Autothrottle
2
2
   
Award
Favorite
Favorited
Unfavorite
Mod, 1.3, 1.4
File Size
Posted
Updated
38.265 KB
2 Dec, 2021 @ 5:39am
12 Nov, 2022 @ 1:43am
3 Change Notes ( view )

Subscribe to download
Rimatomics PID Autothrottle

Description
Replaces the nuclear reactor autothrottle code in Dubs Rimatomics with a faster and more efficient one based on PID control.

Why make this mod?
Dubs Rimatomics offers an autothrottle feature for its nuclear reactors. However, this autothrottle has two drawbacks:
1) It will try to keep the overall power grid load somewhere between 0 and 5kW. Once this is achieved, it is done. This means, that your batteries will only charge slowly, and since Rimatomics uses energy weapons that take Wd directly from batteries (and take a lot of them at once) you may find yourself not having enough power when you need to defend yourself.
2) Once your batteries are full, it will still keep the grid a couple of thousand watts in the positive. Since batteries are at capacity already, the extra power is wasted. Most of you won't care about this considering the plentiful amount of power that comes with Rimatomics, but I don't like to waste anything.

What is PID control?
A control loop mechanism based on continuously checking a feedback value against a setpoint. It is usually used in more technical / industrial applications, typical example being temperature control. A detailed description can for example be read here: https://en.wikipedia.org/wiki/PID_controller
In this case, it adjusts the reactor's control rods in order to keep the power grid's battery charge at a certain percentage. If charge is below, power is increased, if it is above, it is decreased. The battery setpoint is currently 75% by default, you can increase it further in the mod settings (or decrease it) but do not set it to 100% - the system will not know to adjust downwards when power output is too high. I recommend to not go above 90%

How does it work?
The system will continuously check the battery charge percentage of the reactor control console's power grid against the setpoint. It calculates an 'error' value, which is just the difference between the setpoint and the actual value. The output value (control rod position) is calculated based on three parts:
1) Proportional: simply the error value multiplied by the proportional gain value. The larger the difference, the greater the adjustment.
2) Integral: every control loop iteration, the current error is added to the integrated error value. The longer an error persists one way, the greater (or smaller) the integrated error becomes. This value is then multiplied by the integral gain value and added to the result.
3) Derivative: a difference between the current iteration's error and the previous one is also calculated to determine the rate of change over time. This is multiplied by the derivative gain value and also added to the result. This just means that large changes in charge will reduce the response value to prevent overshoot. Derivative gain is not strictly needed for small reactors, but the large ones when fully fuelled have such large power outputs that they will change your battery charge very quickly and the D gain becomes necessary.

What to consider?
Technically, any particular system (in this case this would mostly depend on the reactor's power output) would require optimization of the PID gains. However, if you do not want to deal with this, I do not blame you - the mod comes with a set of default values that should work well enough with any reactor setup, although you might not get perfect battery charge times out of them.

Also please note that there is no "reset to default values" button in the mod settings yet either (this is planned, I just haven't figured it out yet). If you do change the values and forgot the default ones, they are P=2, I=0.00004, D=250. You can also go into your user folder where mod settings files are saved and delete it. That will restore the defaults next time you load the game.

Finally, this mod will only work correctly when you have your reactor power output (transformer), batteries and control console all on the same power grid. Sorry to all of you who use several transformers to feed separate power grids but I haven't found a way to sensibly handle those cases.

All credit for the Rimatomics mod of course goes to Dubwise.
22 Comments
belzebot  [author] 4 Jul @ 11:05am 
Good to know!
MrClue 4 Jul @ 6:57am 
Works perfectly with 1.5 !
Sally smithson 4 Jun @ 12:01pm 
gotcha! Ill be giving it a test in my next run
belzebot  [author] 4 Jun @ 10:32am 
Hi there, I haven't had the time to update this but assuming nothing critically changed in Rimatomics I see no reason why it shouldn't work in 1.5 as it is.
Sally smithson 17 May @ 9:07am 
Does this work in 1.5?
Ethereal 29 Dec, 2023 @ 9:32am 
this mod is so nice to use, makes the autothrottle actually useful!
I prefer to run few batteries, and found that decreasing the D component from 250 to 125 and increasing the set point from 0.75 to 0.9 works wonders.
Thank you for creating this mod!
AAA萨依拉龙息碳烤坦克虫 31 Aug, 2023 @ 9:15am 
why this always keep reactor power level so low , total power always mineral
Realify 4 Jul, 2023 @ 9:54am 
Great mod, thank you!
belzebot  [author] 16 Nov, 2022 @ 10:25am 
thanks :)
cy-one 16 Nov, 2022 @ 9:05am 
Ouh, so it's a "gentle failing" mod, that's nice. I like that!
Good work, belzebot!