Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d86df50
我的选题
mengdeqi12 Sep 16, 2025
76fa610
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 16, 2025
4810d2d
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 19, 2025
3184469
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 21, 2025
d847f22
添加我的环境配置
mengdeqi12 Sep 22, 2025
cb82bc4
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 22, 2025
7bf132b
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 22, 2025
46ecebc
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 23, 2025
610f122
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 23, 2025
0d5ed18
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 24, 2025
64291c7
移除.idea文件并更新.gitignore
mengdeqi12 Sep 24, 2025
7fc6526
彻底删除 .idea 目录
mengdeqi12 Sep 24, 2025
587029b
彻底移除 .idea 文件并更新 .gitignore
mengdeqi12 Sep 24, 2025
2404222
彻底移除 .idea 并修正 .gitignore 位置
mengdeqi12 Sep 24, 2025
dce2420
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 24, 2025
33e5d4b
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 25, 2025
ff2758f
机器人行走的基底模型
mengdeqi12 Sep 25, 2025
eddd4de
Merge branch 'main' of https://github.com/mengdeqi12/nn
mengdeqi12 Sep 25, 2025
491f2d1
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 26, 2025
308886a
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 27, 2025
c607e1c
feat: 优化 humanoid_motion_control 模块路径处理,解决模型加载失败问题
mengdeqi12 Sep 28, 2025
17c41ab
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 28, 2025
d689c29
feat: 优化 humanoid_motion_control 模块路径处理,解决模型加载失败问题
mengdeqi12 Sep 28, 2025
73ce4c9
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 29, 2025
a4a3ef0
feat: 优化 humanoid_motion_control 模块路径处理,解决模型加载失败问题
mengdeqi12 Sep 29, 2025
fb35491
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Sep 29, 2025
c7ed4a1
Merge branch 'main' of https://github.com/mengdeqi12/nn
mengdeqi12 Sep 29, 2025
65a2e06
feat: 优化 humanoid_motion_control 模块路径处理,解决模型加载失败问题;改了代码我的项目的参数
mengdeqi12 Sep 29, 2025
19299f5
chore: 从仓库中删除 .venv 并忽略
mengdeqi12 Sep 29, 2025
0312bb8
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Oct 2, 2025
8ac7ca0
chore: 从仓库移除 tatus 文件并添加到 .gitignore
mengdeqi12 Oct 4, 2025
1da2194
Merge branch 'OpenHUTB:main' into main
mengdeqi12 Oct 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .gitignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果没有内容,这个文件就不需要添加

Binary file not shown.
47 changes: 15 additions & 32 deletions src/embodied_robot/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
具身机器人
具身机器人

环境配置:
absl-py 2.3.1
cloudpickle 3.1.1
contourpy 1.3.3
cycler 0.12.1
etils 1.13.0
Farama-Notifications 0.0.4
fonttools 4.59.2
fsspec 2025.9.0
glfw 2.10.0
gymnasium 1.2.0
imageio 2.37.0
importlib_resources 6.5.2
kiwisolver 1.4.9
Markdown 3.9
matplotlib 3.10.6
mujoco 3.3.6
numpy 2.3.3
packaging 25.0
pillow 11.3.0
pip 25.2
PyOpenGL 3.1.10
pyparsing 3.2.4
python-dateutil 2.9.0.post0
python-markdown-math 0.9
six 1.17.0
typing_extensions 4.15.0
zipp 3.23.0
torch 2.8.0+cpu
torchaudio 2.8.0+cpu
torchvision 0.23.0+cpu
1. 行走:
# 核心库(必须安装)
mujoco==3.3.6
numpy==2.2.6

# 间接依赖(通常自动安装,若缺失则补充)
absl-py==2.3.1
glfw==2.10.0
PyOpenGL==3.1.10
etils==1.13.0
importlib_resources==6.5.2
typing_extensions==4.15.0
zipp==3.23.0
fsspec==2025.9.0
81 changes: 81 additions & 0 deletions src/embodied_robot/main.py
Original file line number Diff line number Diff line change
@@ -1 +1,82 @@
import mujoco
import time
from mujoco import viewer


def main():
# 定义简单的双轮机器人模型
robot_xml = """
<mujoco model="simple_robot">
<option timestep="0.01"/>
<worldbody>
<!-- 地面 -->
<body name="ground">
<geom type="plane" size="5 5 0.1" rgba="0.9 0.9 0.9 1"/>
</body>

<!-- 机器人主体 -->
<body name="base" pos="0 0 0.1">
<inertial pos="0 0 0" mass="1.0" diaginertia="0.1 0.1 0.1"/>
<geom type="box" size="0.2 0.1 0.1" rgba="0.2 0.4 0.8 1"/>

<!-- 左轮 -->
<body name="left_wheel" pos="0 -0.15 0">
<joint name="left_joint" type="hinge" axis="0 1 0"/>
<geom type="cylinder" size="0.05 0.08" rgba="0.5 0.5 0.5 1"/>
<inertial pos="0 0 0" mass="0.2" diaginertia="0.01 0.01 0.01"/>
</body>

<!-- 右轮 -->
<body name="right_wheel" pos="0 0.15 0">
<joint name="right_joint" type="hinge" axis="0 1 0"/>
<geom type="cylinder" size="0.05 0.08" rgba="0.5 0.5 0.5 1"/>
<inertial pos="0 0 0" mass="0.2" diaginertia="0.01 0.01 0.01"/>
</body>
</body>
</worldbody>

<!-- 电机执行器 -->
<actuator>
<motor name="left_motor" joint="left_joint" gear="100"/>
<motor name="right_motor" joint="right_joint" gear="100"/>
</actuator>
</mujoco>
"""

# 加载模型
model = mujoco.MjModel.from_xml_string(robot_xml)
data = mujoco.MjData(model)

# 初始化可视化器
viewer_instance = viewer.launch_passive(model, data)

# 设置直行速度(左右轮相同速度)
forward_speed = 1.0
data.ctrl[0] = forward_speed # 左轮速度
data.ctrl[1] = forward_speed # 右轮速度

# 运行仿真10秒
total_time = 10.0
steps = int(total_time / model.opt.timestep)

start_time = time.time()
for _ in range(steps):
# 执行仿真步
mujoco.mj_step(model, data)

# 更新可视化
viewer_instance.sync()

# 维持实时速率
elapsed = time.time() - start_time
expected = _ * model.opt.timestep
if elapsed < expected:
time.sleep(expected - elapsed)

print(f"仿真完成,机器人最终位置: {data.body('base').xpos}")
viewer_instance.close()


if __name__ == "__main__":
main()

8 changes: 4 additions & 4 deletions src/embodied_robot/robot_walk/Robot_move_straight.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
<!-- 机器人主体 -->
<!--名为robot_base的机器人基座的坐标为(0 0 0.2),Z轴为0.2避免与地面直接接触-->
<body name="robot_base" pos="0 0 0.2">
<!-- 新增关节定义,允许机器人在X轴方向移动 -->
<joint name="base_joint" type="slide" axis="1 0 0" range="-10 10"/>
<!-- 关节定义,允许机器人在X轴方向移动,移动范围在-20到20之间 -->
<joint name="base_joint" type="slide" axis="1 0 0" range="-20 20"/>
<!--定义物理惯性,质量为1.0单位,物体绕三维坐标旋转的阻力(0.1 0.1 0.1 )值越大,物体越难改变旋转状态 -->
<inertial pos="0 0 0" mass="1.0" diaginertia="0.1 0.1 0.1"/>
<inertial pos="0 0 0" mass="1.0" diaginertia="1 1 1"/>
<!--引用了<asset>的材质模版和default中定义的geom -->
<geom material="red"/>
</body>
Expand All @@ -35,6 +35,6 @@
<!-- 4. 执行器 (电机等) -->
<actuator>
<!-- joint用来指定电机驱动的关节;gear为电机传动比,值越大,力矩越大-->
<motor name="joint_motor" joint="base_joint" gear="100"/>
<motor name="joint_motor" joint="base_joint" gear="5"/>
</actuator>
</mujoco>
3 changes: 2 additions & 1 deletion src/embodied_robot/robot_walk/move_straight.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def control_robot(model_path):

# 计算控制信号
elapsed_time = time.time() - start_time
data.ctrl[0] = 5.0 if (elapsed_time % 4 < 2) else -5.0
data.ctrl[0] = 0.5 if (elapsed_time % 20 < 10) else -0.5

# 运行仿真步
mujoco.mj_step(model, data)
Expand All @@ -32,6 +32,7 @@ def control_robot(model_path):
# 控制仿真速度
time.sleep(model.opt.timestep)


except KeyboardInterrupt:
print("\n仿真被用户中断")

Expand Down
54 changes: 53 additions & 1 deletion src/humanoid_motion_control/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
"""
[路径优化] 自动切换工作目录并加载模型

为了增强代码的可移植性,我们在程序启动时自动将工作目录切换到项目根目录。
这样可以确保脚本中使用的相对路径(如 "src/humanoid_motion_control/humanoid.xml")
无论从哪个位置运行,都能正确地指向预期的文件。

修改原因:
- 原版代码使用的是基于运行时目录的相对路径,这在不同环境或不同运行方式下容易出错。
- 通过自动切换到项目根目录,可以统一所有相对路径的基准,避免 "No such file or directory" 错误。

使用方法:
- 保持 main.py 中原有相对路径写法不变即可。
- 此脚本会在加载模型等操作前自动完成路径切换。

注意事项:
- 此代码段必须放置在所有依赖相对路径的导入或文件操作之前。
- 如果项目目录结构发生重大改变,可能需要调整计算 project_root 的层级。
"""

import os
import mujoco

# --- 你之前的切换目录代码 ---
import sys
file_path = os.path.abspath(__file__)
project_root = os.path.dirname(os.path.dirname(file_path))
os.chdir(project_root)
print(f"当前工作目录已切换到: {os.getcwd()}")
# ----------------------------

# 1. 定义模型文件的相对路径
# 注意:这里使用了推荐的正斜杠
relative_model_path = "src/humanoid_motion_control/humanoid.xml"
print(f"尝试查找的模型路径: {relative_model_path}")

# 2. 检查文件是否存在
if os.path.exists(relative_model_path):
print("✅ 模型文件找到了!")
try:
# 3. 如果文件存在,再尝试加载
model = mujoco.MjModel.from_xml_path(relative_model_path)
data = mujoco.MjData(model)
print("🎉 模型加载成功!")
# ... 你的其他代码 ...
except Exception as e:
print(f"模型加载失败: {e}")
else:
print(f"❌ 错误:在当前工作目录下找不到模型文件。")
print(f"请确认文件 '{relative_model_path}' 确实存在。")


# 标准库
import time
# 第三方库
Expand All @@ -6,7 +58,7 @@

def main():
try:
model = mujoco.MjModel.from_xml_path("src\humanoid_motion_control\humanoid.xml")
model = mujoco.MjModel.from_xml_path(r"humanoid_motion_control\humanoid.xml")
except Exception as e:
print(f"模型加载失败: {e}")
return
Expand Down
2 changes: 1 addition & 1 deletion src/humanoid_mujoco_py/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def main():
# 加载MJCF模型文件
# 模型定义了物理场景:包含平面、光源和一个自由下落的盒子
# from_xml_path方法支持从XML文件加载模型,替代C++中的mj_loadXML
model = mujoco.MjModel.from_xml_path("src\humanoid_control\hello.xml")
model = mujoco.MjModel.from_xml_path("src/humanoid_control/hello.xml")

# 创建与模型对应的动态数据结构
# 存储模拟过程中的状态变量(位置、速度等),类似C++中的mjData
Expand Down