Advertisement
ordenix

Untitled

Mar 20th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. local r=peripheral.wrap("BigReactors-Reactor_26")
  2. --dpr
  3. local z=50
  4. local w=60
  5. local pp=4
  6. local ppr=0
  7. local wyster=100
  8. local zadane=50
  9. local k=60
  10. local ki=0.4
  11. local kd=0.9
  12. local u=0
  13. local up=0
  14. local su=0
  15. local prw=0
  16. local il=0
  17.  
  18. -- funkcja wlancz
  19. function spr(ppr)
  20. --wlancz
  21. --wylancz
  22. if ppr==1 then
  23. r.setActive(true)
  24. else
  25. r.setActive(false)
  26. end
  27. end
  28. --Glowna penta programu
  29. while true do
  30. local moc=r.getEnergyStored()/100000
  31. --function round(num, idp)
  32. --  local mult = 10^(idp or 0)
  33. --  mocz=math.floor(num * mult + 0.5) / mult
  34. --end
  35. --round(moc,2)
  36. --print(mocz)
  37. --sleep(10)
  38.  
  39. if pp==2 then
  40. if moc<z then
  41. spr(1)
  42. end
  43. if moc>w then
  44. spr(0)
  45. end
  46. end --end2
  47. if pp==1 then
  48. end --end pp1
  49. if pp==0 then
  50. end --pp0
  51. if pp==3 then --sterowanie PID
  52.  
  53.  
  54.  
  55. --poczĥA5A585tki
  56. function round(num, idp)
  57.   local mult = 10^(idp or 0)
  58.   mocz=math.floor(num * mult + 0.5) / mult
  59. end
  60. round(moc,3)
  61. --print(mocz)
  62. --sleep(10)
  63. --pobranie danych
  64. moc1=mocz
  65. sleep(1,1)
  66. local moc=r.getEnergyStored()/100000
  67. round(moc,3)
  68.  
  69.  
  70. moc2=mocz
  71. if moc1<moc2 and moc2>zadane then
  72. wyster=wyster+1
  73. print("c1")
  74. end
  75.  
  76.  
  77. if moc1>moc2 and moc2<zadane then
  78. wyster=wyster-1
  79. print("c2")
  80. end
  81. if moc1==moc2 and moc2==zadane then
  82. wyster=wyster
  83. print("c3")
  84. end
  85. if moc1<moc2 and moc2==zadane then
  86. wyster=wyster
  87. print("c4")
  88. end
  89. if moc1==moc2 and moc2<zadane  then
  90. wyster=wyster-1
  91. print("c5")
  92. end
  93. if moc1>moc2 and moc2==zadane then
  94. wyster=wyster
  95. print("c7")
  96. end
  97. if moc1==moc2 and moc2>zadane  then
  98. wyster=wyster+1
  99. print("c9")
  100. end
  101. if wyster>100 then
  102. wyster=100
  103. end
  104. if wyster<0 then
  105. wyster=0
  106. end
  107. print(wyster)
  108. print("1")
  109. print(moc1)
  110. print("2")
  111. print(moc2)
  112. r.setAllControlRodLevels(wyster)
  113.  
  114.  
  115. end
  116.  
  117.  
  118.  
  119. if pp==4 then
  120. r.setActive(true)
  121. local izpp=2
  122.  
  123. local mult = 10^(izpp or 0)
  124. local moc=r.getEnergyStored()/100000
  125. moco=math.floor(moc * mult + 0.5) / mult
  126. u=zadane-moco
  127. p=k*u
  128. su=su+u
  129. i=ki*su
  130. d=kd*(u-up)
  131. up=u
  132. il=il+1
  133.  
  134. print("MOCo:")
  135. print(moco)
  136. print("zwyster")
  137. print(wyster)
  138. print(il)
  139. --print("suma")
  140. --print(su)
  141. --print(i)
  142. print("--------")
  143. sleep(0,5)
  144.  
  145. pwr=p+i+d
  146. wyster=100-pwr
  147.  
  148.  
  149. if wyster>100 then
  150. wyster=100
  151. end
  152. if wyster<0 then
  153. wyster=0
  154. end
  155.  
  156. r.setAllControlRodLevels(wyster)
  157.  
  158. end
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177. sleep(0,1)
  178.  
  179. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement