remie92

Untitled

Apr 22nd, 2026
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.92 KB | None | 0 0
  1. alt_sensor=peripheral.wrap("left")
  2. angle_sensor=peripheral.wrap("back")
  3. redstone=peripheral.wrap("top")
  4.  
  5. redstone2=peripheral.wrap("redstone_relay_1")
  6.  
  7. nav_sensor=peripheral.wrap("navigation_table_1")
  8.  
  9.  
  10. angles=angle_sensor.getAngles()
  11. alt=alt_sensor.getHeight()
  12. pitch=angles[1]
  13. roll=angles[2]
  14. nav_angle=90-nav_sensor.getRelativeAngle()
  15.  
  16.  
  17.  
  18. wanted_alt=180
  19.  
  20. wanted_pitch=0
  21. pitch_range=6
  22. wanted_roll=0
  23. roll_range=4
  24. yaw_range=10
  25.  
  26.  
  27.  
  28.  
  29.  
  30. function set_yaw(yaw_val)
  31.     left="bottom"
  32.     right="right"
  33.     if yaw_val==-1 then
  34.         redstone2.setOutput(left,true)    --up
  35.         redstone2.setOutput(right,false)
  36.     end
  37.     if yaw_val==0 then
  38.         redstone2.setOutput(left,false)
  39.         redstone2.setOutput(right,false)
  40.     end
  41.     if yaw_val==1 then
  42.         redstone2.setOutput(left,false)
  43.         redstone2.setOutput(right,true)
  44.     end
  45. end
  46.  
  47.  
  48.  
  49. function set_pitch(pitch_val)
  50.     if pitch_val==1 then
  51.         redstone.setOutput("left",true)    --up
  52.         redstone.setOutput("right",false)
  53.     end
  54.     if pitch_val==0 then
  55.         redstone.setOutput("right",false)
  56.         redstone.setOutput("left",false)
  57.     end
  58.     if pitch_val==-1 then
  59.         redstone.setOutput("left",false)
  60.         redstone.setOutput("right",true)
  61.     end
  62. end
  63.  
  64. function set_roll(roll_val)
  65.     if roll_val==1 then
  66.         redstone.setOutput("back",true)    --right
  67.         redstone.setOutput("front",false)
  68.     end
  69.     if roll_val==0 then
  70.         redstone.setOutput("back",false)
  71.         redstone.setOutput("front",false)
  72.     end
  73.     if roll_val==-1 then
  74.         redstone.setOutput("back",false)    --left
  75.         redstone.setOutput("front",true)
  76.     end
  77. end
  78.  
  79.  
  80.  
  81. function get_sensor_data()
  82.     angles=angle_sensor.getAngles()
  83.     alt=alt_sensor.getHeight()
  84.     pitch=angles[1]
  85.     roll=angles[2]
  86.     nav_angle=90-nav_sensor.getRelativeAngle()
  87. end
  88.  
  89. function calculate_pitch()
  90.     wanted_pitch=(alt-wanted_alt)/10
  91.     wanted_pitch=math.max(wanted_pitch,-30)
  92.     wanted_pitch=math.min(wanted_pitch,30)
  93.  
  94.  
  95.     if math.abs(wanted_pitch-pitch)>pitch_range then
  96.         if wanted_pitch-pitch<0 then
  97.             set_pitch(1)
  98.         else
  99.             set_pitch(-1)
  100.         end
  101.     else
  102.         set_pitch(0)
  103.     end
  104. end
  105.  
  106.  
  107. function calculate_roll()
  108.     if math.abs(wanted_roll-roll)>roll_range then
  109.         if wanted_roll-roll<0 then
  110.             set_roll(1)
  111.         else
  112.             set_roll(-1)
  113.         end
  114.     else
  115.         set_roll(0)
  116.     end
  117. end
  118.  
  119. function calculate_yaw()
  120.     if math.abs(nav_angle)>yaw_range then
  121.         if nav_angle<0 then
  122.             set_yaw(-1)
  123.         else
  124.             set_yaw(1)
  125.         end
  126.     else
  127.         set_yaw(0)
  128.     end
  129. end
  130.  
  131.  
  132. while true do
  133.     get_sensor_data()
  134.     calculate_pitch()
  135.     calculate_roll()
  136.     calculate_yaw()
  137.     print("Alt",alt)
  138.     print("pitch",pitch)
  139.     print("roll",roll)
  140.     print("Wanted Pitch",wanted_pitch)
  141.     print(nav_angle)
  142.     sleep(0)
  143. end
Advertisement
Add Comment
Please, Sign In to add comment