Всем ку, благодоря бессоной ночи изучение api opencomputers написал прогу для контроля за роботом через планшет.
Благодаря возможно изменения разрешения удалось свернуть окно для обзора за роботом, сделать это можно по кнопке "R".
Для работы этого приложения на компьютер или планшет нужно установить видеокарту карту 2 уровня или выше (из-за изменения разрешения) , и вайфай карту.
На робота только вайфай карту.
Из функционала доступно:
Все функции движения
Все swing()
Все use()
И моя любимая команда для робота вида :
os.execute(msg)где msg это то что вы вписали при вызове отправки шела:
Протокол передачи написан настолько по индусски и небезопастно, что для работы вам достаточно просто запустить эти программы на роботе и планшете.
Вашего робота могут просто упереть этой же программой XD.
Если вы одобрите эту программу, то я допилю её.
Код для планшета:
--tab
local component = require("component")
local term = require("term")
local event = require("event")
local m = component.modem
--component.gpu.setResolution(1,1)
term.clear()
print("--------------------------------------------------------------")
print("|Движение: Вперёд= ↑; Назад = ↓; Вниз = ctrl; Вверх = shift; |")
print("|Поворот: Влево = ←; Вправо →; Выход из программы = '0' |")
print("|Shell = 'O' - передать аргумент shell робота; |")
print("|Левый клик: Вперёд = space; Вверх = 'E'; Вниз = 'D' |")
print("|Правый клик: Вперёд = enter; Вверх = 'W'; Вниз = 'S' |")
print("|Сворачивание окна планшета для слежения за роботом = 'R' |")
print("|By http://vk.com/dencraft23 for http://computercraft.ru/ |")
print("--------------------------------------------------------------")
m.open(23)
sr = 1
while true do
_,_,key1,key2 = event.pull("key_down")
z = key2
print(z)
if (z==19) then
if (sr==1) then
term.clear()
component.gpu.setResolution(2,2)
sr = 0
else
component.gpu.setResolution(80,25)
print("--------------------------------------------------------------")
print("|Движение: Вперёд= ↑; Назад = ↓; Вниз = ctrl; Вверх = shift; |")
print("|Поворот: Влево = ←; Вправо →; Выход из программы = '0' |")
print("|Shell = 'O' - передать аргумент shell робота; |")
print("|Левый клик: Вперёд = space; Вверх = 'E'; Вниз = 'D' |")
print("|Правый клик: Вперёд = enter; Вверх = 'W'; Вниз = 'S' |")
print("|Сворачивание окна планшета для слежения за роботом = 'R' |")
print("|By http://vk.com/dencraft23 for http://computercraft.ru/ |")
print("--------------------------------------------------------------")
sr = 1
end
end
if (z==200) then
m.broadcast(66, "f")
end
if (z==208) then
m.broadcast(66, "b")
end
if (z==203) then
m.broadcast(66, "l")
end
if (z==205) then
m.broadcast(66, "r")
end
if (z==42) then
m.broadcast(66, "u")
end
if (z==29) then
m.broadcast(66, "d")
end
if (z==57) then
m.broadcast(66, "swing")
end
if (z==28) then
m.broadcast(66, "use")
end
if (z==17) then
m.broadcast(66, "useup")
end
if (z==31) then
m.broadcast(66, "usedown")
end
if (z==18) then
m.broadcast(66, "swingup")
end
if (z==32) then
m.broadcast(66, "swingdown")
end
if (z==11) then
m.broadcast(66,"exit")
shell.execute("sh")
end
if (z==24) then
m.broadcast(66,"shell")
os.sleep(1)
print("shell:")
shellr = io.read()
m.broadcast(66,shellr)
end
end
end
Код для робота:
--robot
term = require("term")
r = require("robot")
local component = require("component")
local event = require("event")
local m = component.modem
term.clear()
m.open(66)
while true do
local _, _, _, _, _, msg = event.pull("modem_message")
z = tostring(msg)
if (z=="f") then
r.forward()
end
if (z=="b") then
r.back()
end
if (z=="l") then
r.turnLeft()
end
if (z=="r") then
r.turnRight()
end
if (z=="u") then
r.up()
end
if (z=="d") then
r.down()
end
if (z=="swing") then
r.swing()
end
if (z=="useup") then
r.useUp()
end
if (z=="usedown") then
r.useDown()
end
if (z=="swingup") then
r.swingUp()
end
if (z=="swingdown") then
r.swingDown()
end
if (z=="use") then
r.use()
end
if (z=="exit") then
shell.execute("sh")
end
if (z=="shell") then
local _, _, _, _, _, msg = event.pull("modem_message")
os.execute(msg)
end
end