Stationeers

Stationeers

PID Controller & Filter
19 Comments
micle546 26 Nov, 2023 @ 3:18am 
Added 2 lines to add optional sleep inversion, for those pesky levers to face the correct way.
After "define SPDeviceMultiplier 1":
-Add: "define InvertSleep 0"
and after "l OnState SleepToggle Setting":
-Add: "xor OnState Onstate InvertSleep"
PhoenixKnight314 6 Oct, 2023 @ 5:38am 
This really is an awesome set of code! Is it easy for someone new to stationers with limited coding/ process control experience, no. But with trial and error and learning I have discovered just how powerful this is for controlling things when more than just a proportional controller is needed.

Great work and well worth the tutorials and trial and error to get it working. Using this in a few places, but my favorite application right now is on a system to condense pollutant in a heat pump system :sothappy:
Mr-Chris 26 Sep, 2023 @ 10:33am 
Sorry for the delay... I have been out of town. I will give this a try today and see what happens!
Elmo  [author] 3 Sep, 2023 @ 1:20pm 
@Meester Kreess the best thing about this script is that it is the only thing i have ever released that will never be out of date and stop working. But it's not nesseserily easy to set up. i had 2 courses in university just on how to manage PID controllers ;)

it sounds like you got a case of "integrator windup" https://en.wikipedia.org/wiki/Integral_windup

Long story short: your settings is way to sensitive and accumulates integral error rapidly.
try a much lower Kp and/or a much higher Ti
Mr-Chris 3 Sep, 2023 @ 1:12pm 
I have this thing all wired up and I have the temp and room pressure under control. The volume(fuel) pump comes on for a few seconds when I first take it out of sleep mode. Then it never activates again while the generator is running. The generator runs out of fuel and then about 5 seconds later the fuel pump comes on and just starts pressurizing the line but the generator never activates again. I am not sure what the issue is with this but I am unable to get this script to do much of anything.
I have the generator Pressure as d0
fuel pump as d1
and a sleep switch as d2
set point is 50 but the generator runs at full pressure always
Does this no longer work ??
Universal82 16 Aug, 2023 @ 5:00am 
You are a legend
Xinax 6 Jan, 2023 @ 3:02am 
Is there a way, that I can use 2 PID controller in 1 IC10? I do not need the sleep, so It should work, when I make the PID inside the controller have 2 seperate Variable for them?
Elmo  [author] 22 Jul, 2022 @ 3:56am 
stiefelriemenWill 21 Jul, 2022 @ 11:58pm 
can u please make a video for dummies for the airconditioner how to setup everything? sorry for my bad english im using google translator. im 12 years old and using my brother pc thank you :steamhappy:
Soondead 22 Feb, 2021 @ 12:17pm 
@Elmo I already have a setup for collecting, cooling and recycling the hot waste because running both input and output at the same time was always part of the plan. THANK YOU SO MUCH for the numbers, I'll try them right away! They're way, WAY higher than anything I ever tried, mostly because PID tuning is a big mystery to me :-)
Elmo  [author] 22 Feb, 2021 @ 12:10pm 
so in order to get a very slow and relaxed controller, in your case, the first thing i did was to bump up the filterTicks to 50 (average over 25 sec). Kp can stay at 0.1 With a high Ti at 200
alternatively Kp = 0.01 and Ti=20 allso gained good results.

what i ended up with was a steady input on the furnace at 13-14% with temps between 1000*C and 1500*c (SP=1250) because of the ignition limits. you want to be aware that with that setup it might have both input and output open at the same time so it might end up ejecting fuel. if you aren't already you might want to capture it and reuse it.

To improve on this you can try to tinker with the numbers some more, but because of the game limitations on ignition you might want to rethink the design. i'm not quite sure how but i would suspect having a continuous flow both in and out of the furnace, and reusing some of the gasses and controlling fuel injection might be the way to go.
Elmo  [author] 22 Feb, 2021 @ 12:10pm 
@Soondead
really cool base btw

Furnace control is very interesting because as you touch on, you whon't get ignition before the fuel mix makes up 5% of the atmosphere in the furnace. i don't see the delay between temperature dropping below SP and the controller kicking in (maybe a tick or two), although the output may just be too small to display when close to SP.

Nevertheless when working with system delays like this it's easier to work with it, rather than fight it. aim for keeping the average temp at SP, with a continuous but stable fuel flow. im going to guess it's impossible to keep a furnace temperature exact with the current game limitations on ignition.

in short the different values can be explained like this:
Kp -> how aggressive it is relative to error ("high" = aggressive, "low" = relaxed)
Ti -> how fast it should fight to close the remaining gap ("high" = slow, "Low" = fast)
Td -> how aggressive it should be to change ("Low" = aggressive, "high" = relaxed)
Soondead 22 Feb, 2021 @ 9:29am 
@Elmo I got it to work a little bit better by adjusting Kp to a lower value, but the furnace seems to need a certain amount (ratio?) of fuel before it will ignite, despite me repeatedly toggling Activate. This delay makes the PID step up all the way to 100 before something happens. To make matters worse, there's still a delay of 2-3 seconds from the temperature drops below SP until the PID reacts. (FilterTicks=1)

I have just shared the build in the workshop as "Mars Bar" if you care to have a look.
Elmo  [author] 22 Feb, 2021 @ 4:36am 
@Soondead Reverse mode (-1) would be correct. if it instantly jumps from 0% to 100% the Kp value is probably way to high. (i'm assuming you set the target temperature in kelvin?)

the best way to debug the controller is to set Ti and Td to zero, so they don't affect anything. then you only have the proportinal gain left to deal with. with only proportinal it's a rather simple equation.
u (output) = Kp * e (error)

- in case of temperature > SP the equation shuld output a negative value (capped by minOutput)
- in the case of SP > temp it shuld output a small value when they are close, and proportinal bigger the further those values get from each other. idealy it would find a balance somewhere below SP.

i wouldn't mind to look at the setup if you'd share the world. i havn't attempted to setup an advanced furnace with PID in a while.
Soondead 22 Feb, 2021 @ 3:45am 
Tried to use this for controlling an Advanced Furnace by setting the target temperature on a Logic Memory chip and then writing the actuator value to SettingInput. Tried setting RegulatorMode to -1 since high temperature means shut off fuel input. The result? It either gets stuck at 0% no matter how low the temperature drops, or it just opens the throttle 100% and keeps it open no matter how high the temperature goes. Any tips?
dierickx3 20 Feb, 2021 @ 5:15pm 
Very impressive! Genius!:steamthumbsup:
jay.jahn 14 Feb, 2021 @ 5:03am 
Thanks alot
Elmo  [author] 13 Feb, 2021 @ 5:15pm 
@jay.jahn Uploaded new updated example worlds, see the links
jay.jahn 13 Feb, 2021 @ 8:44am 
Can you upload your saved game please? That way i could see how wired your base. Thanks for all your help.