mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2025-12-24 04:52:48 +01:00
))))
This commit is contained in:
parent
1d8faad9a7
commit
e0e17a8b43
95
Applications/Robot/VRScanComputer.lua
Normal file
95
Applications/Robot/VRScanComputer.lua
Normal file
@ -0,0 +1,95 @@
|
||||
|
||||
local component = require("component")
|
||||
local GUI = require("GUI")
|
||||
local filesystem = require("filesystem")
|
||||
local MineOSPaths = require("MineOSPaths")
|
||||
|
||||
local glasses = component.glasses
|
||||
local modem = component.modem
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local port = 512
|
||||
|
||||
config = {
|
||||
offsetX = 0,
|
||||
offsetY = 0,
|
||||
offsetZ = 0,
|
||||
}
|
||||
|
||||
local configPath = MineOSPaths.applicationData .. "VRScan.cfg"
|
||||
if filesystem.exists(configPath) then
|
||||
config = table.fromFile(configPath)
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function broadcast(...)
|
||||
modem.broadcast(port, "VRScan", ...)
|
||||
end
|
||||
|
||||
local mainContainer = GUI.fullScreenContainer()
|
||||
mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, 0xF0F0F0))
|
||||
|
||||
local layout = mainContainer:addChild(GUI.layout(1, 1, mainContainer.width, mainContainer.height, 1, 1))
|
||||
|
||||
local offsetXInput = layout:addChild(GUI.input(1, 1, 36, 3, 0xE1E1E1, 0x787878, 0xB4B4B4, 0xE1E1E1, 0x2D2D2D, tostring(config.offsetX), "Robot offset by X"))
|
||||
|
||||
local offsetYInput = layout:addChild(GUI.input(1, 1, 36, 3, 0xE1E1E1, 0x787878, 0xB4B4B4, 0xE1E1E1, 0x2D2D2D, tostring(config.offsetY), "Robot offset by Y"))
|
||||
|
||||
local offsetZInput = layout:addChild(GUI.input(1, 1, 36, 3, 0xE1E1E1, 0x787878, 0xB4B4B4, 0xE1E1E1, 0x2D2D2D, tostring(config.offsetZ), "Robot offset by Z"))
|
||||
|
||||
local widthSlider = layout:addChild(GUI.slider(1, 1, 36, 0x66DB80, 0xE1E1E1, 0xFFFFFF, 0xB4B4B4, 1, 10, 3, false, "Width: ", ""))
|
||||
widthSlider.height = 2
|
||||
widthSlider.roundValues = true
|
||||
|
||||
local heightSlider = layout:addChild(GUI.slider(1, 1, 36, 0x66DB80, 0xE1E1E1, 0xFFFFFF, 0xB4B4B4, 1, 10, 3, false, "Height: ", ""))
|
||||
heightSlider.height = 2
|
||||
heightSlider.roundValues = true
|
||||
|
||||
local lengthSlider = layout:addChild(GUI.slider(1, 1, 36, 0x66DB80, 0xE1E1E1, 0xFFFFFF, 0xB4B4B4, 1, 10, 3, false, "Length: ", ""))
|
||||
lengthSlider.height = 2
|
||||
heightSlider.roundValues = true
|
||||
|
||||
local radiusSlider = layout:addChild(GUI.slider(1, 1, 36, 0x66DB80, 0xE1E1E1, 0xFFFFFF, 0xB4B4B4, 1, 10, 3, false, "Radius: ", ""))
|
||||
radiusSlider.height = 2
|
||||
radiusSlider.roundValues = true
|
||||
|
||||
local minDensitySlider = layout:addChild(GUI.slider(1, 1, 36, 0x66DB80, 0xE1E1E1, 0xFFFFFF, 0xB4B4B4, 0, 10, 0.5, false, "Min density: ", ""))
|
||||
minDensitySlider.height = 2
|
||||
|
||||
local maxDensitySlider = layout:addChild(GUI.slider(1, 1, 36, 0x66DB80, 0xE1E1E1, 0xFFFFFF, 0xB4B4B4, 0, 10, 0.5, false, "Max density: ", ""))
|
||||
maxDensitySlider.height = 2
|
||||
|
||||
layout:addChild(GUI.button(1, 1, 36, 3, 0xC3C3C3, 0xFFFFFF, 0x969696, 0xFFFFFF, "Scan")).onTouch = function()
|
||||
config.offsetX, config.offsetY, config.offsetZ = tonumber(offsetXInput.text), tonumber(offsetYInput.text), tonumber(offsetZInput.text)
|
||||
table.toFile(configPath, config)
|
||||
|
||||
broadcast(
|
||||
"scan",
|
||||
config.offsetX,
|
||||
config.offsetY,
|
||||
config.offsetZ,
|
||||
math.floor(widthSlider.value),
|
||||
math.floor(heightSlider.value),
|
||||
math.floor(lengthSlider.value),
|
||||
math.floor(radiusSlider.value),
|
||||
minDensitySlider.value,
|
||||
maxDensitySlider.value
|
||||
)
|
||||
end
|
||||
|
||||
layout.eventHandler = function(mainContainer, layout, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12)
|
||||
if e1 == "modem_message" and e6 == "VRScan" then
|
||||
if e7 == "result" then
|
||||
local robotX, robotY, robotZ, result = e[8], e[9], e[10], serialization.unserialize(e[11])
|
||||
GUI.alert("Got result from " .. robotX .. "x" .. robotY .. robotZ .. " with size " .. #result)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
modem.open(port)
|
||||
mainContainer:drawOnScreen(true)
|
||||
mainContainer:startEventHandling()
|
||||
61
Applications/Robot/VRScanRobot.lua
Normal file
61
Applications/Robot/VRScanRobot.lua
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
local AR = require("advancedRobot")
|
||||
local event = require("event")
|
||||
local serialization = require("serialization")
|
||||
|
||||
local port = 512
|
||||
AR.proxies.modem.open(port)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function broadcast(...)
|
||||
modem.broadcast(port, "VRScan", ...)
|
||||
end
|
||||
|
||||
local function move(x, y, z)
|
||||
print("Moving to next chunk with offset " .. x .. "x" .. y .. "x" .. z)
|
||||
AR.moveToPosition(AR.robotPositionX + x, AR.robotPositionY + y, AR.robotPositionZ + z)
|
||||
end
|
||||
|
||||
while true do
|
||||
local e = {event.pull()}
|
||||
if e[1] == "modem_message" and e[6] == "VRScan" then
|
||||
if e[7] == "scan" then
|
||||
print("Scanning started")
|
||||
|
||||
local width, height, length, radius, minDensity, maxDensity = e[8], e[9], e[10], e[11], e[12], e[13]
|
||||
|
||||
for h = 1, height do
|
||||
for w = 1, width do
|
||||
for l = 1, length do
|
||||
print("Scanning chunk " .. w .. " x " .. h .. " x " .. l)
|
||||
|
||||
local result, column = {}
|
||||
for z = -radius, radius do
|
||||
for x = -radius, radius do
|
||||
column = AR.proxies.geolyzer.scan(x, z)
|
||||
for i = 1, #column do
|
||||
if column[i] >= minDensity and column[i] <= maxDensity then
|
||||
table.insert(result, AR.robotPositionX)
|
||||
table.insert(result, AR.robotPositionY)
|
||||
table.insert(result, AR.robotPositionZ)
|
||||
table.insert(result, column[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print("Scanning finished. Sending result with size: " .. #result)
|
||||
broadcast("result", AR.robotPositionX, AR.robotPositionY, AR.robotPositionZ, serialization.serialize(result))
|
||||
|
||||
move(0, 0, radius + 1)
|
||||
end
|
||||
|
||||
move(radius + 1, 0, 0)
|
||||
end
|
||||
|
||||
move(0, radius + 1, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,8 +1,9 @@
|
||||
local AR = require("advancedRobot")
|
||||
local args = {...}
|
||||
|
||||
if #args < 0 then
|
||||
print("No arguments")
|
||||
if #args == 0 then
|
||||
print("Usage:")
|
||||
print(" commander <command string>")
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user