Repository navigation
配置化与模块化, 性能优化 ,功能扩展与用户体验 - #4547
Merged
Merged
Conversation
仿真循环中新增关节控制代码
donghaiwang
approved these changes
Dec 23, 2025
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.
修改概述:
修改的详细描述
使用@DataClass定义SimConfig类,集中管理所有可配置参数(如运动频率、相机参数、关节幅度),修改时无需改动核心逻辑。
将所有功能封装为HumanoidSimulator类,符合面向对象思想,便于复用和扩展(比如后续添加其他机器人模型)。
性能优化
关节 ID、控制 ID、qpos 索引只在初始化时计算一次,避免每次循环重复调用mj_name2id,提升运行效率。
使用time.perf_counter替代time.sleep,实现更精准的仿真步长控制,让仿真速度更稳定。
累计帧数并计算帧率,直观反映仿真性能。
功能扩展与用户体验
支持三种运动模式:正弦运动(sin)、随机运动(random)、静止(stop),可通过控制台指令切换。
添加关节控制信号的平滑过渡(平滑系数smooth_factor),避免动作突变,机器人运动更自然。
打印信息中添加帧率显示,便于监控仿真性能。
操作提示更详细,支持的指令更多,用户体验更好。
经过了什么样的测试?
运行效果
动图、视频、截图等
2025-12-21.214707.mp4
2025-12-21.214707.mp4