Ubidibity

DraconicReactorMonitor-1.1

Jun 20th, 2021 (edited)
339
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- modified to work with draconic rf storage (trying to determine actual 'gain' from reactor)
  2.  
  3. --Rev. 20210620 wtp
  4. --Added better colorization for temp and field strength warnings in the 'between' zone
  5. --Also added an emergency stop if either containment or saturation drop below 40% (I hope)
  6.  
  7. --Rev. 20210619 wtp
  8. --As my previous paste could be my 'first', this one will become my 1.1 release.
  9.  
  10. --Developed for use on 1.7 Infinity with Draconic Evolution 1.7.10-1.0.2h (Mym.li normal mode)
  11.  
  12. --I've got the main parts I wanted, the setup and considerations are detailed below:
  13.  
  14. --Advanced computer with a Draconic Reactor stabilizer on it's right side.
  15. --Red cage lamp on top (to come on when either containment field or saturation <51%)
  16. -- Note: neither light will light nor flash at 51%, if the last iteration left the red light illuminated it will stay
  17. --       illuminated until either it drops below 51% or rises up or beyond 52% (I call this the 'transition period')
  18. --Green cage lamb on back (to come on with both containment field and saturation >51%)
  19. --A wired modem is on the left side with a cable running up to the Tier-7 Draconic Energy Core Energy Pylon
  20. --advanced monitors 5 wide, three tall stacked below the computer facing the stabilizer I have the flux gate on.
  21. --The Draconic Reactor is connected directly with cryotheum ducts from the stabilizer to the T7 energy 'input'
  22. --then the T7 energy output goes to the reactor injector.
  23. -- The reactor injector flux gate has a redstone signal high at 262,000RF/t and connects back to the injector in
  24. -- reverse containment field mode (three repeaters and a piece of redstone) using 139,700K for my mostly used reactor
  25. -- The stabilizer flux gate to the T7 energy core is currently set at 2,010,000 though of course that took weeks and starts
  26. -- out much lower.
  27. -- Since the T7 fills up and the reactor essentially shuts down, I have a third flux gate 'drain' between the T7
  28. -- energy core and the injector flux gate which is also connected to a modem and wired back to the computer.
  29. -- The idea is to allow both my use and public use to draw on the reactor up to the amount the reactor creates,
  30. -- but to limit the flux gate if that drain gets too high as I've found connecting a new t7 to any of those tessearcts
  31. -- on that flux gate would run out the buffer for the reactor and it would ultimately fail (I lost at least one core this way)
  32.  
  33. -- Its worth acknowledging that the mym.li servers disable the explosion, so while losing the chaos shards hurts,
  34. -- at least you don't lose the rest of the infrastructure.
  35.  
  36. -- Changes for the 19th.
  37. -- Mostly cosmetic, I'm going to start by converting my print redirect output to specific monitor coordinates
  38. -- also better color management, so if the saturation is gaining during the transition period I want that green
  39. -- but the draining warning should be yellow
  40. -- the fluxgate flow override when it kicks in should be red
  41. -- the normal flux gate flow set to the generation power-field drain should be green
  42. -- I may also suppress the maxFieldStrength and maxEnergySaturation as it's static and you sort of get that from the
  43. -- current values and their respective percentages
  44. -- I'm also going to shuffle around and try to put the variable definitions together in a block rather than
  45. -- having code intermixed in the variable initialization block
  46.  
  47. local storage = peripheral.find("draconic_rf_storage")
  48. local monitor = peripheral.wrap("bottom")
  49. local    core = peripheral.wrap("right")
  50. local fluxgate = peripheral.find("flux_gate")
  51. local powerstate = 0
  52. local x=0
  53. local y=0
  54. local x1=0
  55. local msg="empty"
  56. local fieldStrengthPercent=0
  57. local lastFieldStrengthPercent
  58. local energySaturationPercent=0
  59. local lastEnergySaturationPercent=0 -- last energy saturation
  60. local ecrft=0 -- energy core rf per tick
  61.  
  62. term.redirect(monitor)
  63. term.setBackgroundColor(colors.gray)
  64. fluxgate.setOverrideEnabled(true)  -- required for direct computer control of flux gate flow rate
  65.  
  66. while true do
  67.  
  68. local stab = core.getReactorInfo()
  69.  
  70. y=x
  71. x=storage.getEnergyStored()
  72. powerstate=stab.status
  73.  
  74. monitor.clear()
  75.  
  76. monitor.setTextColor(colors.white)
  77.  
  78. monitor.setCursorPos(15,1)
  79. print("status:")
  80. if powerstate=="online" then
  81.   monitor.setTextColor(colors.green)
  82. else
  83.   monitor.setTextColor(colors.red)
  84. end
  85. monitor.setCursorPos(23,1)
  86. print(powerstate)
  87.  
  88. monitor.setTextColor(colors.white)
  89. monitor.setCursorPos(7,2)
  90. print("generationRate: "..stab.generationRate.." RF/t")
  91.  
  92. monitor.setCursorPos(10,3)
  93. x1=stab.temperature
  94. monitor.setTextColor(colors.green)
  95. if (x1>7000) then
  96.   monitor.setTextColor(colors.orange)
  97. end
  98. if (x1>8000) then
  99.   monitor.setTextColor(colors.purple)
  100. end
  101. print("temperature: "..x1)
  102. monitor.setTextColor(colors.white)
  103.  
  104. monitor.setCursorPos(8,4)
  105. print("fieldStrength: "..stab.fieldStrength)
  106.  
  107. -- these two max values are static and don't really tell us anything
  108. --monitor.setCursorPos(5,5)
  109. --print("maxFieldStrength: "..stab.maxFieldStrength)
  110.  
  111. monitor.setCursorPos(7,6)
  112. print("fieldDrainRate: "..stab.fieldDrainRate)
  113.  
  114. monitor.setCursorPos(1,7)
  115. print("Fuel Conversion Rate: "..stab.fuelConversionRate.." nb/t")
  116.  
  117. --monitor.setCursorPos(4,8)
  118. --print("maxFuelConversion: "..stab.maxFuelConversion)
  119.  
  120. local fuelConversionPercent=stab.fuelConversion*100/stab.maxFuelConversion
  121. monitor.setCursorPos(7,9)
  122. print("fuelConversion: "..stab.fuelConversion.."("..math.floor(fuelConversionPercent).."%)")
  123.  
  124. lastEnergySaturationPercent=energySaturationPercent
  125. energySaturationPercent=stab.energySaturation*100/stab.maxEnergySaturation
  126. monitor.setCursorPos(5,10)
  127. print("energySaturation: "..stab.energySaturation.."("..math.floor(energySaturationPercent).."%) "..energySaturationPercent-lastEnergySaturationPercent)
  128.  
  129. --monitor.setCursorPos(2,11)
  130. --print("maxEnergySaturation: "..stab.maxEnergySaturation)
  131.  
  132. monitor.setCursorPos(8,12)
  133. print("fluxgate flow: "..fluxgate.getFlow())
  134.  
  135. lastFieldStrengthPercent=fieldStrengthPercent
  136. fieldStrengthPercent=stab.fieldStrength*100/stab.maxFieldStrength
  137. monitor.setCursorPos(2,13)
  138. print("Cont. fieldStrength: "..math.floor(fieldStrengthPercent).."%".."("..fieldStrengthPercent-lastFieldStrengthPercent..")")
  139.  
  140. monitor.setCursorPos(2,15)
  141. print("Energy Core Storage: "..x)
  142. ecrft=((((x-y)/1000/1000)/2)/20) -- there are 20 ticks in a second so you /20 not multiple dufus
  143.  
  144. monitor.setCursorPos(5,16)
  145.  
  146. x1=ecrft
  147. if (x1>999999999) then
  148. -- leave x1 alone for millions
  149.   msg=" MRF/t"
  150. end
  151.  
  152. if (x1<10000000000) then
  153.   x1=x1*1000
  154.   msg=" KRF/t"
  155. end
  156.  
  157. if (x1<1000000) then
  158.   x1=x1*1000
  159.   msg=" RF/t"
  160. end
  161.  
  162. print("Energy Core RF/t: "..x1..msg..", "..(x*100/2140000000000).."%")
  163. redstone.setOutput("top",false)
  164.  
  165. if (fieldStrengthPercent<51 or energySaturationPercent<51) then
  166.   monitor.setCursorPos(1,14)
  167.   if (lastEnergySaturationPercent<energySaturationPercent) then
  168.     monitor.setTextColor(colors.green)
  169.     print("++++ Correcting")
  170.   elseif (lastEnergySaturationPercent>energySaturationPercent) then
  171.     monitor.setTextColor(colors.yellow)
  172.     print("!!!! Degrading")
  173.   end
  174.   redstone.setOutput("top", not redstone.getOutput("top"))
  175.   redstone.setOutput("back",false)
  176.   if (fieldStrengthPercent<45 or energySaturationPercent<45) then
  177.     redstone.setOutput("top",true)
  178.     core.stopReactor()
  179.     monitor.setCursorPos(20,14)
  180.     monitor.setTextColor(colors.red)
  181.     print("*** REACTOR SCRAM ***")
  182.     term.setBackgroundColor(colors.yellow)
  183.   end
  184. end
  185.  
  186. monitor.setTextColor(colors.white)
  187.  
  188. if (fieldStrengthPercent>51 and energySaturationPercent>51) then
  189.   redstone.setOutput("top",false)
  190.   redstone.setOutput("back",true) -- redstone.getOutput("top"))
  191. end
  192. -- Energy dump, if core>25% then during testing I have this set much higher to give me better reaction time
  193. -- and if net gain >100MRf/t
  194. -- (and less than say 1000 to prevent initialization issues)
  195. -- set fluxgate low flow to core net gain
  196.  
  197.   if (x*100/2141200000000)>70 then  -- per above now I'm only setting the output when over 70%
  198.  
  199. -- seems to work more predictably just allowing the generation rate, using the change kept allow massive drops
  200. -- and recover time was poor (even with the 70% safety margin) an empty T7 is really a RF vacuum.
  201. --    fluxgate.setFlowOverride(ecrft*4000)
  202.     fluxgate.setFlowOverride(stab.generationRate-(stab.fieldDrainRate*2))
  203. --  end
  204.   else
  205.     -- Want to let a little through since I rely on this energy to keep my AE2 system operational
  206.     fluxgate.setFlowOverride(500000)
  207.   end
  208.  
  209. sleep(2)
  210. end
RAW Paste Data