Stationeers

Stationeers

52 ratings
PID Controller & Filter
3
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
198.251 KB
Feb 7, 2021 @ 4:46am
May 11, 2021 @ 6:49am
2 Change Notes ( view )

Subscribe to download
PID Controller & Filter

Description
General purpose PID controller with sensor filter

Pins

d0
Sensor
Device to read Process value from
d1
Actuator
(optional) Device to control
d2
SleepToggle
(optional) Device to toggle controller sleep
d3
SPDevice
(optional) Device to easily change setpoint

System variables
SetPoint: Desired target for the controller. Not used if you have set SPdevice.
Min/Max output: Upper and lower limits on the output of the controller.
FilterTicks: The number of ticks the controller should take an average of the sensor readings.
SPDeviceMultiplier: Simply a number that is multiplied with SPdevice readout if used.

Tuning
RegulatorMode: can be either 1 (direct) or -1 (reversed).
If your ProcessValue is higher than setpoint, should your actuator:
  • Increase: Direct mode (1)
  • Decrease: Reverse mode (-1)

In order to tune the controller, start with Ti and Td at zero. Find the highest Kp value that gives stable oscillation without reaching max or min, called Ku. Take not of the oscillation period (time between peeks) Tu. You can then calculate your variables based on desired behavior:
Control Type
Kp
Ti
Td
PI
0.45 * Ku
0.8 * Tu
0
classic PID
0.6 * Ku
0.5 * Tu
0.125 * Tu
no overshoot
0.2 * Ku
0.5 * Tu
0.33 * Tu

See https://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method
and don't be afraid to tinker with the values and see it's behavior change.

Example world:
Europa: https://steamcommunity.com/sharedfiles/filedetails/?id=2394680235
Mars: https://steamcommunity.com/sharedfiles/filedetails/?id=2394680007
Moon: https://steamcommunity.com/sharedfiles/filedetails/?id=2394679313

AC example world:
https://steamcommunity.com/sharedfiles/filedetails/?id=2488371541
19 Comments
micle546 Nov 26, 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 Oct 6, 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 Sep 26, 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] Sep 3, 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 Sep 3, 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 Aug 16, 2023 @ 5:00am 
You are a legend
Xinax Jan 6, 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] Jul 22, 2022 @ 3:56am 
stiefelriemenWill Jul 21, 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 Feb 22, 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 :-)