ulvis.paste.net

Paste Search Dynamic
[LUA]Output Draconic Reactor
  1. ----------------------------------------------------------------------------------
  2. ------------------------- RAGNAMOD EP 45/46 - BY J3PH ----------------------------
  3. --------------------- CONTROLE DRACONIC REACTOR - OUTPUT -------------------------
  4. ---------------------- https://www.youtube.com/c/j3phmc --------------------------
  5. ----------------------------------------------------------------------------------
  6.  
  7. local component = require("component")
  8. local event = require("event")
  9. local term = require("term")
  10. local gpu = component.gpu
  11. local event = require("event")
  12. local w, h = gpu.getResolution()
  13.  
  14. reactor = component.draconic_reactor
  15. flux_out = component.flux_gate
  16.  
  17. desired_temp = 8000
  18.  
  19.  -- tweakable pid gains
  20.  
  21. outflow_P_gain = 500
  22. outflow_I_gain = 0.5
  23. outflow_II_gain = 0.0000003
  24. outflow_D_gain = 60000
  25.  
  26.  -- initialize main loop
  27.  
  28. outflow_I_sum = 0
  29. outflow_II_sum = 0
  30. outflow_D_last = 0
  31. outflow = flux_out.getSignalHighFlow()
  32.  
  33. local function bar_v(bar_x,bar_y,bar_h,pos,ep,col,titre,brut)       -- barre vertical syntax: bar_v(<pos colone>,<pos ligne>,<longueur>,<info>,<epaisseur de barre>,<couleur>,<titre>,<valeur brut>)
  34.     local m = (bar_h/100)
  35.     local v,d = math.floor(pos*m),bar_w
  36.     local f = (bar_h-v)
  37.    
  38.     gpu.setBackground(0x101010) -- couleur font de barre
  39.     gpu.fill(bar_x,bar_y,ep,f," ")  -- barre progressive
  40.    
  41.     gpu.setBackground(col)  -- couleur barre
  42.     gpu.fill(bar_x,(bar_y+f),ep,(bar_h-f)," ")
  43.    
  44.     gpu.setBackground(0x222222)
  45.     gpu.setForeground(0xffffff)
  46.     gpu.set(bar_x,(bar_y+bar_h+1),titre.." :")
  47.     gpu.set(bar_x,(bar_y+bar_h+2),""..string.format(" %5d",brut))
  48. end
  49.  
  50. local function scroll_bar_v(bar_x,bar_y,bar_h,pos,ep,col,titre,brut)        -- barre vertical syntax: scroll_bar_v(<pos colone>,<pos ligne>,<longueur>,<info>,<epaisseur de barre>,<couleur>,<titre>,<valeur brut>)
  51.     local m = (bar_h/100)
  52.     local v,d = math.floor(pos*m),bar_w
  53.     local f = (bar_h-v)
  54.    
  55.     gpu.setBackground(0x101010) -- couleur font de barre
  56.     gpu.fill(bar_x,bar_y,ep,f," ")  -- barre progressive
  57.    
  58.     gpu.setBackground(col)  -- couleur barre
  59.     gpu.fill(bar_x,(bar_y+f),ep,(bar_h-f)," ")
  60.    
  61.     gpu.setBackground(0x222222)
  62.     gpu.setForeground(0xffffff)
  63.     gpu.set(bar_x,(bar_y+bar_h+3),titre.." :")
  64.     gpu.set(bar_x,(bar_y+bar_h+4),""..brut)
  65. end
  66.  
  67. local function calcul()
  68.     outflow = 0
  69.           -- adjust outflow rate based on core temperature
  70.  
  71.       temp_error = ideal_temp - info.temperature
  72.       proportional_temp_error = temp_error * outflow_P_gain
  73.      
  74.       outflow_I_sum = outflow_I_sum + temp_error
  75.      
  76.       integral_temp_error = outflow_I_sum * outflow_I_gain
  77.      
  78.       if math.abs(temp_error) < 100 then
  79.         outflow_II_sum = outflow_II_sum + integral_temp_error
  80.       else
  81.         outflow_II_sum = 0
  82.       end
  83.       second_integral_temp_error = outflow_II_sum * outflow_II_gain
  84.       derivative_temp_error = (temp_error - outflow_D_last) * outflow_D_gain
  85.      
  86.       outflow_D_last = temp_error
  87.      
  88.       outflow_correction = proportional_temp_error + integral_temp_error + second_integral_temp_error + derivative_temp_error
  89.      
  90.       if outflow_correction < 0 then
  91.         outflow_I_sum = outflow_I_sum - temp_error
  92.       end
  93.      
  94.       outflow = outflow_correction
  95.       outflow = math.floor(outflow)
  96.       flux_out.setSignalHighFlow(outflow)
  97. end
  98.  
  99. local function desc()
  100.     gpu.setBackground(0x222222)
  101.     --gpu.setForeground(0x000000)
  102.     gpu.fill(1,1,w,h," ")
  103. end
  104.  
  105. local function print_temp()
  106.     local bar_color = 0x009900
  107.     if info.temperature >= 8000 and info.temperature <= desired_temp then
  108.         bar_color = 0xfe9310
  109.     elseif info.temperature > desired_temp then
  110.         bar_color = 0xAA0000
  111.     elseif info.temperature < 8000 then
  112.         bar_color = 0x009900
  113.     end    
  114.     bar_v(10,5,40,((info.temperature*100)/10000),10,bar_color,"Temp",info.temperature)
  115. end
  116.  
  117. local function print_shield()
  118.     local bar_color = 0x0002e8
  119.     local valeur_s = ((info.fieldStrength*100)/info.maxFieldStrength)      
  120.     if valeur_s <= 5 then
  121.         valeur_s = ((info.fieldStrength*100)/info.maxFieldStrength) * 20
  122.         bar_color = 0x009900
  123.     end    
  124.     bar_v(25,5,40,valeur_s,5,bar_color,"Shield",info.fieldStrength)
  125. end
  126.  
  127. local function valeur_temp()
  128.     local index = desired_temp / 100
  129.     local bar_color = 0x023f63
  130.     if desired_temp < 8000 then
  131.         bar_color = 0x023f63
  132.     elseif desired_temp >= 8000 then
  133.         bar_color = 0xfe9310
  134.     end
  135.     scroll_bar_v(40,7,36,index,5,bar_color,"Temp max",desired_temp)
  136.     gpu.setBackground(0x023f63)
  137.     gpu.setForeground(0xffffff)
  138.     gpu.set(40,5,"+ |++")
  139.     gpu.set(40,44,"- |--")
  140. end
  141.  
  142. local function tactil(_,_,x,y)
  143.     if x >= 40 and x <= 41 and y == 5 and desired_temp < 10000 then         -- Reglage 10 a 10 Temps max de sécurité
  144.             desired_temp = desired_temp + 10      
  145.     elseif x >= 40 and x <= 41 and y == 44 and desired_temp > 2000 then    
  146.             desired_temp = desired_temp - 10
  147.     end
  148.    
  149.     if x >= 43 and x <= 44 and y == 5 and desired_temp <= 9900 then         -- Reglage 100 a 100 Temps max de sécurité
  150.             desired_temp = desired_temp + 100  
  151.     elseif x >= 43 and x <= 44 and y == 44 and desired_temp >= 2100 then
  152.             desired_temp = desired_temp - 100
  153.     end
  154. end
  155.  
  156. term.clear()
  157. desc()
  158.  
  159. local function print_info(c,l)
  160.     gpu.setBackground(0x222222)
  161.     gpu.setForeground(0xffffff)
  162.       gpu.set(c,l,"Status:              " .. info.status .. "   ")
  163.       gpu.set(c,l+2,"Force du bouclier:   " .. ((info.fieldStrength / info.maxFieldStrength) * 100) .. " %    ")
  164.       gpu.set(c,l+4,"Saturation:          " .. ((info.energySaturation / info.maxEnergySaturation) * 100) .. " %     ")
  165.       gpu.set(c,l+6,"Fuel Concentration:  " .. ((1 - info.fuelConversion / info.maxFuelConversion) * 100) .. " %     ")
  166.       gpu.set(c,l+8,"Temperature:         " .. info.temperature .. " °C     ")
  167.       gpu.set(c,l+10,"Efficacité:          " .. info.fuelConversionRate .. " nb/t     ")
  168.       gpu.set(c,l+12,"Valeur du flow:      " .. outflow .. " RF/t      ")
  169.       gpu.set(c,l+14,"Temperature idéal:   " .. ideal_temp .. " °C  ")
  170. end
  171.  
  172. local function loop()
  173.     info = reactor.getReactorInfo()
  174.     local pct = (info.fieldStrength * 100) / info.maxFieldStrength
  175.    
  176.     if pct >= 10 then
  177.         ideal_temp = (desired_temp /2)
  178.     elseif pct < 10 then
  179.         ideal_temp = desired_temp
  180.     end
  181.    
  182.     if info.status == "running" then
  183.         calcul()
  184.         print_info(100,2)
  185.         print_temp()
  186.         print_shield()
  187.         valeur_temp()
  188.     end
  189. end
  190.  
  191. event.timer(0.05,loop,math.huge)
  192. event.listen("touch",tactil)
  193. event.pull("quit")
Parsed in 0.019 seconds