Skip to content

Commit

Permalink
Bug fix for bunker silo driver #2783
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Oct 18, 2023
1 parent 4fcef26 commit 283df35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
19 changes: 5 additions & 14 deletions scripts/ai/AIDriveStrategyBunkerSilo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,11 @@ function AIDriveStrategyBunkerSilo.new(customMt)
AIDriveStrategyCourse.initStates(self, AIDriveStrategyBunkerSilo.myStates)
self.state = self.states.DRIVING_TO_SILO

-- course offsets dynamically set by the AI and added to all tool and other offsets
self.aiOffsetX, self.aiOffsetZ = 0, 0
self.debugChannel = CpDebug.DBG_SILO
---@type ImplementController[]
self.controllers = {}
self.silo = nil
self.siloController = nil
self.drivingForwardsIntoSilo = true
self.turnNode = CpUtil.createNode("turnNode", 0, 0, 0)


self.isStuckTimer = Timer.new(self.isStuckMs)
self.driveIntoSiloAttempts = 0
Expand Down Expand Up @@ -177,7 +172,7 @@ function AIDriveStrategyBunkerSilo:setAllStaticParameters()
else
self:startDrivingTemporaryOutOfSilo()
end
elseif self.siloController:hasNearbyUnloader() and self:isDrivingToParkPositionAllowed() then
elseif self.state == self.states.DRIVING_INTO_SILO and self.siloController:hasNearbyUnloader() and self:isDrivingToParkPositionAllowed() then
self:debug("Found an unloader nearby and is stuck, so immediately leave the silo.")
self:startDrivingOutOfSilo()
end
Expand Down Expand Up @@ -292,15 +287,11 @@ end
function AIDriveStrategyBunkerSilo:update(dt)
AIDriveStrategyBunkerSilo:superClass().update(self, dt)
self:updateImplementControllers(dt)

if CpDebug:isChannelActive(self.debugChannel, self.vehicle) then
if self.course then
-- TODO_22 check user setting
if self.course:isTemporary() then
self.course:draw()
elseif self.ppc:getCourse():isTemporary() then
self.ppc:getCourse():draw()
end
if self.course and self.course:isTemporary() then
self.course:draw()
elseif self.ppc:getCourse():isTemporary() then
self.ppc:getCourse():draw()
end
if self.siloEndDetectionMarker ~= nil then
DebugUtil.drawDebugNode(self.siloEndDetectionMarker, "siloEndDetectionMarker", false, 1)
Expand Down
6 changes: 3 additions & 3 deletions scripts/ai/controllers/LevelerController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ function LevelerController:setCylinderedLevelerRotation(dt, offsetDeg)
local _, dy, _ = localToWorld(self.levelerTool.node, 0, 0, 0)
local dx, _, dz = localToWorld(self.levelerNode, 0, 0, 0)
local _, ny, _ = worldToLocal(self.levelerTool.node, dx, dy, dz)
self:debug("dist: %.2f, ny: %.2f", dist, ny)
-- self:debug("dist: %.2f, ny: %.2f", dist, ny)
local targetRot = math.asin(ny/dist) + math.rad(offsetDeg)
if ny > 0 then
targetRot = -math.asin(-ny/dist) + math.rad(offsetDeg)
end
self:debug("curRot: %.2f, targetRot: %.2f, offset: %.2f, rotMin: %.2f, rotMax: %.2f",
angle, targetRot, math.rad(offsetDeg), self.levelerTool.rotMin, self.levelerTool.rotMax)
-- self:debug("curRot: %.2f, targetRot: %.2f, offset: %.2f, rotMin: %.2f, rotMax: %.2f",
-- angle, targetRot, math.rad(offsetDeg), self.levelerTool.rotMin, self.levelerTool.rotMax)

return ImplementUtil.moveMovingToolToRotation(self.levelerToolVehicle, self.levelerTool, dt,
MathUtil.clamp(angle - targetRot, self.levelerTool.rotMin, self.levelerTool.rotMax))
Expand Down

0 comments on commit 283df35

Please sign in to comment.