Advertisement
1ng0

CC - BigReactor Control by Pyramidalist 1/2 Multiturbine

Nov 28th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.95 KB | None | 0 0
  1. -----------------------------------------------------
  2. --                         --
  3. --  Pyramidalist                   --
  4. --                         --
  5. --  https://www.youtube.com/watch?v=BhOBAZqCI1g    --
  6. --                         --
  7. -----------------------------------------------------
  8. local reactor
  9.     reactor = peripheral.wrap("back")
  10.  
  11.     MIN = 244         -- SOLL-Temperatur
  12.      
  13.     BandBreite = 1    -- TemperaturToleranz
  14.     Grundstellung = 56 -- Rod-Anfangseinstellung
  15.     -- HINWEIS: 78 ist ein guter Startwert bei 5 Rods und 2 Maximal-Turbinen Ziel: 198 Grad
  16.     -- HINWEIS: 68 ist ein guter Startwert bei 5 Rods und 3 Maximal-Turbinen Ziel:    Grad
  17.     -- HINWEIS: 56 ist ein guter Startwert bei 5 Rods und 4 Maximal-Turbinen Ziel: 244 Grad
  18.    
  19.     Gain = 7          -- AnpassungsGeschwindigkeit
  20.    
  21.     Pulsschwelle = 5  -- maximale Abweichung in der der Puls gelten soll
  22.     PulseGain = 5     -- Puls für Tempanpassung in Kleinstschritten Kurz Pulsen und dann zurück
  23.     PulseDauer = 2    -- Sekunden Pulsdauer
  24.      
  25.     MAXKorrektur =  2 * Gain -- Grenze Schub zum Hochfahren
  26.     MINKorrektur = -1 * Gain -- Grenze Schub zum Abkuehlen
  27.  
  28.     ExtremCounterMAX = 0
  29.     ExtremCounterMIN = 0
  30.     boost = 1         -- Verschiebt ALLE Rods wenn der FeinStellRod zu oft extreme Werte hat
  31.      
  32.     Speed = 3         -- allgemeiner Warte-Zeitraum wegen Systemträgheit
  33.  
  34. rednet.open("top")
  35. MinOLD = MIN
  36. rednetA, MIN, rednetC = rednet.receive(Speed)
  37. if MIN == nil then
  38. MIN = MinOLD
  39. else
  40. -- MIN ist neu gesetzt
  41. end
  42. rednet.close("top")
  43.  
  44. -- Grundeinstellung zum Programmstart
  45.     reactor.setControlRodLevel(0, Grundstellung) -- 1
  46.     Rod0 = reactor.getControlRodName(0)
  47.     reactor.setControlRodLevel(1, Grundstellung) -- 2
  48.     Rod1 = reactor.getControlRodName(1)
  49.     reactor.setControlRodLevel(2, Grundstellung) -- 3
  50.     Rod2 = reactor.getControlRodName(2)
  51.     reactor.setControlRodLevel(3, Grundstellung) -- 4
  52.     Rod3 = reactor.getControlRodName(3)
  53.     reactor.setControlRodLevel(4, Grundstellung) -- 5
  54.     Rod4 = reactor.getControlRodName(4)
  55.  
  56.  
  57. -- LaufzeitScheife
  58.      
  59.     while true do
  60.      
  61.     term.clear()
  62.     term.setCursorPos(0, 0)
  63.     print("")
  64.    
  65.     if Mitte ~= 0 then
  66.     reactor.setControlRodLevel(0, Grundstellung) -- 1
  67.     Rod0 = reactor.getControlRodName(0)
  68.     -- print(Rod0,"0 in Grundstellung")
  69.     end
  70.     if Mitte ~= 1 then
  71.     reactor.setControlRodLevel(1, Grundstellung) -- 2
  72.     Rod1 = reactor.getControlRodName(1)
  73.     -- print(Rod0, "1 in Grundstellung")
  74.     end
  75.     if Mitte ~= 2 then
  76.     reactor.setControlRodLevel(2, Grundstellung) -- 3
  77.     Rod2 = reactor.getControlRodName(2)
  78.     -- print(Rod2, "2 in Grundstellung")
  79.     end
  80.     if Mitte ~= 3 then
  81.     reactor.setControlRodLevel(3, Grundstellung) -- 4
  82.     Rod3 = reactor.getControlRodName(3)
  83.     -- print(Rod3, "3 in Grundstellung")
  84.     end
  85.     if Mitte ~= 4 then
  86.     reactor.setControlRodLevel(4, Grundstellung) -- 5
  87.     Rod4 = reactor.getControlRodName(4)
  88.     -- print(Rod4, "4 in Grundstellung")
  89.     end
  90.  
  91. -- print("-----------------")
  92. -- print(reactor.getControlRodLevel(0))
  93. -- print(reactor.getControlRodLevel(1))
  94. -- print(reactor.getControlRodLevel(2))
  95. -- print(reactor.getControlRodLevel(3))
  96. -- print(reactor.getControlRodLevel(4))
  97.  
  98.  
  99. if Rod0 == "Pyra3Mitte" then print("Rod 0 ist Mitte", " Grundstellung = ", Grundstellung) Mitte = 0 sleep(1) end
  100. if Rod1 == "Pyra3Mitte" then print("Rod 1 ist Mitte", " Grundstellung = ", Grundstellung) Mitte = 1 sleep(1) end
  101. if Rod2 == "Pyra3Mitte" then print("Rod 2 ist Mitte", " Grundstellung = ", Grundstellung) Mitte = 2 sleep(1) end
  102. if Rod3 == "Pyra3Mitte" then print("Rod 3 ist Mitte", " Grundstellung = ", Grundstellung) Mitte = 3 sleep(1) end
  103. if Rod4 == "Pyra3Mitte" then print("Rod 4 ist Mitte", " Grundstellung = ", Grundstellung) Mitte = 4 sleep(1) end
  104. print("ExtremC.MAX= ", ExtremCounterMAX, "  ExtremC.MIN= ", ExtremCounterMIN)
  105.  
  106.     print(" ")
  107.  
  108.     Temperatur = reactor.getFuelTemperature()
  109.     print("Rel. 03 Temperatur= ", Temperatur, "     SOll= ", MIN)
  110.  
  111.      
  112.     Korrektur = MIN - Temperatur
  113.     if Korrektur > 1 then
  114.        Korrektur = (Gain - (Gain/Korrektur))
  115.     end
  116.     if Korrektur < -1 then
  117.        Korrektur = (Gain -(Gain/Korrektur))*-1
  118.     end
  119.      
  120.      
  121.     print("Korrektur ist        ", Korrektur)
  122.     if Korrektur > MAXKorrektur then
  123.     Korrektur = MAXKorrektur
  124.     end
  125.     if Korrektur < MINKorrektur then
  126.     Korrektur = MINKorrektur
  127.     end
  128.     print("Angepasste Korrektur ", Korrektur)
  129.      
  130.      
  131.     print(" ")
  132.      
  133.      -- WarteDauer zwischen RegelKreisDurchlaeufen
  134.     sleep(3)
  135.          
  136.      
  137.     -- ### Hier beginnt das eigentliche Programm
  138.     print("")
  139.      
  140.     if Temperatur < MIN then
  141.     print("Zu niedrige Temperatur")
  142.     if MIN - Temperatur > 10 then
  143.        ExtremCounterMIN = ExtremCounterMIN + 1
  144.        if ExtremCounterMIN > 3 then
  145.           Grundstellung = Grundstellung - 1
  146.           ExtremCounterMIN = 0
  147.           ExtremCounterMax = 0
  148.        end
  149.        reactor.setControlRodLevel(0, Grundstellung - boost) -- 1
  150.        reactor.setControlRodLevel(1, Grundstellung - boost) -- 2
  151.        reactor.setControlRodLevel(2, Grundstellung - boost) -- 3
  152.        reactor.setControlRodLevel(3, Grundstellung - boost) -- 4
  153.        reactor.setControlRodLevel(4, Grundstellung - boost) -- 5
  154.        sleep(Speed)
  155.     end
  156.     if MIN - Temperatur < Pulsschwelle then
  157.        RodPosition = reactor.getControlRodLevel(Mitte)
  158.        RodOld = RodPosition
  159.        print(RodPosition)
  160.        print("Pulsing auf:")
  161.        RodPosition = RodPosition - PulseGain
  162.        if RodPosition < 0.1 then RodPosition = 0.1 end
  163.        if RodPosition > 99.9 then RodPosition = 99,9 end
  164.        print(RodPosition)
  165.        reactor.setControlRodLevel(Mitte, RodPosition)
  166.        sleep(PulseDauer)
  167.        RodPosition = RodOld
  168.        reactor.setControlRodLevel(Mitte, RodPosition) -- zurück in Stellung vor Pulsing
  169.        Korrektur = 0 -- Verhindern einer Über-Re-Korrektur
  170.     else
  171.        RodPosition = reactor.getControlRodLevel(Mitte)
  172.        print(RodPosition)
  173.        print("Geaendert auf:")
  174.        RodPosition = RodPosition - Korrektur
  175.        if RodPosition < 0.1 then RodPosition = 0.1 end
  176.        if RodPosition > 99.9 then RodPosition = 99,9 end
  177.        print(RodPosition)
  178.        reactor.setControlRodLevel(Mitte, RodPosition)
  179.  
  180.     end
  181.     -- sleep(Speed)
  182.    
  183. rednet.open("top")
  184. MinOLD = MIN
  185. rednetA, MIN, rednetC = rednet.receive(Speed)
  186. if MIN == nil then
  187. MIN = MinOLD
  188. else
  189. -- MIN ist neu gesetzt
  190. end
  191. rednet.close("top")
  192.      
  193.     Temperature = reactor.getFuelTemperature()
  194.     if Temperature > MIN then
  195.     RodPosition = RodPosition + Korrektur
  196.     print("Anstieg gebremst")
  197.     print(RodPosition)
  198.     reactor.setControlRodLevel(Mitte, RodPosition)
  199.      
  200.     Speed = Speed / 3
  201.     end
  202.      
  203.     -- sleep(Speed)
  204. rednet.open("top")
  205. MinOLD = MIN
  206. rednetA, MIN, rednetC = rednet.receive(Speed)
  207. if MIN == nil then
  208. MIN = MinOLD
  209. else
  210. -- MIN ist neu gesetzt
  211. end
  212. rednet.close("top")
  213.  
  214.     else
  215.      
  216.     if Temperatur > MIN+BandBreite then
  217.     print("Temperatur zu hoch")
  218.     if Temperatur - (MIN+BandBreite) > 10 then
  219.        ExtremCounterMAX = ExtremCounterMAX + 1
  220.        if ExtremCounterMAX > 3 then
  221.           Grundstellung = Grundstellung + 1
  222.           ExtremCounterMAX = 0
  223.           ExtremCounterMin = 0
  224.        end
  225.        reactor.setControlRodLevel(0, Grundstellung + boost) -- 1
  226.        reactor.setControlRodLevel(1, Grundstellung + boost) -- 2
  227.        reactor.setControlRodLevel(2, Grundstellung + boost) -- 3
  228.        reactor.setControlRodLevel(3, Grundstellung + boost) -- 4
  229.        reactor.setControlRodLevel(4, Grundstellung + boost) -- 5
  230.        sleep(Speed)
  231.     end
  232.  
  233.     RodPosition = reactor.getControlRodLevel(Mitte)
  234.     print(RodPosition)
  235.     print("Geaendert auf:")
  236.      
  237.     RodPosition = RodPosition - Korrektur
  238.     if RodPosition < 0.1 then RodPosition = 0.1 end
  239.     if RodPosition > 99.9 then RodPosition = 99,9 end
  240.  
  241.     print(RodPosition)
  242.     reactor.setControlRodLevel(Mitte, RodPosition)
  243.      
  244.     -- sleep(Speed)
  245. rednet.open("top")
  246. MinOLD = MIN
  247. rednetA, MIN, rednetC = rednet.receive(Speed)
  248. if MIN == nil then
  249. MIN = MinOLD
  250. else
  251. -- MIN ist neu gesetzt
  252. end
  253. rednet.close("top")
  254.      
  255.     Temperature = reactor.getFuelTemperature()
  256.     if Temperature < MIN+BandBreite then
  257.      
  258.     RodPosition = RodPosition + Korrektur
  259.      
  260.      
  261.     print("Abfall gebremst")
  262.     print(RodPosition)
  263.     reactor.setControlRodLevel(Mitte, RodPosition)
  264.      
  265.     Speed = Speed / 3
  266.     end
  267.      
  268.     -- sleep(Speed)
  269. rednet.open("top")
  270. MinOLD = MIN
  271. rednetA, MIN, rednetC = rednet.receive(Speed)
  272. if MIN == nil then
  273. MIN = MinOLD
  274. else
  275. -- MIN ist neu gesetzt
  276. end
  277. rednet.close("top")
  278.      
  279.     else
  280.     print("Temperatur OK")
  281.     end
  282.      
  283.     end
  284.      
  285.     -- ### Hier ENDET das eigentliche Programm
  286.  
  287.     -- sleep(Speed)
  288. rednet.open("top")
  289. MinOLD = MIN
  290. rednetA, MIN, rednetC = rednet.receive(Speed)
  291. if MIN == nil then
  292. MIN = MinOLD
  293. else
  294. -- MIN ist neu gesetzt
  295. end
  296. rednet.close("top")
  297.  
  298.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement