Advertisement
SythsGod

Turbine/Reactor Control

Mar 7th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- local t  = peripheral.wrap("BigReactors-Turbine_1")
  2. -- local ta = peripheral.wrap("BigReactors-Turbine_2")
  3. -- local tb = peripheral.wrap("BigReactors-Turbine_3")
  4. -- local e  = peripheral.find("tile_blockcapacitorbank_name")
  5. local r  = peripheral.find("BigReactors-Reactor")
  6. -- local cap_num = 36
  7. local max = 10000000 -- 10.000.000
  8. local min = 1000000  --  1.000.000
  9. local eFull = false
  10.  
  11. function getSpeed(turbine, nr)
  12.   local speed = turbine.getRotorSpeed()
  13.  
  14.   if speed > 1805 and turbine.getActive() then
  15.     print("Too fast, turning turbine " .. nr .. " off")
  16.     turbine.setActive(false)
  17.   elseif speed < 1795 and not turbine.getActive() then
  18.     print("Too slow, turning turbine " .. nr .. " on")
  19.     turbine.setActive(true)
  20.   end
  21. end
  22.  
  23. function rOff()
  24.   r.setActive(false)
  25. end
  26.  
  27. function rOn()
  28.   r.setActive(true)
  29. end
  30.  
  31. while true do
  32.   -- getSpeed(t, 1)
  33.   -- getSpeed(ta, 2)
  34.   -- getSpeed(tb, 3)
  35.  
  36.   local heat = r.getFuelTemperature()
  37.  
  38.   if heat >= 1800 and r.getActive() then
  39.     print("Too hot, turning off")
  40.     rOff()
  41.   elseif heat <= 1600 and not r.getActive() and not eFull then
  42.     print("Too cold, turning on")
  43.     rOn()
  44.   end
  45.  
  46.   local energy = r.getEnergyStored()
  47.  
  48.   print(energy)
  49.  
  50.   -- and not t.getInductorEngaged() and speed > 1750
  51.   if energy < min then
  52.     eFull = false
  53.     print("Low on energy, turning on reactor!")
  54.     -- t.setInductorEngaged(true)
  55.     -- ta.setInductorEngaged(true)
  56.     rOn()
  57.   -- and t.getInductorEngaged()
  58.   elseif energy >= max then
  59.     eFull = true
  60.     print("Full, turning off reactor!")
  61.     -- t.setInductorEngaged(false)
  62.     -- ta.setInductorEngaged(false)
  63.     rOff()
  64.   end  
  65.  
  66.   sleep(1)
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement