Advertisement
Micrafast

Drone firmware

Sep 8th, 2018
1,277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.93 KB | None | 0 0
  1. local useport = 1351 -- make sure this number is the same as the drone client
  2.  
  3. local drone = component.proxy(component.list("drone")())
  4. local navigation = component.proxy(component.list("navigation")())
  5. local modem = component.proxy(component.list("modem")())
  6. modem.open(useport)
  7. modem.setWakeMessage("_BROADCAST_TARGETS_PS_BOOT")
  8.  
  9. local function split(str, chrs)
  10.     local ret = {} string.gsub(str, "[^"..chrs.."]+", function(s) table.insert(ret, s) end) return ret
  11. end
  12.  
  13. local function main()
  14.     computer.beep(500, 1)
  15.     while true do
  16.         local name, receiver, sender, _, _, command = computer.pullSignal()
  17.         if name == "modem_message" then
  18.             local cmd = split(command, " ")
  19.             if cmd[1] == "_BROADCAST_TARGETS_PS_K" then
  20.                 modem.send(sender, useport, "target "..drone.name())
  21.             elseif cmd[1] == "list" then
  22.                 if cmd[2] == "waypoints" then
  23.                     local ways = navigation.findWaypoints(100)
  24.                     local ret = ""
  25.                     for i, v in ipairs(ways) do
  26.                         ret = ret .. tostring(i)..". "..v.label.."\n"
  27.                     end
  28.                     modem.send(sender, useport, ret)
  29.                 end
  30.             elseif cmd[1] == "goto" then
  31.                 local wname = cmd[2]
  32.                     local ways = navigation.findWaypoints(100)
  33.                     for i, v in ipairs(ways) do
  34.                         if not (type(v)=="number") then
  35.                             if v.label == wname then
  36.                                 modem.send(sender, useport, "Operation succeed.")
  37.                                 drone.move(v.position[1], v.position[2], v.position[3])
  38.                                 break
  39.                             end
  40.                         end
  41.                     end
  42.             elseif cmd[1] == "move" then
  43.                 if cmd[2] == "waypoints" then
  44.                     local wname = cmd[3]
  45.                     local ways = navigation.findWaypoints(100)
  46.                     for i, v in ipairs(ways) do
  47.                         if not (type(v)=="number") then
  48.                             if v.label == wname then
  49.                                 modem.send(sender, useport, "Operation succeed.")
  50.                                 drone.move(v.position[1], v.position[2], v.position[3])
  51.                                 break
  52.                             end
  53.                         end
  54.                     end
  55.                 elseif cmd[2] == "relpos" then
  56.                     local x = tonumber(cmd[3])
  57.                     local y = tonumber(cmd[4])
  58.                     local z = tonumber(cmd[5])
  59.                     modem.send(sender, useport, "Operation succeed.")
  60.                     drone.move(x, y, z)
  61.                 end
  62.             end
  63.             for i=1, 30 do
  64.                 computer.pullSignal(0.01)
  65.             end
  66.         end
  67.     end
  68. end
  69.  
  70. while true do
  71.     pcall(main)
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement