chore: pålæsnings-diagnose viser AD's porte pr. fyldenhed — 1.62.155

This commit is contained in:
2026-10-10 05:55:09 +02:00
parent 46ab43acd3
commit a2fee60349
3 changed files with 37 additions and 3 deletions
+35 -2
View File
@@ -50,7 +50,36 @@ local function inBox(trigger, trailer)
return false
end
local function describeTrailer(adEnv, trailer, fillType)
-- AD's egne porte for pålæsning ved triggeren (AutoDrive.getTriggerAndTrailerPairs + tryLoadingAtTrigger): pr. fyldenhed
-- understøtter/tillader varen, fri plads, varevalget matcher, vognen i triggerens liste, kildens niveau, trigger i gang.
local function adGates(adEnv, vehicle, trailer, trigger, fillType)
local autoDrive = adEnv.AutoDrive
local parts = {}
local farmId = vehicle.getActiveFarm ~= nil and vehicle:getActiveFarm() or nil
local sourceLevel = nil
if trigger.source ~= nil and trigger.source.getAllFillLevels ~= nil then
local ok, levels = pcall(trigger.source.getAllFillLevels, trigger.source, farmId)
if ok and type(levels) == "table" then sourceLevel = levels[fillType] end
end
table.insert(parts, string.format("kilde(%s)=%s", tostring(farmId), tostring(sourceLevel)))
table.insert(parts, "trigger.isLoading=" .. tostring(trigger.isLoading))
local selected = vehicle.ad.stateModule.getSelectedFillTypes ~= nil and vehicle.ad.stateModule:getSelectedFillTypes() or {}
for i = 1, #(trailer:getFillUnits() or {}) do
local supports = trailer:getFillUnitSupportsFillType(i, fillType)
local allows = trailer.getFillUnitAllowsFillType == nil or trailer:getFillUnitAllowsFillType(i, fillType)
local okM, match = pcall(autoDrive.fillTypesMatch, vehicle, trigger, trailer, selected, i)
local okL, inList = pcall(autoDrive.trailerIsInTriggerList, trailer, trigger, i)
table.insert(parts, string.format("enhed%d: understøtter=%s tillader=%s fri=%.0f varevalg=%s iListe=%s", i, tostring(supports), tostring(allows),
trailer:getFillUnitFreeCapacity(i) or -1, okM and tostring(match) or "fejl", okL and tostring(inList) or "fejl"))
end
local tm = vehicle.ad.trailerModule
if tm ~= nil then
table.insert(parts, string.format("AD: isLoading=%s trigger=%s", tostring(tm.isLoading), tostring(tm.trigger ~= nil)))
end
return table.concat(parts, " ")
end
local function describeTrailer(adEnv, trailer, fillType, vehicle)
local node = trailer.components ~= nil and trailer.components[1] ~= nil and trailer.components[1].node or trailer.rootNode
if node == nil then return nil end
local tx, _, tz = getWorldTranslation(node)
@@ -75,6 +104,10 @@ local function describeTrailer(adEnv, trailer, fillType)
inBox(nearestOk.trigger, trailer) and "i boksen" or "ikke i boksen"))
end
if nearestOk == nil then table.insert(parts, "INGEN AD-læssetrigger med varen") end
if nearestOk ~= nil and vehicle ~= nil and trailer.getFillUnits ~= nil then
local okG, gates = pcall(adGates, adEnv, vehicle, trailer, nearestOk.trigger, fillType)
table.insert(parts, "[" .. (okG and gates or ("fejl: " .. tostring(gates))) .. "]")
end
return string.format("'%s': %s", tostring(name), table.concat(parts, ", ")), nearestOk ~= nil and nearestOk.d or nil
end
@@ -85,7 +118,7 @@ local function report(adEnv, task)
local lines, distances = {}, {}
for _, trailer in ipairs(task.trailers or {}) do
if trailer.getFillUnits ~= nil and #trailer:getFillUnits() > 0 then
local ok, line, distance = pcall(describeTrailer, adEnv, trailer, fillType)
local ok, line, distance = pcall(describeTrailer, adEnv, trailer, fillType, vehicle)
if ok and line ~= nil then table.insert(lines, line) end
if ok and distance ~= nil then table.insert(distances, distance) end
end