From 0e48dbca122904eaacd57c0fa87886d18ee664f0 Mon Sep 17 00:00:00 2001 From: blunty666 Date: Tue, 20 Dec 2016 15:25:25 +0000 Subject: [PATCH] Added check for change in position between pathfinding sessions --- netNav/netNav.lua | 14 +++++++++++++- starNav/starNav.lua | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/netNav/netNav.lua b/netNav/netNav.lua index d58d5ee..53914d7 100644 --- a/netNav/netNav.lua +++ b/netNav/netNav.lua @@ -162,7 +162,7 @@ local function detectAll(currPos) end local function findSensor() - for _, side in ipairs(peripheral.getNames()) do + for _, side in ipairs({"left", "right"}) do if peripheral.getType(side) == "turtlesensorenvironment" then return side end @@ -247,6 +247,18 @@ local function _goto(x, y, z, maxDistance) if not position then return false, "couldn't determine location" end + else + -- check if position has changed + local curPos = {gps.locate()} + if #curPos == 3 then + curPos = vector.new(unpack(curPos)) + if not aStar.vectorEquals(curPos, position) then -- position has changed + position = findPosition() + if not position then + return false, "couldn't determine location" + end + end + end end local goal = vector.new(tonumber(x), tonumber(y), tonumber(z)) diff --git a/starNav/starNav.lua b/starNav/starNav.lua index 9618b99..edf2bba 100644 --- a/starNav/starNav.lua +++ b/starNav/starNav.lua @@ -157,7 +157,7 @@ local function detectAll(currPos) end local function findSensor() - for _, side in ipairs(peripheral.getNames()) do + for _, side in ipairs({"left", "right"}) do if peripheral.getType(side) == "turtlesensorenvironment" then return side end @@ -241,6 +241,18 @@ local function _goto(x, y, z, maxDistance) if not position then return false, "couldn't determine location" end + else + -- check if position has changed + local curPos = {gps.locate()} + if #curPos == 3 then + curPos = vector.new(unpack(curPos)) + if not aStar.vectorEquals(curPos, position) then -- position has changed + position = findPosition() + if not position then + return false, "couldn't determine location" + end + end + end end local goal = vector.new(tonumber(x), tonumber(y), tonumber(z))