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
|
||||
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()
|
||||
if config.targetY >= config.startY then
|
||||
error('targetY should be lower than startY')
|
||||
@ -112,12 +124,12 @@ local function returnMineProcedure()
|
||||
if robotState.y > miner.lastPositionState.y then
|
||||
miner.robot.down()
|
||||
elseif robotState.z < miner.lastPositionState.z then
|
||||
miner.robot.forward()
|
||||
robotForceForward()
|
||||
else
|
||||
miner.robot.turnRight()
|
||||
|
||||
for i=1, miner.lastPositionState.x, 1 do
|
||||
miner.robot.forward()
|
||||
robotForceForward()
|
||||
end
|
||||
|
||||
while miner.robot.getState().dir ~= miner.lastPositionState.dir do
|
||||
@ -144,19 +156,19 @@ local function mineProcedure()
|
||||
miner.robot.down()
|
||||
elseif robotState.dir == 'FORWARD' and robotState.z < targetZ then
|
||||
turtleUtils.digAll()
|
||||
miner.robot.forward()
|
||||
robotForceForward()
|
||||
elseif robotState.dir == 'FORWARD' and robotState.z == targetZ then
|
||||
miner.robot.turnRight()
|
||||
turtleUtils.digAll()
|
||||
miner.robot.forward()
|
||||
robotForceForward()
|
||||
miner.robot.turnRight()
|
||||
elseif robotState.dir == 'BACKWARD' and robotState.z > 0 then
|
||||
turtleUtils.digAll()
|
||||
miner.robot.forward()
|
||||
robotForceForward()
|
||||
elseif robotState.dir == 'BACKWARD' and robotState.z == 0 then
|
||||
miner.robot.turnLeft()
|
||||
turtleUtils.digAll()
|
||||
miner.robot.forward()
|
||||
robotForceForward()
|
||||
miner.robot.turnLeft()
|
||||
end
|
||||
|
||||
@ -171,7 +183,7 @@ local function mineProcedure()
|
||||
miner.robot.turnRight()
|
||||
|
||||
for i=1, config.size - 1, 1 do
|
||||
miner.robot.forward()
|
||||
robotForceForward()
|
||||
end
|
||||
|
||||
miner.robot.turnRight()
|
||||
@ -206,13 +218,13 @@ local function returnHomeProcedure()
|
||||
end
|
||||
|
||||
for i=1, robotState.x, 1 do
|
||||
miner.robot.forward()
|
||||
robotForceForward()
|
||||
end
|
||||
|
||||
miner.robot.turnLeft()
|
||||
elseif robotState.z > 0 then
|
||||
for i=1, robotState.z, 1 do
|
||||
miner.robot.forward()
|
||||
robotForceForward()
|
||||
end
|
||||
|
||||
miner.robot.turnLeft()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user