From 1a28f00c3e16e48bb79c6124dbe3207b05f3e1d2 Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Thu, 14 Jun 2018 22:42:06 +0300 Subject: [PATCH] aefae --- Applications/Robot/VRScanRobot.lua | 128 +++++++++++++++++---------- Applications/Robot/advancedRobot.lua | 12 --- 2 files changed, 83 insertions(+), 57 deletions(-) diff --git a/Applications/Robot/VRScanRobot.lua b/Applications/Robot/VRScanRobot.lua index af0e3195..d5144f67 100644 --- a/Applications/Robot/VRScanRobot.lua +++ b/Applications/Robot/VRScanRobot.lua @@ -1,6 +1,7 @@ local AR = require("advancedRobot") local event = require("event") +local sides = require("sides") local serialization = require("serialization") local port = 512 @@ -29,67 +30,104 @@ while true do if e[1] == "modem_message" and e[6] == "VRScan" then if e[7] == "scan" then local settings = serialization.unserialize(e[8]) - + local w, h, l + + AR.positionX = 0 + AR.positionY = 0 + AR.positionZ = 0 + AR.rotation = 0 + print("Scanning with paramerers: " .. e[8]) - local h, w, l, startX, startY, startZ = 0, 0, 0, AR.positionX, AR.positionY, AR.positionZ - - local function move() - local distance = settings.radius * 2 + 1 - local moveX, moveZ = AR.getRotatedPosition(w * distance, l * distance) - - AR.moveToPosition( - startX + moveX, - startY + h * distance, - startZ + moveZ - ) + local function moveChunk(side) + for i = 1, settings.radius * 2 + 1 do + AR.swingAndMove(side) + end end - while h < settings.height do - while w < settings.width do - while l < settings.length do - print("Scanning chunk " .. w .. " x " .. h .. " x " .. l) + local function doChunk() + print("Scanning chunk " .. w .. " x " .. h .. " x " .. l) + + local result, column = { + x = AR.positionX, + y = AR.positionY, + z = AR.positionZ, + blocks = {} + } + + local blockCount = 0 + for z = -settings.radius, settings.radius do + for x = -settings.radius, settings.radius do + column = AR.proxies.geolyzer.scan(x, z) - local result, column = { - x = AR.positionX, - y = AR.positionY, - z = AR.positionZ, - blocks = {} - } + for i = 32 - settings.radius, 32 + settings.radius do + if column[i] >= settings.minDensity and column[i] <= settings.maxDensity then + local y = i - 33 + result.blocks[x] = result.blocks[x] or {} + result.blocks[x][y] = result.blocks[x][y] or {} + result.blocks[x][y][z] = result.blocks[x][y][z] or {} + table.insert(result.blocks[x][y][z], round(column[i], 2)) - local blockCount = 0 - for z = -settings.radius, settings.radius do - for x = -settings.radius, settings.radius do - column = AR.proxies.geolyzer.scan(x, z) - - for i = 32 - settings.radius, 32 + settings.radius do - if column[i] >= settings.minDensity and column[i] <= settings.maxDensity then - local y = i - 33 - result.blocks[x] = result.blocks[x] or {} - result.blocks[x][y] = result.blocks[x][y] or {} - result.blocks[x][y][z] = result.blocks[x][y][z] or {} - table.insert(result.blocks[x][y][z], round(column[i], 2)) + blockCount = blockCount + 1 + end + end + end + end - blockCount = blockCount + 1 - end - end + print("Scanning finished. Sending result with blocks size: " .. blockCount) + broadcast("result", serialization.serialize(result)) + end + + local function doLength() + l = 1 + while l <= settings.length do + doChunk() + if l < settings.length then + moveChunk(sides.front) + end + l = l + 1 + end + end + + h = 1 + while h <= settings.height do + w = 1 + while w <= settings.width do + doLength() + + AR.turnRight() + moveChunk(sides.front) + AR.turnRight() + + doLength() + + if w < settings.width then + AR.turnLeft() + moveChunk(sides.front) + AR.turnLeft() + else + AR.turnRight() + for i = 1, settings.width * 2 - 1 do + moveChunk(sides.front) + end + AR.turnRight() + + if h < settings.height then + moveChunk(sides.up) + else + for i = 1, settings.height - 1 do + moveChunk(sides.down) end end - - print("Scanning finished. Sending result with blocks size: " .. blockCount) - broadcast("result", serialization.serialize(result)) - - l = l + 1 - move() end w = w + 1 - move() end h = h + 1 - move() end + + print("Task finished") end end end diff --git a/Applications/Robot/advancedRobot.lua b/Applications/Robot/advancedRobot.lua index 34f3c15d..ec9c4570 100644 --- a/Applications/Robot/advancedRobot.lua +++ b/Applications/Robot/advancedRobot.lua @@ -58,18 +58,6 @@ AR.rotation = 0 -------------------------------------------------------------------------------- -function AR.getRotatedPosition(x, z) - if AR.rotation == 0 then - return x, z - elseif AR.rotation == 1 then - return -z, x - elseif AR.rotation == 2 then - return -x, -z - else - return z, -x - end -end - function AR.updateProxies() local name for name in pairs(AR.requiredProxies) do