fix: kørende traktor stoppes når den fjernes fra run / run slettes; stop logges (v1.11.1.0)
This commit is contained in:
@@ -79,7 +79,13 @@ function ADRunsController.createRun(name)
|
|||||||
return run
|
return run
|
||||||
end
|
end
|
||||||
|
|
||||||
function ADRunsController.deleteRun(runId)
|
function ADRunsController.deleteRun(runId, adEnv)
|
||||||
|
local run = ADRuns.getRun(ADRunsController.store, runId)
|
||||||
|
if run ~= nil and adEnv ~= nil then
|
||||||
|
for _, vehicleId in ipairs(run.vehicleIds) do
|
||||||
|
ADRunsController.stopIfRunning(ADRunsController.findVehicleById(adEnv, vehicleId), "run slettet")
|
||||||
|
end
|
||||||
|
end
|
||||||
ADRunsController.store = ADRuns.deleteRun(ADRunsController.store, runId)
|
ADRunsController.store = ADRuns.deleteRun(ADRunsController.store, runId)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -109,6 +115,7 @@ function ADRunsController.unassignVehicle(vehicle)
|
|||||||
local id = ADRunsController.getVehicleId(vehicle)
|
local id = ADRunsController.getVehicleId(vehicle)
|
||||||
if id ~= nil then
|
if id ~= nil then
|
||||||
ADRunsController.store = ADRuns.unassignVehicle(ADRunsController.store, id)
|
ADRunsController.store = ADRuns.unassignVehicle(ADRunsController.store, id)
|
||||||
|
ADRunsController.stopIfRunning(vehicle, "fjernet fra run")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -429,6 +436,26 @@ function ADRunsController.startRun(adEnv, runId)
|
|||||||
return results
|
return results
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Som ADInputManager:input_start_stop: loops nulstilles og AD stoppes.
|
||||||
|
local function stopVehicle(vehicle)
|
||||||
|
local stateModule = vehicle.ad.stateModule
|
||||||
|
if stateModule.setLoopsDone ~= nil then
|
||||||
|
stateModule:setLoopsDone(0)
|
||||||
|
end
|
||||||
|
vehicle:stopAutoDrive()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- En kørende traktor der fjernes fra sit run (eller hvis run slettes) kører run'ets job —
|
||||||
|
-- den stoppes, så den ikke fortsætter uden run. Returnerer true hvis den blev stoppet.
|
||||||
|
function ADRunsController.stopIfRunning(vehicle, reason)
|
||||||
|
if vehicle == nil or vehicle.ad == nil or not isVehicleActive(vehicle) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
stopVehicle(vehicle)
|
||||||
|
Logging.info(ADRunsController.LOG_PREFIX .. "'%s' stoppet (%s)", tostring(vehicle:getName()), tostring(reason))
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
function ADRunsController.stopRun(adEnv, runId)
|
function ADRunsController.stopRun(adEnv, runId)
|
||||||
local run = ADRuns.getRun(ADRunsController.store, runId)
|
local run = ADRuns.getRun(ADRunsController.store, runId)
|
||||||
local stopped = 0
|
local stopped = 0
|
||||||
@@ -439,8 +466,9 @@ function ADRunsController.stopRun(adEnv, runId)
|
|||||||
for _, vehicleId in ipairs(run.vehicleIds) do
|
for _, vehicleId in ipairs(run.vehicleIds) do
|
||||||
local vehicle = vehiclesById[vehicleId]
|
local vehicle = vehiclesById[vehicleId]
|
||||||
if vehicle ~= nil and isVehicleActive(vehicle) then
|
if vehicle ~= nil and isVehicleActive(vehicle) then
|
||||||
vehicle:stopAutoDrive()
|
stopVehicle(vehicle)
|
||||||
stopped = stopped + 1
|
stopped = stopped + 1
|
||||||
|
Logging.info(ADRunsController.LOG_PREFIX .. "run '%s': '%s' stoppet", tostring(run.name), tostring(vehicle:getName()))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return stopped
|
return stopped
|
||||||
|
|||||||
@@ -819,7 +819,7 @@ function SmartPickupFrame:onDeleteResult(yes)
|
|||||||
self:safe(function(frame)
|
self:safe(function(frame)
|
||||||
local run = frame:getRun()
|
local run = frame:getRun()
|
||||||
if yes and run ~= nil then
|
if yes and run ~= nil then
|
||||||
ADRunsController.deleteRun(run.id)
|
ADRunsController.deleteRun(run.id, frame.getAdEnv())
|
||||||
frame.selectedRunId = nil
|
frame.selectedRunId = nil
|
||||||
frame:requestRebuild()
|
frame:requestRebuild()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
<modDesc descVersion="107">
|
<modDesc descVersion="107">
|
||||||
<author>masterdraco</author>
|
<author>masterdraco</author>
|
||||||
<version>1.11.0.0</version>
|
<version>1.11.1.0</version>
|
||||||
<title>
|
<title>
|
||||||
<en>AD Smart Pickup</en>
|
<en>AD Smart Pickup</en>
|
||||||
</title>
|
</title>
|
||||||
|
|||||||
@@ -375,5 +375,21 @@ check("C16 validering ok med flere mål", ADRunsController.validateVehicle(adEnv
|
|||||||
ADRunsController.updateRun(multi.id, {targetWayPointIds = {4242}})
|
ADRunsController.updateRun(multi.id, {targetWayPointIds = {4242}})
|
||||||
check("C16 kun ukendte mål -> noTarget", ADRunsController.validateVehicle(adEnv, ADRuns.getRun(ADRunsController.store, multi.id), multiVehicle).reason, "noTarget")
|
check("C16 kun ukendte mål -> noTarget", ADRunsController.validateVehicle(adEnv, ADRuns.getRun(ADRunsController.store, multi.id), multiVehicle).reason, "noTarget")
|
||||||
|
|
||||||
|
-- C17: kørende traktor der fjernes fra run stoppes; slettes run, stoppes dets traktorer; Stop logger
|
||||||
|
buildWorld()
|
||||||
|
local runVehicle = makeVehicle("vehicleR", "Kørende", {STRAW, TMR}, 1000000, 100, 0)
|
||||||
|
local stopRun = ADRunsController.createRun("Stop-test")
|
||||||
|
ADRunsController.updateRun(stopRun.id, {targetWayPointId = 94})
|
||||||
|
ADRunsController.assignVehicle(stopRun.id, runVehicle)
|
||||||
|
ADRunsController.startRun(adEnv, stopRun.id)
|
||||||
|
check("C17 kører", runVehicle.started, 1)
|
||||||
|
ADRunsController.unassignVehicle(runVehicle)
|
||||||
|
check("C17 fjernet fra run -> stoppet", runVehicle.stopped, 1)
|
||||||
|
ADRunsController.assignVehicle(stopRun.id, runVehicle)
|
||||||
|
ADRunsController.startRun(adEnv, stopRun.id)
|
||||||
|
ADRunsController.deleteRun(stopRun.id, adEnv)
|
||||||
|
check("C17 run slettet -> stoppet", runVehicle.stopped, 2)
|
||||||
|
check("C17 stop logget", logLines[#logLines]:find("stoppet", 1, true) ~= nil, true)
|
||||||
|
|
||||||
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
|
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
|
||||||
os.exit(failures == 0 and 0 or 1)
|
os.exit(failures == 0 and 0 or 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user