MyrddinE

ComputerCraft BigReactor Turbine automatic rate control

May 30th, 2014
1,700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. -- Title: ComputerCraft BigReactor Turbine automatic rate control software
  2. -- Author: MyrddinE
  3. --
  4. -- Purpose: Control the allowed steam input to one or more turbines, based on the energy
  5. -- remaining in one or more cells. Uses wired modems, one per turbine and one per cell.
  6. -- You can have as many cells (of different types) and as many turbines as you want. The
  7. -- cells must respond to 'getMaxEnergyStored' and 'getEnergyStored'; only tested with
  8. -- ThermalExpansion cells, but should work with other cells that support those commands.
  9. --
  10. -- For the feedback process to respond in time, you should have about 100M RF storage
  11. -- per turbine. Turbines take a long time to spin down and up, and a large buffer means
  12. -- less wasted overpower, and no power underruns. Also, since each turbine generates up
  13. -- to 30k RF/tick, and each cell (TE Resonant 50M) can only pass through 10K RF/tick per
  14. -- face, you will be throughput limited unless you go through some complicated
  15. -- shenanigans, so plan accordingly with extra cells. If you have lots of cells, a
  16. -- 2-wide 'wall' of cells passes through 10k per cell, with room on the sides for the
  17. -- modems. If you have lots of space and want to scrimp on the cells, you can jam in
  18. -- four conduits (2 in, 2 out) and a modem around each cell to halve the cells needed.
  19. --
  20. -- Wiring Diagram
  21. --
  22. --       Overflow Storage (Optional)         More Power Storage (Optional)
  23. --             ^             |                       ^            |
  24. --             |             v                       |            v
  25. -- Turbines -----------------------> Buffer Bank ------------------------> Load
  26. --     T                                  T
  27. --     |            Computer              |
  28. --     |                T                 |
  29. --     +----------------+-----------------+
  30.  
  31.  
  32. -- Change this to be the side your wired modem is attached to the computer.
  33. modem = peripheral.wrap('bottom')
  34.  
  35. -- Get the list of cells and turbines. Run once at startup. If you add or remove devices
  36. -- terminate and restart the program.
  37. name = modem.getNamesRemote()
  38. turbine = {}
  39. cell = {}
  40. tCount = 0
  41. cCount = 0
  42. for i = 1, #name, 1 do
  43.   p = peripheral.wrap(name[i])
  44.  
  45.   if name[i]:match 'BigReactor' then
  46.     tCount = tCount + 1
  47.     turbine[tCount] = p
  48.   else
  49.     cCount = cCount + 1
  50.     cell[cCount] = p
  51.   end
  52. end
  53. print(tCount," turbines, ",cCount," cells connected.")
  54.  
  55. -- Loop forever
  56. while true do
  57.   -- Add up the total (and max) power stored in the attached cells.
  58.   energy = 0
  59.   max = 0
  60.   for i = 1, cCount, 1 do
  61.     max = max + cell[i].getMaxEnergyStored('')
  62.     energy = energy + cell[i].getEnergyStored('')
  63.   end
  64.  
  65.   -- The emptier the cells, the faster it will set the turbines to go, up to the max of
  66.   -- 2000mB/tick.
  67.   rate = math.floor(2000*(1-energy/max))
  68.  
  69.   -- Set all attached turbines to the given rate. Total up how much RF they are
  70.   -- producing at the same time, for display.
  71.   RF = 0
  72.   for i = 1, tCount, 1 do
  73.     turbine[i].setFluidFlowRateMax(rate)
  74.     RF = RF + turbine[i].getEnergyProducedLastTick()
  75.   end
  76.  
  77.   -- Print some useful stats to the console.
  78.   RF = math.floor(RF)
  79.   batt = math.floor(100*energy/max).."%"
  80.   print("Buffer at ",batt," - ",rate,"mB/tick - Making ",RF,"RF/tick")
  81.  
  82.   -- Sleep for 5 seconds.
  83.   sleep(10)
  84. end
Advertisement
Add Comment
Please, Sign In to add comment