Skip to content

Commit

Permalink
Added check for change in position between pathfinding sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
blunty666 committed Dec 20, 2016
1 parent 49a0f95 commit 0e48dbc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion netNav/netNav.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
14 changes: 13 additions & 1 deletion starNav/starNav.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 0e48dbc

Please sign in to comment.