Dimencia

Untitled

Jan 5th, 2023
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. -- Super basic reactor and turbine control script
  2.  
  3. turbine = peripheral.wrap("BiggerReactors_Turbine_0")
  4. reactor = peripheral.wrap("BiggerReactors_Reactor_0")
  5.  
  6. -- Basically we just want to PID power to 0 by way of control rod insertion
  7. -- First, let's see what we've got...
  8. -- Reactor:
  9. -- ambientTemperature
  10. -- connected
  11. -- active
  12. -- setAllControlRodLevels
  13. -- battery
  14. -- fuelTemperature
  15. -- controlRodCount
  16. -- setActive
  17. -- fuelTank
  18. -- coolantTank
  19. -- apiVersion
  20. -- getControlRod
  21. -- stackTemperature
  22. -- casingTemperature
  23.  
  24. -- Actually, I might want to PID the casingTemperature to a certain level instead
  25. -- Just below steam generation so I can easily add more
  26. -- That should be 373.15k
  27.  
  28. -- Turbine:
  29. -- connected
  30. -- rotor
  31. -- battery
  32. -- fluidTank
  33. -- setActive
  34. -- setCoilEngaged
  35. -- apiVersion
  36. -- active
  37. -- coilEngaged
  38.  
  39. reactor.setActive(true)
  40. while(true) do
  41. local targetTemp = 373.15
  42. local steamScalar = 1/100
  43. -- We might need to adjust this up for when we need steam
  44. targetTemp = targetTemp - (turbine.fluidTank().input().amount() * steamScalar)
  45. print("Target temp: " .. targetTemp)
  46.  
  47. local controlMult = 0.1
  48. local controlRodChange = (reactor.casingTemperature()-targetTemp) * controlMult
  49. reactor.setAllControlRodLevels(reactor.getControlRod(0).level+controlRodChange)
  50. print("Control rod change: " .. controlRodChange)
  51.  
  52. -- Now try to keep the turbine at 1800 rpm
  53. if turbine.rotor().RPM() > 1800 and turbine.active() then
  54. turbine.setActive(false)
  55. elseif turbine.rotor().RPM() < 1800 and not turbine.active() then
  56. turbine.setActive(true)
  57. end
  58.  
  59. -- And turn on the coils when we need power
  60. if turbine.battery().stored() > 0 and turbine.coilEngaged() then
  61. turbine.setCoilEngaged(false)
  62. elseif turbine.battery().stored() == 0 and not turbine.coilEngaged() then
  63. turbine.setCoilEngaged(true)
  64. end
  65.  
  66. coroutine.yield()
  67. end
Advertisement
Add Comment
Please, Sign In to add comment