Ubuntu 20.04 使用 Issac Gym 进行宇树G1人形机器人进行强化学习训练(Linux仿真)

目录

一、PBHC源码下载

二、创建虚拟环境

[三、安装 Isaac Gym​](#三、安装 Isaac Gym)

[四、安装 rsl_rl​](#四、安装 rsl_rl)

[五、安装Unitree 强化学习相关库](#五、安装Unitree 强化学习相关库)

[5.1 安装unitree_rl_gym​](#5.1 安装unitree_rl_gym)

[5.2 unitree_sdk2py(可选)](#5.2 unitree_sdk2py(可选))

六、强化学习训练

[6.1 训练命令​](#6.1 训练命令)

[6.2 效果演示 Play](#6.2 效果演示 Play)

[6.3 Mujuco 仿真验证](#6.3 Mujuco 仿真验证)


参考链接:https://blog.csdn.net/qq_38429958/article/details/149634498?spm=1001.2014.3001.5501

在此记录整个复现过程

一、PBHC源码下载

首先下载源码:

git clone https://github.com/TeleHuman/PBHC.git

二、创建虚拟环境

创建 conda虚拟环境

conda create -n unitree-rl python=3.8

激活虚拟环境​

conda activate unitree-rl

安装 PyTorch

conda install pytorch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 pytorch-cuda -c pytorch -c nvidia

或者使用

pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu118

三、安装 Isaac Gym

3.1下载

Isaac Gym 是 Nvidia 提供的刚体仿真和训练框架。首先,先在 Nvidia 官网https://developer.nvidia.com/isaac-gym/download 下载Archive压缩包。

3.2解压

tar -zxvf IsaacGym_Preview_4_Package.tar.gz

cd isaacgym/python

pip install -e .

3.3验证安装

cd examples

python 1080_balls_of_solitude.py

四、安装 rsl_rl​

1. 克隆仓库

git clone https://github.com/leggedrobotics/rsl_rl.git -b v1.0.2

2. 安装

cd rsl_rl

pip install -e .

五、安装Unitree 强化学习相关库

5.1 安装unitree_rl_gym​

git clone https://github.com/unitreerobotics/unitree_rl_gym.git

cd unitree_rl_gym

pip install -e .

5.2 unitree_sdk2py(可选)

unitree_sdk2py 是用于与真实机器人通信的库。如果需要将训练的模型部署到物理机器人上运行,可以安装此库。

git clone https://github.com/unitreerobotics/unitree_sdk2_python.git

cd unitree_sdk2_python

pip install -e .

六、强化学习训练

6.1 训练命令​

python legged_gym/scripts/train.py --task=g1 --headless

https://github.com/unitreerobotics/unitree_rl_gym/issues/69

https://github.com/leggedrobotics/rsl_rl/pull/12/files

具体操作为在rsl_rl/utils/utils.py中增加和删除对应的代码:

python 复制代码
    trajectory_lengths_list = trajectory_lengths.tolist()
    # Extract the individual trajectories
    trajectories = torch.split(tensor.transpose(1, 0).flatten(0, 1),trajectory_lengths_list)
    # add at least one full length trajectory
    trajectories = trajectories + (torch.zeros(tensor.shape[0], tensor.shape[-1], device=tensor.device), )
    # pad the trajectories to the length of the longest trajectory
    padded_trajectories = torch.nn.utils.rnn.pad_sequence(trajectories)
    # remove the added tensor
    padded_trajectories = padded_trajectories[:, :-1]


    trajectory_masks = trajectory_lengths > torch.arange(0, tensor.shape[0], device=tensor.device).unsqueeze(1)
    trajectory_masks = trajectory_lengths > torch.arange(0, padded_trajectories.shape[0], device=tensor.device).unsqueeze(1)
    return padded_trajectories, trajectory_masks

def unpad_trajectories(trajectories, masks):

训练结果如下:

6.2 效果演示 Play

在 Gym 中查看训练效果,可以运行以下命令:​

python legged_gym/scripts/play.py --task=g1

生成仅一个模型

python legged_gym/scripts/play.py --task=g1 --num_envs=1

#使用指定路径下模型进行测试(load_run不需要带logs地址)

python legged_gym/scripts/play.py --task=g1 --num_envs=1 --load_run=Oct10_03-50-19_

使用指定路径下 指定模型进行测试(load_run不需要带logs地址)

python legged_gym/scripts/play.py --task=g1 --num_envs=1 --load_run=Oct10_03-50-19_ --checkpoint=5000

结果如下:

!!!实际训练到7000次就可以了,7000次左右以后的结果开始不正常

6.3 Mujuco 仿真验证

python deploy/deploy_mujoco/deploy_mujoco.py g1.yaml

修改g1.yaml文件中的(policy_path):

python 复制代码
#policy_path: "{LEGGED_GYM_ROOT_DIR}/deploy/pre_train/g1/motion.pt"
policy_path: "{LEGGED_GYM_ROOT_DIR}/logs/g1/exported/policies/policy_lstm_1.pt"
xml_path: "{LEGGED_GYM_ROOT_DIR}/resources/robots/g1_description/scene.xml"

# Total simulation time
simulation_duration: 60.0
# Simulation time step
simulation_dt: 0.002
# Controller update frequency (meets the requirement of simulation_dt * controll_decimation=0.02; 50Hz)
control_decimation: 10

kps: [100, 100, 100, 150, 40, 40, 100, 100, 100, 150, 40, 40]
kds: [2, 2, 2, 4, 2, 2, 2, 2, 2, 4, 2, 2]

default_angles: [-0.1,  0.0,  0.0,  0.3, -0.2, 0.0,
                  -0.1,  0.0,  0.0,  0.3, -0.2, 0.0]

ang_vel_scale: 0.25
dof_pos_scale: 1.0
dof_vel_scale: 0.05
action_scale: 0.25
cmd_scale: [2.0, 2.0, 0.25]
num_actions: 12
num_obs: 47

cmd_init: [0.5, 0, 0]

结果还不错:

相关推荐
梦想的旅途27 小时前
基于RPA技术的企业微信自动化接口设计思路与应用实践
人工智能·机器人·自动化·企业微信·rpa
CCPC不拿奖不改名7 小时前
Redis 工程化部署深度解析
linux·服务器·数据库·redis·深度学习·缓存·rag
鱼很腾apoc8 小时前
【Linux】第7期 进程间通信 (IPC) 详解:管道 (匿名 / 命名) + System V
linux·服务器·c语言·学习·进程间通信·ipc
毒爪的小新8 小时前
踩坑实录 | RAG知识库完整搭建-Milvus2.4+BGE大中文AI模型嵌入
linux·人工智能·ai·milvus·rag
2023自学中9 小时前
imx6ull 开发板, mame 模拟器,运行游戏 测试
linux·游戏·嵌入式·开发板
是个西兰花9 小时前
Linux:进程信号
linux·运维·服务器
CS创新实验室9 小时前
从“业余爱好”到数字基石:Linux 发展史及带给技术人的成长启示
linux·运维·服务器
Biomamba生信基地9 小时前
FindNeighbors()函数报错object ‘CsparseMatrix_validate’ not found
linux·运维·服务器·生物信息学
zzzzzz31012 小时前
别争了,OpenClaw 和国产龙虾我全都要:一个 AI Agent 混合部署实战
机器学习·机器人·api
orion572 天前
Missing Semester Class1:course overview and introduction of shell
linux