Potentially fixed heading issue.
This commit is contained in:
parent
098343f7fd
commit
6d3541a1c6
@ -325,9 +325,17 @@ local function determineHeading()
|
|||||||
sendLog(HEADING, "Heading obtained. \nForward: " .. textutils.serialiseJSON(heading) .. "\nRight direction: " .. textutils.serialiseJSON(rightAxis))
|
sendLog(HEADING, "Heading obtained. \nForward: " .. textutils.serialiseJSON(heading) .. "\nRight direction: " .. textutils.serialiseJSON(rightAxis))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function moveBy(delta, forward, right)
|
local function moveBy(delta, relative)
|
||||||
sendLog(MOVEBY, "Attempting to move by (" .. delta.x .. "," .. delta.y .. "," .. delta.z .. ") (x,y,z).")
|
sendLog(MOVEBY, "Attempting to move by (" .. delta.x .. "," .. delta.y .. "," .. delta.z .. ") (x,y,z).")
|
||||||
-- x first
|
local forward
|
||||||
|
local right
|
||||||
|
if relative then
|
||||||
|
forward = relHeading
|
||||||
|
right = relRightAxis
|
||||||
|
else
|
||||||
|
forward = heading
|
||||||
|
right = rightAxis
|
||||||
|
end
|
||||||
if delta.x ~= 0 then
|
if delta.x ~= 0 then
|
||||||
sendLog(MOVEBY, "Moving on x axis by: " .. delta.x)
|
sendLog(MOVEBY, "Moving on x axis by: " .. delta.x)
|
||||||
orient(vector.new(delta.x, 0, 0):normalize(), forward, right)
|
orient(vector.new(delta.x, 0, 0):normalize(), forward, right)
|
||||||
@ -367,7 +375,16 @@ local function moveBy(delta, forward, right)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function moveTo(dest)
|
local function moveTo(dest, relative)
|
||||||
|
local forward, right
|
||||||
|
if relative then
|
||||||
|
forward = relHeading
|
||||||
|
right = relRightAxis
|
||||||
|
else
|
||||||
|
forward = heading
|
||||||
|
right = rightAxis
|
||||||
|
end
|
||||||
|
|
||||||
dest = dest:round()
|
dest = dest:round()
|
||||||
sendLog(MOVETO, "Attempting to move by (" .. dest.x .. "," .. dest.y .. "," .. dest.z .. ") (x,y,z).")
|
sendLog(MOVETO, "Attempting to move by (" .. dest.x .. "," .. dest.y .. "," .. dest.z .. ") (x,y,z).")
|
||||||
if position == nil or heading == nil then
|
if position == nil or heading == nil then
|
||||||
@ -377,27 +394,33 @@ local function moveTo(dest)
|
|||||||
local xBlocked, yBlocked, zBlocked = false, false, false
|
local xBlocked, yBlocked, zBlocked = false, false, false
|
||||||
local oldPos = nil
|
local oldPos = nil
|
||||||
while not vectorEqual(dest, position) do
|
while not vectorEqual(dest, position) do
|
||||||
if oldPos ~= nil and vectorEqual(oldPos, position) then
|
local pos
|
||||||
|
if relative then
|
||||||
|
pos = position
|
||||||
|
else
|
||||||
|
pos = relativePos
|
||||||
|
end
|
||||||
|
if oldPos ~= nil and vectorEqual(oldPos, pos) then
|
||||||
sendLog(FAILED, "Cannot proceed to due obstacle. XYZ being blocked: " .. tostring(xBlocked) .. "," .. tostring(yBlocked) .. "," .. tostring(zBlocked))
|
sendLog(FAILED, "Cannot proceed to due obstacle. XYZ being blocked: " .. tostring(xBlocked) .. "," .. tostring(yBlocked) .. "," .. tostring(zBlocked))
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
oldPos = vector.new(position.x, position.y, position.z);
|
oldPos = vector.new(pos.x, pos.y, pos.z);
|
||||||
if position.x ~= dest.x then
|
if position.x ~= dest.x then
|
||||||
if not orient(vector.new(dest.x - position.x, 0, 0):normalize(), heading, rightAxis) then
|
if not orient(vector.new(dest.x - pos.x, 0, 0):normalize(), forward, right) then
|
||||||
sendLog(FAILED, "Unable to orient for X axis.")
|
sendLog(FAILED, "Unable to orient for X axis.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
xblocked = attemptMoveForward()
|
xblocked = attemptMoveForward()
|
||||||
end
|
end
|
||||||
if position.y ~= dest.y then
|
if position.y ~= dest.y then
|
||||||
if dest.y - position.y > 0 then
|
if dest.y - pos.y > 0 then
|
||||||
yBlocked = attemptMoveUp()
|
yBlocked = attemptMoveUp()
|
||||||
else
|
else
|
||||||
yBlocked = attemptMoveDown()
|
yBlocked = attemptMoveDown()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if position.z ~= dest.z then
|
if pos.z ~= dest.z then
|
||||||
if not orient(vector.new(0, 0, dest.z - position.z):normalize(), heading, rightAxis) then
|
if not orient(vector.new(0, 0, dest.z - pos.z):normalize(), forward, right) then
|
||||||
sendLog(FAILED, "Unable to orient for Z axis.")
|
sendLog(FAILED, "Unable to orient for Z axis.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -407,10 +430,19 @@ local function moveTo(dest)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function quarry(x, y, z, forward, right, pattern)
|
local function quarry(x, y, z, relative, pattern)
|
||||||
x = tonumber(x)
|
x = tonumber(x)
|
||||||
y = tonumber(y)
|
y = tonumber(y)
|
||||||
z = tonumber(z)
|
z = tonumber(z)
|
||||||
|
local forward;
|
||||||
|
local right;
|
||||||
|
if relative then
|
||||||
|
forward = relHeading
|
||||||
|
right = relRightAxis
|
||||||
|
else
|
||||||
|
forward = heading
|
||||||
|
right = rightAxis
|
||||||
|
end
|
||||||
sendLog(QUARRY, "Starting quarry of (x length,depth,z length): " .. x .. "," .. y .. "," .. z .. " with a not pattern of: " .. pattern)
|
sendLog(QUARRY, "Starting quarry of (x length,depth,z length): " .. x .. "," .. y .. "," .. z .. " with a not pattern of: " .. pattern)
|
||||||
for yDelta=1,math.abs(y) do
|
for yDelta=1,math.abs(y) do
|
||||||
if (y > 0) then
|
if (y > 0) then
|
||||||
@ -436,6 +468,7 @@ local function quarry(x, y, z, forward, right, pattern)
|
|||||||
for xDelta=1,math.abs(x) do
|
for xDelta=1,math.abs(x) do
|
||||||
for zDelta=1,math.abs(z) do
|
for zDelta=1,math.abs(z) do
|
||||||
print("X,Z: " .. xDelta .. "," .. zDelta)
|
print("X,Z: " .. xDelta .. "," .. zDelta)
|
||||||
|
print("heading, right heading: " .. forward .. ", " .. right)
|
||||||
local success = true;
|
local success = true;
|
||||||
if reverseTrip then
|
if reverseTrip then
|
||||||
orient(vector.new(0,0, -z), forward, right)
|
orient(vector.new(0,0, -z), forward, right)
|
||||||
@ -506,11 +539,11 @@ local function listen()
|
|||||||
if heading ~= nil then
|
if heading ~= nil then
|
||||||
print("Using actual coordinates.")
|
print("Using actual coordinates.")
|
||||||
sendLog(MOVETO, "Using actual coordinates to move.")
|
sendLog(MOVETO, "Using actual coordinates to move.")
|
||||||
attemptStartTask(MOVETO, moveTo, vector.new(x,y,z), heading, rightAxis)
|
attemptStartTask(MOVETO, moveTo, vector.new(x,y,z), false)
|
||||||
else
|
else
|
||||||
print("Using relative coordinates.")
|
print("Using relative coordinates.")
|
||||||
sendLog(MOVETO, "Using relative coordinates to move.")
|
sendLog(MOVETO, "Using relative coordinates to move.")
|
||||||
attemptStartTask(MOVETO, moveTo, vector.new(x,y,z), relHeading, relRightAxis)
|
attemptStartTask(MOVETO, moveTo, vector.new(x,y,z), true)
|
||||||
end
|
end
|
||||||
elseif data["request"] == MOVEBY then
|
elseif data["request"] == MOVEBY then
|
||||||
local x = data["content"][1]
|
local x = data["content"][1]
|
||||||
@ -519,11 +552,11 @@ local function listen()
|
|||||||
if heading ~= nil then
|
if heading ~= nil then
|
||||||
print("Using actual coordinates.")
|
print("Using actual coordinates.")
|
||||||
sendLog(MOVEBY, "Using actual coordinates to move.")
|
sendLog(MOVEBY, "Using actual coordinates to move.")
|
||||||
attemptStartTask(MOVEBY, moveBy, vector.new(x,y,z), heading, rightAxis)
|
attemptStartTask(MOVEBY, moveBy, vector.new(x,y,z), false)
|
||||||
else
|
else
|
||||||
print("Using relative coordinates.")
|
print("Using relative coordinates.")
|
||||||
sendLog(MOVEBY, "Using relative coordinates to move.")
|
sendLog(MOVEBY, "Using relative coordinates to move.")
|
||||||
attemptStartTask(MOVEBY, moveBy, vector.new(x,y,z), relHeading, relRightAxis)
|
attemptStartTask(MOVEBY, moveBy, vector.new(x,y,z), true)
|
||||||
end
|
end
|
||||||
elseif data["request"] == STATUS then
|
elseif data["request"] == STATUS then
|
||||||
status = {
|
status = {
|
||||||
@ -550,11 +583,11 @@ local function listen()
|
|||||||
determineHeading()
|
determineHeading()
|
||||||
elseif data["request"] == QUARRY then
|
elseif data["request"] == QUARRY then
|
||||||
if heading ~= nil then
|
if heading ~= nil then
|
||||||
quarry(data["content"][1], data["content"][2], data["content"][3], heading, rightAxis, notPattern)
|
quarry(data["content"][1], data["content"][2], data["content"][3], false, notPattern)
|
||||||
sendLog(QUARRY, "Using actual position for quarrying.")
|
sendLog(QUARRY, "Using actual position for quarrying.")
|
||||||
else
|
else
|
||||||
sendLog(QUARRY, "Using relative position for quarrying.")
|
sendLog(QUARRY, "Using relative position for quarrying.")
|
||||||
quarry(data["content"][1], data["content"][2], data["content"][3], relHeading, relRightAxis, notPattern)
|
quarry(data["content"][1], data["content"][2], data["content"][3], true, notPattern)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user