Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 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('back')
  34. mon=peripheral.wrap('top')
  35.  
  36. -- Get the list of cells and turbines. Run once at startup. If you add or remove devices
  37. -- terminate and restart the program.
  38. name = modem.getNamesRemote()
  39. turbine = {}
  40. cell = {}
  41. tCount = 0
  42. cCount = 0
  43. for i = 1, #name, 1 do
  44. p = peripheral.wrap(name[i])
  45.  
  46. if name[i]:match 'BigReactor' then
  47. tCount = tCount + 1
  48. turbine[tCount] = p
  49. else
  50. cCount = cCount + 1
  51. cell[cCount] = p
  52. end
  53. end
  54. mon.clear()
  55. mon.setCursorPos(1,1)
  56. mon.write(tCount," turbines, ",cCount," cells connected.")
  57.  
  58. -- Loop forever
  59. while true do
  60. -- Add up the total (and max) power stored in the attached cells.
  61. energy = 0
  62. max = 0
  63. for i = 1, cCount, 1 do
  64. max = max + cell[i].getMaxEnergyStored('')
  65. energy = energy + cell[i].getEnergyStored('')
  66. end
  67.  
  68. -- The emptier the cells, the faster it will set the turbines to go, up to the max of
  69. -- 2000mB/tick.
  70. rate = math.floor(2000*(1-energy/max))
  71.  
  72. -- Set all attached turbines to the given rate. Total up how much RF they are
  73. -- producing at the same time, for display.
  74. RF = 0
  75. for i = 1, tCount, 1 do
  76. turbine[i].setFluidFlowRateMax(rate)
  77. RF = RF + turbine[i].getEnergyProducedLastTick()
  78. end
  79.  
  80. -- Print some useful stats to the console.
  81. RF = math.floor(RF)
  82. batt = math.floor(100*energy/max).."%"
  83. mon.setCursorPos(1,2)
  84. mon.write("Buffer at ",batt," - ",rate,"mB/tick - Making ",RF,"RF/tick")
  85.  
  86. -- Sleep for 5 seconds.
  87. sleep(10)
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement