Skip to content

Commit

Permalink
Fix for shovels and more debug options
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Aug 21, 2023
1 parent 3650d9a commit 2df69c3
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 17 deletions.
3 changes: 3 additions & 0 deletions config/VehicleConfigurations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ You can define the following custom settings:
<Vehicle name="lowloader4A.xml"
disableUnfolding = "true"
/>
<Vehicle name="l180HHighTipShovel.xml"
shovelMovingToolIx = "1"
/>

<!--Vermeer-->
<Vehicle name="tm1410.xml"
Expand Down
6 changes: 5 additions & 1 deletion scripts/ai/ImplementUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ function ImplementUtil.stopMovingTool(implement, tool)
end

function ImplementUtil.getLevelerNode(object)
return object.spec_leveler and object.spec_leveler.nodes and object.spec_leveler.nodes[1] and object.spec_leveler.nodes[1]
return object.spec_leveler and object.spec_leveler.nodes and object.spec_leveler.nodes[1]
end

function ImplementUtil.getShovelNode(object)
return object.spec_shovel and object.spec_shovel.shovelNodes and object.spec_shovel.shovelNodes[1]
end

--- Visually displays the bale collector offset
Expand Down
35 changes: 33 additions & 2 deletions scripts/ai/controllers/ShovelController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ ShovelController.POSITIONS = {
UNLOADING = 4,
}

function ShovelController:init(vehicle, implement)
function ShovelController:init(vehicle, implement, isConsoleCommand)
ImplementController.init(self, vehicle, implement)
self.shovelSpec = self.implement.spec_shovel
self.shovelNode = self.shovelSpec.shovelNodes[1]
self.shovelNode = ImplementUtil.getShovelNode(implement)
self.turnOnSpec = self.implement.spec_turnOnVehicle
self.isConsoleCommand = isConsoleCommand
end

function ShovelController:update()
Expand Down Expand Up @@ -126,3 +127,33 @@ function ShovelController:moveShovelToPosition(pos)
self.implement:cpSetShovelState(pos)
return self.implement:areCpShovelPositionsDirty()
end

function ShovelController:printShovelDebug()
self:debug("--Shovel Debug--")
if self.shovelNode then
self:debug("Fill unit index: %d, max pickup angle: %.2f, width: %.2f",
self.shovelNode.fillUnitIndex,
math.deg(self.shovelNode.maxPickupAngle),
self.shovelNode.width)
if self.shovelNode.movingToolActivation then
self:debug("Has moving tool activation => open factor: %.2f, inverted: %s",
self.shovelNode.movingToolActivation.openFactor,
tostring(self.shovelNode.movingToolActivation.isInverted))
end
if self.shovelSpec.shovelDischargeInfo.node then
self:debug("min angle: %.2f, max angle: %.2f",
math.deg(self.shovelSpec.shovelDischargeInfo.minSpeedAngle),
math.deg(self.shovelSpec.shovelDischargeInfo.maxSpeedAngle))
end
end
self:debug("--Shovel Debug finished--")
end

function ShovelController:debug(...)
if self.isConsoleCommand then
--- Ignore vehicle debug setting, if the pipe controller was created by a console command.
self:info(...)
return
end
ImplementController.debug(self, ...)
end
83 changes: 69 additions & 14 deletions scripts/specializations/CpShovelPositions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ CpShovelPositions.KEY = "." .. CpShovelPositions.SPEC_NAME

function CpShovelPositions.initSpecialization()
local schema = Vehicle.xmlSchemaSavegame
g_devHelper.consoleCommands:registerConsoleCommand('cpSetShovelState', 'cpSetShovelState', 'consoleCommandSetShovelState', CpShovelPositions)
g_devHelper.consoleCommands:registerConsoleCommand('cpSetShovelArmLimit', 'cpSetShovelArmLimit', 'consoleCommandSetPreUnloadArmLimit', CpShovelPositions)

g_devHelper.consoleCommands:registerConsoleCommand("cpShovelPositionsPrintShovelDebug",
"Prints debug information for the shovel",
"consoleCommandPrintShovelDebug", CpShovelPositions)
g_devHelper.consoleCommands:registerConsoleCommand("cpShovelPositionsSetState",
"Set's the current shovel state",
"consoleCommandSetShovelState", CpShovelPositions)
g_devHelper.consoleCommands:registerConsoleCommand("cpShovelPositionsSetArmLimit",
"Set's the arm max limit",
"consoleCommandSetPreUnloadArmLimit", CpShovelPositions)
end

function CpShovelPositions.prerequisitesPresent(specializations)
Expand Down Expand Up @@ -140,6 +148,49 @@ function CpShovelPositions:consoleCommandSetPreUnloadArmLimit(min, max)
end, min, max)
end

function CpShovelPositions:consoleCommandPrintShovelDebug(cylinderedDepth)
return executeConsoleCommand(function(shovelImplement)
--- Position debug
CpUtil.infoImplement(shovelImplement, "-- Position debug --")
local spec = shovelImplement.spec_cpShovelPositions
if spec then
CpUtil.infoImplement(shovelImplement, " arm tool %s -> %s",
CpUtil.getName(spec.armVehicle), tostring(spec.armToolIx))
CpUtil.infoImplement(shovelImplement, " shovel tool %s -> %s",
CpUtil.getName(spec.shovelVehicle), tostring(spec.shovelToolIx))
local highDumpShovelIx = g_vehicleConfigurations:get(shovelImplement, "shovelMovingToolIx")
CpUtil.infoImplement(shovelImplement, " shovel high dump %s -> %s",
CpUtil.getName(shovelImplement), tostring(highDumpShovelIx))
end

CpUtil.infoImplement(shovelImplement, "-- Position debug --")
--- Shovel debug
local controller = ShovelController(shovelImplement.rootVehicle, shovelImplement, true)
controller:printShovelDebug()
controller:delete()
--- Cylindered debug here
CpUtil.infoImplement(shovelImplement, "-- Cylindered debug --")
cylinderedDepth = cylinderedDepth and tonumber(cylinderedDepth) or 0

local childVehicles = shovelImplement.rootVehicle:getChildVehicles()
for _, vehicle in ipairs(childVehicles) do
if vehicle.spec_cylindered then
for ix, tool in pairs(vehicle.spec_cylindered.movingTools) do
CpUtil.infoImplement(shovelImplement, " %s => ix: %d ",
CpUtil.getName(vehicle), ix)
if cylinderedDepth > 0 then
CpUtil.infoImplement(shovelImplement, " %s",
DebugUtil.debugTableToString(tool, " ", 0, cylinderedDepth))
end
CpUtil.infoImplement(shovelImplement, " %s => ix: %d finished",
CpUtil.getName(vehicle), ix)
end
end
end
CpUtil.infoImplement(shovelImplement, "-- Cylindered debug finished --")
end)
end

--------------------------------------------
--- Event Listener
--------------------------------------------
Expand Down Expand Up @@ -339,19 +390,23 @@ function CpShovelPositions:setShovelPosition(dt, shovelLimits, armLimits, isLoad
isDirty = ImplementUtil.moveMovingToolToRotation(self, highDumpShovelTool, dt,
highDumpShovelTool.invertAxis and highDumpShovelTool.rotMax or highDumpShovelTool.rotMin) or isDirty
end
else
for i, tool in pairs(self.spec_cylindered.movingTools) do
if tool.axis then
if isLoading or isUnloading then
--- Opens the shovel for loading and unloading
isDirty = ImplementUtil.moveMovingToolToRotation(self, tool, dt,
tool.invertAxis and tool.rotMin or tool.rotMax) or isDirty
else
--- Closes the shovel after loading
isDirty = ImplementUtil.moveMovingToolToRotation(self, tool, dt,
tool.invertAxis and tool.rotMax or tool.rotMin) or isDirty
else
local shovelData = ImplementUtil.getShovelNode(self)
if shovelData.movingToolActivation then
--- The shovel has a moving tool for grabbing.
for i, tool in pairs(self.spec_cylindered.movingTools) do
if tool.axis then
if isLoading or isUnloading then
--- Opens the shovel for loading and unloading
isDirty = ImplementUtil.moveMovingToolToRotation(self, tool, dt,
tool.invertAxis and tool.rotMin or tool.rotMax) or isDirty
else
--- Closes the shovel after loading
isDirty = ImplementUtil.moveMovingToolToRotation(self, tool, dt,
tool.invertAxis and tool.rotMax or tool.rotMin) or isDirty
end
break
end
break
end
end
end
Expand Down

0 comments on commit 2df69c3

Please sign in to comment.