Added check for change in position between pathfinding sessions
This commit is contained in:
parent
49a0f95f7b
commit
0e48dbca12
@ -162,7 +162,7 @@ local function detectAll(currPos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function findSensor()
|
local function findSensor()
|
||||||
for _, side in ipairs(peripheral.getNames()) do
|
for _, side in ipairs({"left", "right"}) do
|
||||||
if peripheral.getType(side) == "turtlesensorenvironment" then
|
if peripheral.getType(side) == "turtlesensorenvironment" then
|
||||||
return side
|
return side
|
||||||
end
|
end
|
||||||
@ -247,6 +247,18 @@ local function _goto(x, y, z, maxDistance)
|
|||||||
if not position then
|
if not position then
|
||||||
return false, "couldn't determine location"
|
return false, "couldn't determine location"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
local goal = vector.new(tonumber(x), tonumber(y), tonumber(z))
|
local goal = vector.new(tonumber(x), tonumber(y), tonumber(z))
|
||||||
|
|||||||
@ -157,7 +157,7 @@ local function detectAll(currPos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function findSensor()
|
local function findSensor()
|
||||||
for _, side in ipairs(peripheral.getNames()) do
|
for _, side in ipairs({"left", "right"}) do
|
||||||
if peripheral.getType(side) == "turtlesensorenvironment" then
|
if peripheral.getType(side) == "turtlesensorenvironment" then
|
||||||
return side
|
return side
|
||||||
end
|
end
|
||||||
@ -241,6 +241,18 @@ local function _goto(x, y, z, maxDistance)
|
|||||||
if not position then
|
if not position then
|
||||||
return false, "couldn't determine location"
|
return false, "couldn't determine location"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
local goal = vector.new(tonumber(x), tonumber(y), tonumber(z))
|
local goal = vector.new(tonumber(x), tonumber(y), tonumber(z))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user