Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.01 KB | None | 0 0
  1. -- EterniaLogic (DreadEnd - IGN)
  2. -- Draconic Reactor Control Script
  3. -- http://imgur.com/a/BPPKN
  4.  
  5. -----------
  6. -- The Field input value should be 30% of the power provied
  7. -- Capacitors are used to help guage when the power storage is full
  8. -- The inflow flux gate can also be modem networked together with the computer
  9. --
  10. -----------
  11.  
  12. -- ReS - Reactor Stabilizer
  13. -- "+" - Cryo-stabilized fluxduct
  14. -- CPU - Computer
  15. -- FxG - Flux Gate
  16. -- ___ - Air
  17. -- CAP - Basic Capacitor (The smaller the total value, the better)
  18.  
  19. -- ==Level 1==
  20. -- ReS +
  21. -- CPU FxG
  22. -- ___ +
  23.  
  24. -- ==Level 2==
  25. -- ___ CAP
  26. -- CAP CAP
  27. -- ___ CAP
  28.  
  29. wantedField=50000000 -- Force the field value to this approximate value
  30.  
  31. FluxMODEMVALUE = 0
  32. ValueChange = 10000 -- Change on the Flux Gate over time (Not exact, temperature and saturation divide this)
  33. MinEnergySat = 1000000 -- Minimum energy saturation level
  34. WantedRFt = 1200000
  35. totalFuel = 10368 -- Fully upgraded reactor
  36.  
  37. CapacitorNum = 5 -- 5 Capacitors on top of computer
  38. CapacitorVal = 1000000 -- Power holding capacity of the capacitors
  39.  
  40.  
  41. FIRavg = {} -- last FIR to go [Flux Input Rate]
  42. FIRLen = 20 -- length of averages
  43. FIRi = 0 -- location to do running average
  44. FIRVal = 200000 -- initial value for FIR
  45. FIRChg = false -- has an up-down happened?
  46. FIRLow = 0
  47. FIRHigh = 0
  48. FIRLastDelta = 999999
  49.  
  50. for i=0, FIRLen-1 do
  51. FIRavg[i] = FIRVal
  52. end
  53.  
  54. mon = peripheral.find("monitor")
  55. if(mon ~= nil) then
  56. term.redirect(mon)
  57. end
  58. -----------
  59. function init()
  60. inflowFluxGate = peripheral.find("flux_gate")
  61. if inflowFluxGate ~= nil then
  62. inflowFluxGate.open(1)
  63. print("|# Input fluxgate: "..inflowFluxGate.callRemote("flux_gate_"..FluxMODEMVALUE,"getSignalLowFlow"))
  64. end
  65.  
  66.  
  67.  
  68. maxFieldCharge = totalFuel * 96.45061728395062 * 100
  69. maxEnergySaturation = (totalFuel * 96.45061728395062 * 1000)
  70.  
  71. -- Capacitor on top
  72. CapacitorMax = CapacitorVal*CapacitorNum -- Power holding capacity of the capacitors
  73.  
  74.  
  75.  
  76. capacitor_1 = peripheral.wrap("top")
  77. tbl = peripheral.call("back","getReactorInfo")
  78. FluxGateStatus = peripheral.call("right", "getSignalLowFlow")
  79.  
  80. for k, v in pairs (tbl) do
  81. --print(k,v)
  82. if k == "temperature" then -- Weise bestimmte programmrelevante Parameter einzelnen Variablen zu
  83. temperatur = v
  84. end
  85. if k == "energySaturation" then
  86. energysat = v
  87. end
  88. if k == "fieldStrength" then
  89. feldst = v
  90. end
  91. if k == "generationRate" then
  92. RFpt = v
  93. end
  94. if k == "fuelConversion" then
  95. RestKraftstoff = v
  96. end
  97. if k == "fuelConversionRate" then
  98. Kraftstoffverbrauch = v
  99. end
  100. end
  101. energieladung = energysat * 0.0000001
  102. fieldstr = feldst * 0.000001
  103. kRFpt = RFpt / 1000
  104. fuel = RestKraftstoff / 10368
  105. FuelConv = fuel * 100
  106. --------------------------------------------------
  107. print("|# Reactor temperature: "..math.ceil(temperatur))
  108. print("|# Energy saturation %: "..math.ceil(energieladung))
  109. print("|# Field strength %: "..math.ceil(fieldstr))
  110. print("|# Refuel level %: "..math.ceil(FuelConv))
  111. --print("|# ConvesionRate: "..math.ceil(Kraftstoffverbrauch))
  112. print("|# Energyproduction: "..math.ceil(kRFpt).." kRF/t")
  113. -------------------------------------------------
  114. end
  115.  
  116. function doFIRavg()
  117. local val=0
  118. for i=0, FIRLen-1 do
  119. val = val+FIRavg[i]
  120. end
  121. return val/FIRLen
  122. end
  123.  
  124. function calcFieldDrain()
  125. if FIRi >= FIRLen then
  126. FIRi = 0
  127. else
  128. FIRi = FIRi+1
  129. end
  130.  
  131. FIRavg[FIRi]=feldst
  132. local avg = doFIRavg()
  133. --print(avg.." "..wantedField)
  134. local difference = math.abs(avg-wantedField)
  135.  
  136. --local valuedelta = math.pow(avg-wantedField, 2)/(300*avg)
  137.  
  138. local height = 40000
  139.  
  140. local Offset = 78540000
  141. local valuedelta = math.sin((avg-(wantedField+Offset))/(50000000))*height+height
  142. if(valuedelta < 0) then
  143. valuedelta = 1
  144. --print("Neg at: "..avg)
  145. end
  146.  
  147. --print("TTT: "..valuedelta)
  148.  
  149.  
  150. if (avg > wantedField) then
  151. if FIRVal-valuedelta < 10000 then
  152. FIRVal = 10000
  153. else
  154. FIRVal = FIRVal-valuedelta
  155. end
  156. if(FIRChg) then
  157. FIRChg = false
  158. FIRHigh = FIRVal
  159.  
  160. -- Predict middle
  161. --FIRVal = (FIRHigh+FIRLow)/2
  162. end
  163. else
  164. if (avg < wantedField) then
  165. if FIRVal+valuedelta > (900000-valuedelta) then
  166. FIRVal = 900000
  167. else
  168. FIRVal = FIRVal+valuedelta
  169. end
  170. end
  171. if(not FIRChg) then
  172. FIRChg = true
  173. FIRLow = FIRVal
  174.  
  175. -- Predict middle
  176. --FIRVal = (FIRHigh+FIRLow)/2
  177. end
  178.  
  179. end
  180.  
  181. --print("Low: "..FIRLow)
  182. --print("High: "..FIRHigh)
  183. --print("Delta: "..math.abs(FIRHigh-FIRLow))
  184.  
  185. fluxval = FIRVal
  186. print("|#== FluxInputRate: "..math.floor(fluxval).." kRF/t")
  187. end
  188.  
  189.  
  190. -- Set the shield input level
  191. function setLowLevel()
  192. if inflowFluxGate ~= nil then
  193. calcFieldDrain()
  194. inflowFluxGate.callRemote("flux_gate_"..FluxMODEMVALUE,"setSignalLowFlow",fluxval)
  195. end
  196. end
  197.  
  198.  
  199. function setLevel(level)
  200. print("|#== FluxGate set to: "..math.ceil(FluxGateStatus).." kRF/t")
  201. peripheral.call("right", "setSignalLowFlow", FluxGateStatus)
  202.  
  203. end
  204.  
  205.  
  206. function limitLevel(FluxStatus)
  207. -- Set the maximum value
  208. if FluxGateStatus >= (WantedRFt*0.9-FluxGateStatus*0.3) then
  209. FluxGateStatus = (WantedRFt*0.9-FluxGateStatus*0.3)
  210. end
  211. end
  212.  
  213.  
  214. -- Start the reactor
  215. function startReactor()
  216. peripheral.call("back", "chargeReactor")
  217. print("|#== Reactor charge !! ==#|")
  218. if feldst >= 50000000 then
  219. peripheral.call("back", "activateReactor")
  220. print("|#== Reactor activate ! ==#|")
  221. end
  222. end
  223.  
  224.  
  225. function testFieldStrength()
  226. if feldst <= 15000000 then
  227. peripheral.call("back", "stopReactor")
  228. print("|#== Reactor Emergency stop ! ==#|")
  229. print("|#== Field strength too low ! ==#|")
  230. else
  231. if feldst >= 20000000 then
  232. peripheral.call("back", "activateReactor")
  233. --print("|#== Reactor active ! ==#|")
  234. end
  235. end
  236. end
  237.  
  238.  
  239. function calcNewValueChange()
  240. local chg = ValueChange
  241. local saturationchg = (energieladung/100)-0.3
  242. local reactorTempx = 1-((temperatur-3000)/10000+0.2) -- reactor temperature accounting for +3000 heat
  243.  
  244. print("|# Temperature Factor: "..reactorTempx)
  245. print("|# Saturation Factor: "..saturationchg)
  246. chg = chg*math.min(saturationchg,reactorTempx) -- Account for saturation and Temperature
  247.  
  248. return chg
  249. end
  250.  
  251.  
  252. function testCapacitor()
  253. -- Slow down the reactor to 1/8 of the requested power level
  254. -- This is so that a slow-start is not required for later use
  255. if capacitor_1 ~= nil then
  256. local energyStored = capacitor_1.getEnergyStored()
  257. if energyStored >= CapacitorMax then
  258. FluxGateStatus = WantedRFt/8
  259. setLevel(FluxGateStatus)
  260. end
  261. end
  262. end
  263.  
  264.  
  265. -- Run this program!
  266. function doRun()
  267. if temperatur > 7777 then -- Temperatur check wenn mehr als 7777 Grad
  268. FluxGateStatus = 200000
  269. end
  270.  
  271.  
  272. -- Set the energy level to be produced
  273. if energysat > MinEnergySat then
  274. limitLevel(FluxGateStatus)
  275. FluxGateStatus = RFpt + calcNewValueChange() -- anpassen der Flux-Gate_Variablen an den neuen Wert
  276. setLevel(FluxGateStatus)
  277. end
  278.  
  279.  
  280.  
  281.  
  282. -- Energy Saturation settings
  283. --if energysat < MinEnergySat then
  284. -- if FluxGateStatus <= 10000 then -- Minimalwert abregelung auf 0
  285. -- FluxGateStatus = 10000
  286. -- end
  287. -- FluxGateStatus = FluxGateStatus - ValueChange -- anpassen der Flux-Gate_Variablen an den neuen Wert
  288. -- setLevel(FluxGateStatus)
  289. --end
  290.  
  291.  
  292.  
  293. -- Stop the reactor when 90% of the fuel is gone
  294. if FuelConv >= 90 then
  295. peripheral.call("back", "stopReactor")
  296.  
  297. print("|#== Reactor refuel stop ! ==#|")
  298. print("|#============#| S D R C |#============#|")
  299. sleep(300)
  300. end
  301.  
  302. if temperatur <= 2000 then -- Starttest zum aufladen des Reaktors
  303. startReactor()
  304. else
  305. testFieldStrength()
  306. end
  307.  
  308. setLowLevel(level)
  309. testCapacitor()
  310. end
  311.  
  312. while true do
  313. term.clear()
  314. term.setCursorPos(1,1)
  315. init()
  316. doRun()
  317. sleep(0.06)
  318. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement