Skip to content

Commit

Permalink
[fix] 修复agent move2最终位置设置
Browse files Browse the repository at this point in the history
[feat] watchdog允许指定回收类型
[doc] 更新watchdog文档
  • Loading branch information
huuhghhgyg committed Jul 1, 2024
1 parent ab2e6f8 commit c238882
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
12 changes: 6 additions & 6 deletions agent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function Agent()
local taskname, params = table.unpack(agent.tasksequence[1])
-- 参数验证
if agent.tasks[taskname] == nil then
print('[' .. agent.type .. agent.id .. '] 错误,没有找到任务:',taskname)
print('[' .. agent.type .. agent.id .. '] 错误,没有找到任务:', taskname)
print(debug.traceback())
os.exit()
end
Expand Down Expand Up @@ -141,7 +141,7 @@ function Agent()
print(debug.traceback('[' .. agent.type .. agent.id .. '] 错误,fn任务没有找到args参数'))
os.exit()
end

params.init = true
coroutine.queue(0, agent.execute, agent) -- 结束时间唤醒execute
end,
Expand All @@ -153,10 +153,10 @@ function Agent()

-- params = {t} 秒
agent.tasks.delay = {
init = function (params)
init = function(params)
-- 参数检查
if type(params[1]) ~= "number" then
print('[' .. agent.type .. agent.id .. '] 错误,delay任务的参数不为数字',params[1])
print('[' .. agent.type .. agent.id .. '] 错误,delay任务的参数不为数字', params[1])
print(debug.traceback())
os.exit()
end
Expand All @@ -165,7 +165,7 @@ function Agent()
params.dt = params[1]
coroutine.queue(params.dt, agent.execute, agent)
end,
execute = function (dt, params)
execute = function(dt, params)
if dt == params.dt then
agent:deltask() -- 删除任务
end
Expand Down Expand Up @@ -211,7 +211,7 @@ function Agent()

if math.abs(params.dt - dt) < agent.timeError then -- 如果时间误差小于agent.timeerror,任务结束
agent.pos = {params[1], params[2], params[3]} -- 更新位置
agent:setpos({table.unpack(agent.pos)})
agent:setpos(table.unpack(agent.pos)) -- 设置位置
agent:deltask() -- 删除任务
end
end
Expand Down
1 change: 1 addition & 0 deletions docs/watchdog.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ run_command --->|停止运行|stop
- `isImmediateStop`: 当所有组件都没有需要执行的任务时停止刷新。如果仿真事件不是紧接着的(如随机生成或导入事件),则建议关闭(设置为`false`)。
- `lasttime`: 上一次刷新的时间,用于计算刷新间隔。
- `runcommand`: 是否允许继续运行。是从`scene.render()`函数中获得的返回值,检测程序运行状态表侄,以及时停止运行。
- `recycleType`: 需要回收的Agent类型列表,默认为`{'agv'}`。当Agent的类型在列表中且Agent无任务时会被回收。可以通过`config`重新设置列表为空来取消回收
26 changes: 19 additions & 7 deletions watchdog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ function WatchDog(simv, ActionObjs, config)
}

-- 更新参数
if config ~= nil then
-- 立即停止参数
if config.isImmediateStop ~= nil then
watchdog.isImmediateStop = config.isImmediateStop
end
if config == nil then
config = {}
end

-- 立即停止参数
if config.isImmediateStop ~= nil then
watchdog.isImmediateStop = config.isImmediateStop
end
watchdog.recycleType = config.recycleType or {"agv"} -- 需要回收的对象类型

function watchdog.refresh(f)
if type(f) == 'function' then
Expand Down Expand Up @@ -86,12 +89,21 @@ function WatchDog(simv, ActionObjs, config)
print('===================================')
end

function inRecycleList(objTypeStr)
assert(type(objTypeStr) == "string", "输入的类型不是字符串")
for _, v in ipairs(watchdog.recycleType) do
if v == objTypeStr then
return true
end
end
end

-- 检测是否需要回收
function watchdog:scanRecycle()
for i = 1, #ActionObjs do
local obj = ActionObjs[i]

if obj.type == "agv" and #obj.tasksequence == 0 then
if inRecycleList(obj.type) and #obj.tasksequence == 0 then
watchdog:recycle(obj)
table.remove(ActionObjs, i)
break -- 假设每次同时只能到达一个,因此可以中止
Expand All @@ -101,7 +113,7 @@ function WatchDog(simv, ActionObjs, config)

-- 回收某个对象
function watchdog:recycle(obj)
if obj.type == "agv" then
if inRecycleList(obj.type) then
if obj.container ~= nil then
obj.container:delete()
end
Expand Down

0 comments on commit c238882

Please sign in to comment.