Dimencia

Untitled

Jan 5th, 2023
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 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 = 500
  42. local steamScalar = 1/10
  43. -- We might need to adjust this up for when we need steam
  44. targetTemp = targetTemp - ((turbine.fluidTank().input().amount()-(1800-turbine.rotor().RPM())*50) * steamScalar)
  45. print("Target temp: " .. targetTemp)
  46.  
  47. local controlMult = 0.0001
  48.  
  49.  
  50. -- Now try to keep the turbine at 1800 rpm
  51. if turbine.rotor().RPM() > 1800 and turbine.active() then
  52. turbine.setActive(false)
  53. elseif turbine.rotor().RPM() < 1800 and not turbine.active() then
  54. turbine.setActive(true)
  55. end
  56.  
  57. -- And turn on the coils when we need power
  58. if turbine.battery().stored() == turbine.battery().capacity() and turbine.coilEngaged() then
  59. turbine.setCoilEngaged(false)
  60. elseif turbine.battery().stored() < turbine.battery().capacity() and not turbine.coilEngaged() then
  61. turbine.setCoilEngaged(true)
  62. end
  63.  
  64. if turbine.coilEngaged() then
  65. targetTemp = targetTemp*2 -- And go ham if it's on
  66. end
  67.  
  68. local controlRodChange = (reactor.casingTemperature()-targetTemp) * controlMult
  69. reactor.setAllControlRodLevels(reactor.getControlRod(0).level()+controlRodChange)
  70. print("Control rod change: " .. controlRodChange)
  71.  
  72. print("RFT: " .. turbine.battery().producedLastTick())
  73.  
  74. sleep(0.01)
  75. end
Advertisement
Add Comment
Please, Sign In to add comment