fix: robot force forward
This commit is contained in:
parent
1e30be3223
commit
4c84f48207
30
miner.lua
30
miner.lua
@ -31,6 +31,18 @@ local function isOdd(x)
|
|||||||
return (x % 2) == 1
|
return (x % 2) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function robotForceForward()
|
||||||
|
local ok = miner.robot.forward()
|
||||||
|
|
||||||
|
if ok then
|
||||||
|
return ok
|
||||||
|
end
|
||||||
|
|
||||||
|
turtleUtils.digAll()
|
||||||
|
|
||||||
|
return miner.robot.forward()
|
||||||
|
end
|
||||||
|
|
||||||
local function checkConfig()
|
local function checkConfig()
|
||||||
if config.targetY >= config.startY then
|
if config.targetY >= config.startY then
|
||||||
error('targetY should be lower than startY')
|
error('targetY should be lower than startY')
|
||||||
@ -112,12 +124,12 @@ local function returnMineProcedure()
|
|||||||
if robotState.y > miner.lastPositionState.y then
|
if robotState.y > miner.lastPositionState.y then
|
||||||
miner.robot.down()
|
miner.robot.down()
|
||||||
elseif robotState.z < miner.lastPositionState.z then
|
elseif robotState.z < miner.lastPositionState.z then
|
||||||
miner.robot.forward()
|
robotForceForward()
|
||||||
else
|
else
|
||||||
miner.robot.turnRight()
|
miner.robot.turnRight()
|
||||||
|
|
||||||
for i=1, miner.lastPositionState.x, 1 do
|
for i=1, miner.lastPositionState.x, 1 do
|
||||||
miner.robot.forward()
|
robotForceForward()
|
||||||
end
|
end
|
||||||
|
|
||||||
while miner.robot.getState().dir ~= miner.lastPositionState.dir do
|
while miner.robot.getState().dir ~= miner.lastPositionState.dir do
|
||||||
@ -144,19 +156,19 @@ local function mineProcedure()
|
|||||||
miner.robot.down()
|
miner.robot.down()
|
||||||
elseif robotState.dir == 'FORWARD' and robotState.z < targetZ then
|
elseif robotState.dir == 'FORWARD' and robotState.z < targetZ then
|
||||||
turtleUtils.digAll()
|
turtleUtils.digAll()
|
||||||
miner.robot.forward()
|
robotForceForward()
|
||||||
elseif robotState.dir == 'FORWARD' and robotState.z == targetZ then
|
elseif robotState.dir == 'FORWARD' and robotState.z == targetZ then
|
||||||
miner.robot.turnRight()
|
miner.robot.turnRight()
|
||||||
turtleUtils.digAll()
|
turtleUtils.digAll()
|
||||||
miner.robot.forward()
|
robotForceForward()
|
||||||
miner.robot.turnRight()
|
miner.robot.turnRight()
|
||||||
elseif robotState.dir == 'BACKWARD' and robotState.z > 0 then
|
elseif robotState.dir == 'BACKWARD' and robotState.z > 0 then
|
||||||
turtleUtils.digAll()
|
turtleUtils.digAll()
|
||||||
miner.robot.forward()
|
robotForceForward()
|
||||||
elseif robotState.dir == 'BACKWARD' and robotState.z == 0 then
|
elseif robotState.dir == 'BACKWARD' and robotState.z == 0 then
|
||||||
miner.robot.turnLeft()
|
miner.robot.turnLeft()
|
||||||
turtleUtils.digAll()
|
turtleUtils.digAll()
|
||||||
miner.robot.forward()
|
robotForceForward()
|
||||||
miner.robot.turnLeft()
|
miner.robot.turnLeft()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -171,7 +183,7 @@ local function mineProcedure()
|
|||||||
miner.robot.turnRight()
|
miner.robot.turnRight()
|
||||||
|
|
||||||
for i=1, config.size - 1, 1 do
|
for i=1, config.size - 1, 1 do
|
||||||
miner.robot.forward()
|
robotForceForward()
|
||||||
end
|
end
|
||||||
|
|
||||||
miner.robot.turnRight()
|
miner.robot.turnRight()
|
||||||
@ -206,13 +218,13 @@ local function returnHomeProcedure()
|
|||||||
end
|
end
|
||||||
|
|
||||||
for i=1, robotState.x, 1 do
|
for i=1, robotState.x, 1 do
|
||||||
miner.robot.forward()
|
robotForceForward()
|
||||||
end
|
end
|
||||||
|
|
||||||
miner.robot.turnLeft()
|
miner.robot.turnLeft()
|
||||||
elseif robotState.z > 0 then
|
elseif robotState.z > 0 then
|
||||||
for i=1, robotState.z, 1 do
|
for i=1, robotState.z, 1 do
|
||||||
miner.robot.forward()
|
robotForceForward()
|
||||||
end
|
end
|
||||||
|
|
||||||
miner.robot.turnLeft()
|
miner.robot.turnLeft()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user