Bjoerniboii

Bjoerniboii Big Reaktor Control

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