Advertisement
OreSeur-

Test Program

Feb 3rd, 2021 (edited)
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. --This code is designed to leave the reactor on all the times and maintain
  2. --power levels by adjusting the control rod insertion
  3.  
  4. --return a integar ignoring any remainder
  5. function DIV(a,b)
  6.     return (a - (a % b)) / b
  7. end
  8.  
  9. --the total size of the buffer
  10. local BUFFER_MAX = 10000000
  11. --the amount of power we want to maintain in the buffer
  12. local TARGET_AMOUNT = 5000000
  13. --the default insertion of control rods
  14. local controlLevel = 50
  15.  
  16. --connect to reactor
  17. local reactor = peripheral.wrap("back")
  18.  
  19. --confirm connection
  20. if(not reactor.getConnected) then
  21.     print("Not connected to Reactor")
  22. end
  23.  
  24. --turn the reactor on
  25. if(not reactor.getActive()) then
  26.     reactor.setActive(true)
  27.     print("Starting Reactor")
  28. end
  29.  
  30. --move control rod to defaul level
  31. reactor.setAllControlRodLevels(controlLevel)
  32.  
  33. while(true) do
  34.     --control the rods to maintain a specified buffer
  35.    
  36.     --find the current amount of energy in the buffer
  37.     local currentEnergy = reactor.getEnergyStored()
  38.     --set the new control level to the difference between the
  39.     --amount of evergy and wanted energy
  40.     local number = (currentEnergy - TARGET_AMOUNT)
  41.     print("Number: ", number)
  42.     local controlNumber = DIV(math.abs(number), 100000)
  43.     print("Control Number: ", contorolNumber)
  44.    
  45.     if (number > 0) then
  46.         controlLevel = controlLevel + controlNumber
  47.     elseif(number < 0 ) then
  48.         controlLevel = controlLevel - controlNumber
  49.     end
  50.    
  51.     if (controlLevel < 0) then
  52.         controlLevel = 0
  53.     elseif (controlLevel > 100) then
  54.         controlLevel = 100
  55.     end
  56.     reactor.setAllControlRodLevels(controlLevel)
  57.     print("Control Level: %d", controlLevel)
  58.    
  59.     --Check reactor
  60.     if(reactor.getFuelAmount() == 0)then
  61.         redstone.setOutput("right", true)
  62.         print("Control Rods complety Open")
  63.     end
  64.    
  65.     sleep(3)
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement