Repository navigation
feat(ground): 新增 drive_cycle_energy,把「工况能耗与续航」做成可离线复算的能量分解 - #1250
Merged
Merged
Conversation
Added a new section on energy consumption and range during driving cycles.
This was referenced Nov 11, 2026
# Conflicts: # docs/index.md # mkdocs.yml
xingwunian
approved these changes
Nov 11, 2026
xingwunian
left a comment
Contributor
There was a problem hiding this comment.
按贡献指南第 8 节本地核对过(git fetch origin pull/1250/head → 逐文件看 → 跑离线测试),没有阻断问题,可以合。
- 把
master(4c9b5e07,已含 #1246/#1249)合进本分支,冲突只在mkdocs.yml/docs/index.md - 本 PR 原来的导航 hunk 有两个问题:一是把 master 已有的「VRU 冲突风险图」删掉了;二是新增的那一行指向
./ground/ride_comfort_transmissibility.md(是 #1252 的模块,不是本 PR 的)。已改成保留 master 两条,本模块用./ground/drive_cycle_energy.md单独加一行 - 首页同样补上「工况能耗与续航核算」的链接
tests/test_drive_cycle_energy_local.py本地跑:通过 152 项,失败 0 项- 相对 master 的净变化 1349 行新增、0 行删除;
catkin_install_python三个脚本齐全,包内只依赖math
代码逻辑没动,只补了合并与导航。按贡献指南用 Squash and merge。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修改概述
新增
src/ground/drive_cycle_energy模块:把一段行驶工况拆成滚阻、风阻、制动、动能四份能量,给出百公里电耗与满电续航,并用「能量分解 / 回收上限 / 续航自洽 / 风阻上升」四条断言
把账算平。纯标准库实现,不需要 CARLA、不需要显示器,Ubuntu 18.04 + ROS Melodic 直接可跑。
配套新增
docs/ground/drive_cycle_energy.md文档页。修改的详细描述
1. 为什么需要这个包
src/ground/下的地面载具模块,纵向动力学已有braking_distance_check(停车距离)、ros_scenario_runner(场景断言),但没有一处把「跑完一段路到底用了多少电」算清楚:braking_distance_checkros_scenario_runnertire_slip_curve电动车的续航焦虑本质上就是这笔账没算清:同一段路,风阻与滚阻的占比完全不同,
到底是「开太快风阻大」还是「刹车太多」造成的浪费,需要拆开看。本模块给的就是这个拆解。
2. 模型
关键恒等式(第 1 条断言查的就是它):
其中
E_roll = m·g·c_rr·s、E_aero = ∫0.5ρCdA v³dt、ΔKE = ½m(v_end² − v_start²)。这条恒等式把「驱动力做过的功」拆成四份互不重叠的账,任何一项漏算都会立刻暴露。
3. 四条断言
E_drive的相对偏差 ≤ 2%E_regen / E_brake ≤ regen_limit(默认 1.0)range与battery / per_100km × 100一致第 2 条的默认上限是 1.0,不是 0.6:回收能量超过制动能量违反能量守恒,
这是物理边界而不是标定值。第 4 条用「至少 ×6」而不是「恰好 ×8」,是因为工况里
速度并非瞬时翻倍,留了积分带来的余量。
4. 默认数字
工况 8 段、60 s、512.5 m、最高 50 km/h:
5. 参数与话题
12 个参数由 launch 逐个
<arg>(带doc)+<rosparam command="load">+ 同名<param>三层落地:/vehicle/{mass,c_rr,cd,area,battery_kwh,regen_eff}、/check/{breakdown_tolerance,regen_limit}、/rate/publish_hz、三个话题名。三路 latched 话题:
/energy/report(std_msgs/String)、/energy/breakdown(Float64MultiArray,四份能量 + 四份占比)、
/energy/range(Float64MultiArray,百公里与续航)。6. 结构约定
与仓库里已有的 ground 模块保持一致:
config/+launch/main.launch+scripts/{main,*_core,*_node}.pytests/test_*_local.py+docs/ground/*.md,*_core.py不 import rospy(离线可测),*_node.py里_log()把消息 encode 成 byte str(规避 Melodic 的UnicodeEncodeError)。7. 自查修掉的三处
inertia_pos(只累计加速时的正功),导致E_drive ≠ 四项之和。改成带符号的ΔKE后偏差归零。per_100km除零抛异常,检查器直接退出。改成 try/except,把「续航自洽」判成 FAIL 并写明原因。
check()只支持数字,遇到字符串列表(断言名)会抛TypeError,补了分支。8. 没改动什么
没有修改任何既有模块、
mkdocs.yml和docs/index.md(索引与导航的改动单独提交)。docs/ground/drive_cycle_energy.md是本次新增的文件。测试
在 Ubuntu 18.04 + ROS Melodic(Python 2.7.17)的虚拟机里执行:
通过 152 项,失败 0 项。覆盖 11 组:
运行效果
默认参数:
输出
断言:4 通过 / 0 失败(共 4 条)、结论:PASSED。关掉回收(
vehicle_regen_eff:=0.0)续航从 355.3 km 掉到 271.8 km;把regen_limit收到 0.5则只有「回收上限」翻红。
图 1 离线测试通过 152 项

图 2 默认工况

结论:PASSED图 3

vehicle_regen_eff:=0.0:净消耗变大、续航 271.8 km,断言仍全过图 4

regen_limit:=0.5:翻「回收上限」图 5 终端 B 三条

rosparam get回显所使用具体的大模型声明
使用大模型辅助代码编写、测试编写与文档整理,提交内容由本人负责。