Conversation
…clear nav history on STARTED
Walkthrough此更新引入了面向竞赛机器人的完整决策系统。添加了新的ROS地图配置、扩展的黑板状态定义、有限状态机端点、多个游戏意图和任务模块,用于实现路线导航、资源管理和防守行为。 Changes
Sequence Diagram(s)sequenceDiagram
participant Robot as 机器人
participant FSM as train-decision<br/>FSM端点
participant Intent as Intent<br/>(启动/持续巡航)
participant Task as Task<br/>(导航/交叉)
participant Blackboard as 黑板<br/>(状态/条件)
Robot->>FSM: on_init(配置FSM规则)
FSM->>Blackboard: 初始化rule/game/meta
activate FSM
Robot->>FSM: 发送start请求
FSM->>FSM: 状态→start_cruise
loop 游戏阶段STARTED
FSM->>Intent: 创建StartCruiseIntent
activate Intent
Intent->>Task: run(navigate_to_fluctuant_begin)
activate Task
Task->>Task: 选择目标点
Task->>Blackboard: 检查condition.near()
Task-->>Intent: 返回success/fail
deactivate Task
alt 成功
Intent->>FSM: advance()阶段
Note over Intent: crossing_fluctuant阶段
Intent->>Task: run(cross_fluctuant_road)
activate Task
Task->>Blackboard: 更新chassis mode
Task->>Blackboard: 检查导航完成
Task-->>Intent: 返回true
deactivate Task
Intent-->>FSM: 返回true(意图完成)
deactivate Intent
FSM->>FSM: 状态→keep_cruise
else 失败或低血量
FSM->>FSM: 状态→escape
FSM->>Intent: 创建escape_to_home
activate Intent
Intent->>Task: 执行选定路由
Task-->>Intent: 返回导航结果
Intent-->>FSM: 返回success/fail
deactivate Intent
FSM->>FSM: 状态→recover
end
Robot->>FSM: on_tick(更新状态)
FSM->>Blackboard: 轮询health_ready/bullet_ready
end
deactivate FSM
Robot->>FSM: on_exit(清理)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 9
🧹 Nitpick comments (3)
src/lua/blackboard.lua (1)
19-19:user.mode与rule.mode名字重叠,语义不同
user.mode(动态当前底盘/运行模式) 与rule.mode = "movement"(静态规则配置) 共用mode字段名,调用点容易混淆。建议把rule.mode重命名为更明确的名称(例如default_chassis_mode或decision_mode)以表达其作为静态默认/规则配置的含义。Also applies to: 65-65
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lua/blackboard.lua` at line 19, Rename the ambiguous rule field rule.mode to a clearer name (e.g., rule.default_chassis_mode or rule.decision_mode) so it no longer collides semantically with user.mode; update the field declaration in blackboard.lua and change every reference/condition that compares or assigns rule.mode (for example checks for "movement") to the new name (including any rule parsing, config loading, and tests), and optionally add a small compatibility mapping that reads the old rule.mode if present and assigns it to the new property to avoid breaking existing configs.src/lua/task/supply/supply-health.lua (1)
30-32: 建议为等待循环增加可选超时当前
while not condition.health_ready()没有任何兜底,一旦user.health因数据流中断或受伤而长期低于阈值,FSM 会被该协程无限阻塞。建议参考task/navigate-to-point.lua的模式,使用request:wait_until { monitor=..., timeout=... },并在超时返回false,让上层 FSM 决策是否继续等待或切换状态。♻️ 参考实现
- while not condition.health_ready() do - request:sleep(POLL_INTERVAL) - end + local is_timeout = request:wait_until { + monitor = condition.health_ready, + timeout = options and options.timeout or math.huge, + } + if is_timeout then + action:warn("supply-health: 等待补血超时") + return false + end🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lua/task/supply/supply-health.lua` around lines 30 - 32, 当前的等待循环 while not condition.health_ready() ... request:sleep(POLL_INTERVAL) 可能导致无限阻塞,应改为使用 request:wait_until 模式并支持可配置超时;在 supply-health.lua 中替换该循环为 request:wait_until { monitor=function() return condition.health_ready() end, timeout=TIMEOUT_MS }(参考 task/navigate-to-point.lua 的实现),并在 wait_until 返回 false 时让上层 FSM 收到失败/超时信号以决定是否重试或切换状态;确保暴露或使用合适的超时常量(例如 POLL_TIMEOUT 或从配置读取)。src/lua/task/guard-home/occupy-fortress.lua (1)
11-16: 可简化为单行三元表达式- local rule = blackboard.rule - local fortress - if ours_zone then - fortress = rule.fortress.ours - else - fortress = rule.fortress.them - end + local rule = blackboard.rule + local fortress = ours_zone and rule.fortress.ours or rule.fortress.them🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lua/task/guard-home/occupy-fortress.lua` around lines 11 - 16, 将多行的条件赋值简化为单行表达式:用 ours_zone 的短路逻辑替代 if/else,将 fortress 直接赋为基于 ours_zone 的结果(选择 rule.fortress.ours 或 rule.fortress.them),保留同样的行为并且仍然处理 falsy 值风险,定位到占位变量 fortress、条件变量 ours_zone 以及候选值 rule.fortress.ours 和 rule.fortress.them 并替换原有 if/else 代码块为单行表达式。
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/lua/blackboard.lua`:
- Line 37: Rename the misspelled blackboard fields and all their references:
change field our_dart_nmber_of_hits to our_dart_number_of_hits and update any
usages (e.g. result.game.our_dart_nmber_of_hits) to
result.game.our_dart_number_of_hits; change central_highland_gain_pount to
central_highland_gain_point; and change oupost_survival to outpost_survival
(note this predicate is used by FSM/tasks so update all dependent condition
checks). Ensure you update both the declarations in blackboard.lua and every
place that reads/writes these symbols to keep names consistent across the
decision tree/FSM.
In `@src/lua/endpoint/train-decision.lua`:
- Around line 64-77: The coordinates in rule.resupply_zone.ours,
rule.fluctuant_road_begin.ours, rule.fluctuant_road_final.ours,
rule.one_step_begin.ours, rule.one_step_final.ours,
rule.central_highland_near_fluctuant_road.ours,
rule.central_highland_near_doghole.ours and their corresponding .them entries
are all placeholders (0.0,0.0) which collapses all waypoints to the origin;
replace these with the real map coordinates for the intended training map or, if
this endpoint is only for internal testing, explicitly mark it as such (rename
the endpoint to indicate test/internal and add a README note) or refactor the
values into a map-specific config table (e.g., a train_map Lua table) and load
the correct coordinate set in train-decision.lua so runtime behavior uses proper
distinct waypoints instead of zeros.
- Around line 281-291: The success branch in the FSM callback for
KeepCruiseIntent currently just returns when job.done and job.success are true,
which can make the FSM permanently stuck; update the handler (the block around
job.done/job.success checks inside KeepCruiseIntent:run / the anonymous
callback) so that when job.success is true it either treats success as an
exceptional case (e.g., log and transition/stop) or, if the intent should
continue cruising, call run_current_intent_job() just like the failure branch
does; ensure you modify the branch that now does only "return" to instead invoke
run_current_intent_job() (or perform the intended state transition) and keep the
action:warn/ logging consistent.
In `@src/lua/intent/escape-to-home.lua`:
- Around line 31-33: The unknown-route branch currently only calls
action:warn("unknown escape route: " .. tostring(route)) and then the function
continues to call navigate_to_point(resupply_zone, ...) which can cause a
partial retreat; update the branch in escape-to-home.lua (the block handling
route not in "direct" | "onestep" | "fluctuant_road") to stop execution and
surface the error by returning false (or asserting) immediately after logging
the warning so callers (FSM) can handle it; ensure the code references the same
action:warn(...) location and that navigate_to_point(resupply_zone, ...) is not
executed when route is invalid.
In `@src/lua/task/cruise-in-central-highland/cruise-in-central-highlands.lua`:
- Around line 66-69: 当前的 while true do ... end 结构只在导航失败时通过 return false 退出,导致末尾的
return true 永远不可达;修复方法是:在导航成功的分支里用 break 跳出 while 循环(或直接在成功处 return
true),从而让函数在循环外执行末尾的 return true;在修复时定位并修改循环体内处理成功的分支(涉及 while true do、return
false 和末尾的 return true)以确保成功路径能终止循环并返回 true。
- Around line 13-15: The LuaDoc block has inconsistent indentation: the first
line starting with `--- 中央高地巡航:在“靠近起伏路侧”与“靠近狗洞侧”之间按固定周期切换导航目标。` has one extra
tab compared to the following lines (`--- `@param` ours_zone boolean` and `---
`@param` switch_interval number 切换周期(秒)`), so align the leading whitespace of that
first `---` to match the other `---` lines so the entire comment forms a single
LuaDoc group (edit the LuaDoc block around this comment in
cruise-in-central-highlands.lua).
In `@src/lua/task/forward-press/forward-press-in-one-step.lua`:
- Line 14: The assignment to ok uses a global variable; change the statement
assigning the result of navigate_to_point(enemy_fluctuant_road_final, {...}) so
that ok is declared local (e.g., add the local keyword before ok) to avoid
writing to _G.ok and prevent cross-coroutine interference in scheduler; update
the assignment in the forward-press-in-one-step.lua where navigate_to_point is
called.
In `@src/lua/task/forward-press/forward-press-in-two-step.lua`:
- Around line 50-53: The trailing "return true" after the outer "while true do
... end" is unreachable because the loop only exits via "return false" on
navigation failure; remove the unreachable "return true" statement from
forward-press-in-two-step.lua (inside the function containing the outer while
loop) so the function's control flow is not misleading—no other changes needed
unless you intend to add a reachable success return inside the loop.
- Around line 22-37: The variable ok is assigned without local (ok =
navigate_to_point(...)) which pollutes the global namespace; change the
assignment to a local variable (local ok) where used in this task loop (around
the while true block that sets phase_start and calls action:update_chassis_mode
and navigate_to_point) so the result of navigate_to_point is local to this
function/block and will not clash with other modules like
cruise-in-central-highlands.lua.
---
Nitpick comments:
In `@src/lua/blackboard.lua`:
- Line 19: Rename the ambiguous rule field rule.mode to a clearer name (e.g.,
rule.default_chassis_mode or rule.decision_mode) so it no longer collides
semantically with user.mode; update the field declaration in blackboard.lua and
change every reference/condition that compares or assigns rule.mode (for example
checks for "movement") to the new name (including any rule parsing, config
loading, and tests), and optionally add a small compatibility mapping that reads
the old rule.mode if present and assigns it to the new property to avoid
breaking existing configs.
In `@src/lua/task/guard-home/occupy-fortress.lua`:
- Around line 11-16: 将多行的条件赋值简化为单行表达式:用 ours_zone 的短路逻辑替代 if/else,将 fortress
直接赋为基于 ours_zone 的结果(选择 rule.fortress.ours 或 rule.fortress.them),保留同样的行为并且仍然处理
falsy 值风险,定位到占位变量 fortress、条件变量 ours_zone 以及候选值 rule.fortress.ours 和
rule.fortress.them 并替换原有 if/else 代码块为单行表达式。
In `@src/lua/task/supply/supply-health.lua`:
- Around line 30-32: 当前的等待循环 while not condition.health_ready() ...
request:sleep(POLL_INTERVAL) 可能导致无限阻塞,应改为使用 request:wait_until 模式并支持可配置超时;在
supply-health.lua 中替换该循环为 request:wait_until { monitor=function() return
condition.health_ready() end, timeout=TIMEOUT_MS }(参考 task/navigate-to-point.lua
的实现),并在 wait_until 返回 false 时让上层 FSM 收到失败/超时信号以决定是否重试或切换状态;确保暴露或使用合适的超时常量(例如
POLL_TIMEOUT 或从配置读取)。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cbe8c9be-db70-48b8-aae9-4102ae6f4821
⛔ Files ignored due to path filters (1)
maps/train_map.pngis excluded by!**/*.png
📒 Files selected for processing (23)
maps/train_map.yamlsrc/lua/api.luasrc/lua/blackboard.luasrc/lua/endpoint/test.luasrc/lua/endpoint/train-decision.luasrc/lua/intent/escape-to-home.luasrc/lua/intent/guard-home.luasrc/lua/intent/keep-cruise.luasrc/lua/intent/start-cruise.luasrc/lua/task/cross-fluctuant/cross-fluctuant-road.luasrc/lua/task/cross-fluctuant/navigate-to-fluctuant-begin.luasrc/lua/task/cross-road/cross-road-zone.luasrc/lua/task/crossing-road-zone.luasrc/lua/task/cruise-in-central-highland/cruise-in-central-highlands.luasrc/lua/task/forward-press/forward-press-in-one-step.luasrc/lua/task/forward-press/forward-press-in-two-step.luasrc/lua/task/guard-home/cruise-in-front-of-base.luasrc/lua/task/guard-home/occupy-fortress.luasrc/lua/task/navigate-to-point.luasrc/lua/task/one-step/go-down-onestep.luasrc/lua/task/supply/supply-ammunition.luasrc/lua/task/supply/supply-health.luasrc/lua/task/switch-mode.lua
💤 Files with no reviewable changes (1)
- src/lua/task/crossing-road-zone.lua
| gold_coin = 0, -- 队伍剩余金币数 | ||
| exchangeable_ammunition_quantity = 0, -- 队伍 17mm 允许发弹量的剩余可兑换数 | ||
|
|
||
| our_dart_nmber_of_hits = 0, -- 己方飞镖击中次数 |
There was a problem hiding this comment.
字段/谓词存在多处拼写错误,建议统一修正
下列拼写错误会随 blackboard 暴露给整个决策树/FSM,后续修正会成为破坏性变更,建议在合并前一并处理:
- 第 37 行:
our_dart_nmber_of_hits→our_dart_number_of_hits - 第 109 行:
central_highland_gain_pount→central_highland_gain_point - 第 150 行:
oupost_survival→outpost_survival - 第 155 行:
result.game.our_dart_nmber_of_hits(同步修正字段引用)
注意第 150 行的 oupost_survival 是新增的 condition 谓词,已经被 FSM/任务侧依赖,越晚改影响面越大。
🔧 建议的修正 diff
- our_dart_nmber_of_hits = 0, -- 己方飞镖击中次数
+ our_dart_number_of_hits = 0, -- 己方飞镖击中次数- central_highland_gain_pount = PointPair { { 0, 0 }, { 0, 0 } }, -- 中央高地增益点
+ central_highland_gain_point = PointPair { { 0, 0 }, { 0, 0 } }, -- 中央高地增益点- oupost_survival = function ()
- return result.game.outpost_health > 0
- end,
+ outpost_survival = function()
+ return result.game.outpost_health > 0
+ end,
- dart_hit_first_time = function ()
- return result.game.our_dart_nmber_of_hits == 1
- end,
+ dart_hit_first_time = function()
+ return result.game.our_dart_number_of_hits == 1
+ end,Also applies to: 109-109, 150-156
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lua/blackboard.lua` at line 37, Rename the misspelled blackboard fields
and all their references: change field our_dart_nmber_of_hits to
our_dart_number_of_hits and update any usages (e.g.
result.game.our_dart_nmber_of_hits) to result.game.our_dart_number_of_hits;
change central_highland_gain_pount to central_highland_gain_point; and change
oupost_survival to outpost_survival (note this predicate is used by FSM/tasks so
update all dependent condition checks). Ensure you update both the declarations
in blackboard.lua and every place that reads/writes these symbols to keep names
consistent across the decision tree/FSM.
| -- Ours side sample points | ||
| -- 暂时全为0 | ||
| rule.resupply_zone.ours = { x = 0.0, y = 0.0 } --家 | ||
| rule.fluctuant_road_begin.ours = { x = 0.0, y = 0.0 } --起伏路段起点 | ||
| rule.fluctuant_road_final.ours = { x = 0.0, y = 0.0 } --起伏路段终点 | ||
| rule.one_step_begin.ours = { x = 0.0, y = 0.0 } --一级台阶高点(先随便标个回家路上的点) | ||
| rule.one_step_final.ours = { x = 0.0, y = 0.0 } --一级台阶低点(先随便标个回家路上的点) | ||
| rule.central_highland_near_fluctuant_road.ours = { x = 0.0, y = 0.0 } --高地靠近起伏路 | ||
| rule.central_highland_near_doghole.ours = { x = 0.0, y = 0.0 } --高地靠近狗洞 | ||
|
|
||
| rule.central_highland_near_fluctuant_road.them = { x = 0.0, y = 0.0 } --高地靠近起伏路 | ||
| rule.central_highland_near_doghole.them = { x = 0.0, y = 0.0 } --高地靠近狗洞 | ||
| rule.fluctuant_road_final.them = { x = 0.0, y = 0.0 } --起伏路段终点 | ||
| end |
There was a problem hiding this comment.
所有规则坐标点均为占位 (0.0, 0.0)。
resupply_zone / fluctuant_road_* / one_step_* / central_highland_* 全部置零,注释也明确标注“暂时全为0”。在真实赛场中,这会导致所有路径节点重合到原点,巡航/逃跑导航行为不可用。请在合并到 main 之前替换为实际地图坐标,或显式将该 endpoint 限定为内部测试用途(例如改名/加 README 警示)。
如果你希望,我可以帮你把这部分坐标抽取到独立的配置文件(例如按 train_map 区分的 lua 表),便于未来按地图切换。需要的话告诉我即可。
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lua/endpoint/train-decision.lua` around lines 64 - 77, The coordinates in
rule.resupply_zone.ours, rule.fluctuant_road_begin.ours,
rule.fluctuant_road_final.ours, rule.one_step_begin.ours,
rule.one_step_final.ours, rule.central_highland_near_fluctuant_road.ours,
rule.central_highland_near_doghole.ours and their corresponding .them entries
are all placeholders (0.0,0.0) which collapses all waypoints to the origin;
replace these with the real map coordinates for the intended training map or, if
this endpoint is only for internal testing, explicitly mark it as such (rename
the endpoint to indicate test/internal and add a README note) or refactor the
values into a map-specific config table (e.g., a train_map Lua table) and load
the correct coordinate set in train-decision.lua so runtime behavior uses proper
distinct waypoints instead of zeros.
| if not job.done then | ||
| return | ||
| end | ||
|
|
||
| if job.success then | ||
| return | ||
| end | ||
|
|
||
| action:warn("fsm(keep_cruise): 导航失败,重试当前状态") | ||
| run_current_intent_job() | ||
| end, |
There was a problem hiding this comment.
keep_cruise 成功分支可能让 FSM 永久“卡住”。
当 KeepCruiseIntent:run 内部调用的 cruise_in_central_highlands 正常返回(job.success 为真)后,事件处理只是 return。下一帧 job.done 仍为 true、job.success 仍为 true,依然 return,巡航任务再也不会被重新调度。除非依赖低血量/弹药触发 escape,否则机器人将一直停在原地。
请确认期望语义:
- 若
cruise_in_central_highlands应当持续循环、永不正常返回 → 那么“成功返回”就是异常情况,应该重启或转移状态; - 若希望成功后继续巡航 → 成功分支也应调用
run_current_intent_job(),类似失败分支。
♻️ 参考修复(成功后继续巡航)
if job.success then
+ run_current_intent_job()
return
end
action:warn("fsm(keep_cruise): 导航失败,重试当前状态")
run_current_intent_job()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lua/endpoint/train-decision.lua` around lines 281 - 291, The success
branch in the FSM callback for KeepCruiseIntent currently just returns when
job.done and job.success are true, which can make the FSM permanently stuck;
update the handler (the block around job.done/job.success checks inside
KeepCruiseIntent:run / the anonymous callback) so that when job.success is true
it either treats success as an exceptional case (e.g., log and transition/stop)
or, if the intent should continue cruising, call run_current_intent_job() just
like the failure branch does; ensure you modify the branch that now does only
"return" to instead invoke run_current_intent_job() (or perform the intended
state transition) and keep the action:warn/ logging consistent.
| else | ||
| action:warn("unknown escape route: " .. tostring(route)) | ||
| end |
There was a problem hiding this comment.
未知 route 不应继续向下执行。
当 route 不属于 "direct" | "onestep" | "fluctuant_road" 时,目前只是 warn 一行就继续调用 navigate_to_point(resupply_zone, ...)。考虑到上层 FSM 会按返回值决定状态切换,建议直接返回 false(或断言)以暴露调用方传参错误,避免静默执行半套撤退动作。
🔧 建议修复
elseif route == "direct" then
action:info("escape-to-home: 走直接回家路线")
else
action:warn("unknown escape route: " .. tostring(route))
+ return false
end📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| else | |
| action:warn("unknown escape route: " .. tostring(route)) | |
| end | |
| else | |
| action:warn("unknown escape route: " .. tostring(route)) | |
| return false | |
| end |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lua/intent/escape-to-home.lua` around lines 31 - 33, The unknown-route
branch currently only calls action:warn("unknown escape route: " ..
tostring(route)) and then the function continues to call
navigate_to_point(resupply_zone, ...) which can cause a partial retreat; update
the branch in escape-to-home.lua (the block handling route not in "direct" |
"onestep" | "fluctuant_road") to stop execution and surface the error by
returning false (or asserting) immediately after logging the warning so callers
(FSM) can handle it; ensure the code references the same action:warn(...)
location and that navigate_to_point(resupply_zone, ...) is not executed when
route is invalid.
| --- 中央高地巡航:在“靠近起伏路侧”与“靠近狗洞侧”之间按固定周期切换导航目标。 | ||
| --- @param ours_zone boolean | ||
| --- @param switch_interval number 切换周期(秒) |
There was a problem hiding this comment.
LuaDoc 注释缩进异常。
第 13 行的 --- 注释比第 14、15 行多了一个制表符的前导缩进,导致 LuaDoc/LSP 在解析此函数注释块时可能不把第 13 行视作同一注释组(注解会从第 14 行开始)。请与下一行的缩进保持一致。
🔧 建议修复
- --- 中央高地巡航:在“靠近起伏路侧”与“靠近狗洞侧”之间按固定周期切换导航目标。
+--- 中央高地巡航:在"靠近起伏路侧"与"靠近狗洞侧"之间按固定周期切换导航目标。
--- `@param` ours_zone boolean
--- `@param` switch_interval number 切换周期(秒)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| --- 中央高地巡航:在“靠近起伏路侧”与“靠近狗洞侧”之间按固定周期切换导航目标。 | |
| --- @param ours_zone boolean | |
| --- @param switch_interval number 切换周期(秒) | |
| --- 中央高地巡航:在"靠近起伏路侧"与"靠近狗洞侧"之间按固定周期切换导航目标。 | |
| --- `@param` ours_zone boolean | |
| --- `@param` switch_interval number 切换周期(秒) |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lua/task/cruise-in-central-highland/cruise-in-central-highlands.lua`
around lines 13 - 15, The LuaDoc block has inconsistent indentation: the first
line starting with `--- 中央高地巡航:在“靠近起伏路侧”与“靠近狗洞侧”之间按固定周期切换导航目标。` has one extra
tab compared to the following lines (`--- `@param` ours_zone boolean` and `---
`@param` switch_interval number 切换周期(秒)`), so align the leading whitespace of that
first `---` to match the other `---` lines so the entire comment forms a single
LuaDoc group (edit the LuaDoc block around this comment in
cruise-in-central-highlands.lua).
| end | ||
|
|
||
| return true | ||
| end |
There was a problem hiding this comment.
return true 不可达。
外层是 while true do ... end,仅在导航失败时通过 return false 退出,第 68 行的 return true 永远不会被执行。
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lua/task/cruise-in-central-highland/cruise-in-central-highlands.lua`
around lines 66 - 69, 当前的 while true do ... end 结构只在导航失败时通过 return false
退出,导致末尾的 return true 永远不可达;修复方法是:在导航成功的分支里用 break 跳出 while 循环(或直接在成功处 return
true),从而让函数在循环外执行末尾的 return true;在修复时定位并修改循环体内处理成功的分支(涉及 while true do、return
false 和末尾的 return true)以确保成功路径能终止循环并返回 true。
| local enemy_fluctuant_road_final = rule.fluctuant_road_final.them | ||
|
|
||
| action:update_chassis_mode("SPIN") | ||
| ok = navigate_to_point(enemy_fluctuant_road_final, { |
There was a problem hiding this comment.
缺少 local,ok 被泄漏成全局变量
ok = navigate_to_point(...) 没有 local 声明,会写入 _G.ok。在 scheduler 多协程环境下,多个任务并发使用同名变量将相互覆盖,且全局变量污染会让后续调试困难。请加上 local。
🐛 修正
- ok = navigate_to_point(enemy_fluctuant_road_final, {
+ local ok = navigate_to_point(enemy_fluctuant_road_final, {
tolerance = 0.1,
timeout = 10,
})🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lua/task/forward-press/forward-press-in-one-step.lua` at line 14, The
assignment to ok uses a global variable; change the statement assigning the
result of navigate_to_point(enemy_fluctuant_road_final, {...}) so that ok is
declared local (e.g., add the local keyword before ok) to avoid writing to _G.ok
and prevent cross-coroutine interference in scheduler; update the assignment in
the forward-press-in-one-step.lua where navigate_to_point is called.
| while true do | ||
| local phase_start = clock:now() | ||
| action:update_chassis_mode("SPIN") | ||
| ok = navigate_to_point(target, { | ||
| tolerance = 0.1, | ||
| timeout = navigation_timeout, | ||
| }) | ||
| if not ok then | ||
| action:warn(string.format( | ||
| "forward-press-in-two-step: 导航到巡航点失败 (x=%.2f, y=%.2f, timeout=%.2fs)", | ||
| target.x, | ||
| target.y, | ||
| navigation_timeout | ||
| )) | ||
| return false | ||
| end |
There was a problem hiding this comment.
ok 缺少 local,会污染全局变量。
第 25 行 ok = navigate_to_point(...) 没有用 local 声明,导致每次调用本任务都会向全局表写入 ok,不仅与 Lua 风格不符,也会与其它模块(例如同 PR 中 cruise-in-central-highlands.lua 第 40 行的 local ok)形成隐式耦合,调试时极易出现难以复现的并发可见性问题。
🔧 建议修复
while true do
local phase_start = clock:now()
action:update_chassis_mode("SPIN")
- ok = navigate_to_point(target, {
+ local ok = navigate_to_point(target, {
tolerance = 0.1,
timeout = navigation_timeout,
})🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lua/task/forward-press/forward-press-in-two-step.lua` around lines 22 -
37, The variable ok is assigned without local (ok = navigate_to_point(...))
which pollutes the global namespace; change the assignment to a local variable
(local ok) where used in this task loop (around the while true block that sets
phase_start and calls action:update_chassis_mode and navigate_to_point) so the
result of navigate_to_point is local to this function/block and will not clash
with other modules like cruise-in-central-highlands.lua.
| end | ||
|
|
||
| return true | ||
| end |
There was a problem hiding this comment.
return true 不可达。
外层是 while true do ... end,循环只能通过 return false(导航失败)退出,第 52 行的 return true 永远不会被执行,可删除以避免误导后续维护者。
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/lua/task/forward-press/forward-press-in-two-step.lua` around lines 50 -
53, The trailing "return true" after the outer "while true do ... end" is
unreachable because the loop only exits via "return false" on navigation
failure; remove the unreachable "return true" statement from
forward-press-in-two-step.lua (inside the function containing the outer while
loop) so the function's control flow is not misleading—no other changes needed
unless you intend to add a reachable success return inside the loop.
拉取请求摘要:训练决策测试
概述
本PR实现了完整的训练决策系统,包括新的有限状态机(FSM)端点、多个意图模块和任务模块,以支持机器人的自主导航、巡航和应急策略。
主要改动
地图配置
train_map.png的占用栅格网络生成,配置分辨率为0.05米、三元模式、占用阈值0.65、空闲阈值0.196核心决策端点
黑板系统扩展
意图模块(新增)
src/lua/intent/start-cruise.lua(84行):双阶段开始巡航意图
src/lua/intent/keep-cruise.lua(44行):持续巡航意图,在中央高地之间交替导航
src/lua/intent/escape-to-home.lua(47行):应急逃离意图,支持多种策略
onestep:单步前进逃离fluctuant_road:穿过波动路段逃离direct:直接导航回补给区任务模块(新增)
通用导航:
巡航任务:
前进压制任务:
防守和补给:
其他任务:
代码清理
代码审查难度评估
改动统计