LejuRobot Lab
本文档同步自开源仓库 OpenLET/LejuLab-Train,内容以仓库为准。仓库代码与历史版本:https://gitcode.com/OpenLET/LejuLab-Train
This example trains RobanS17 to imitate the fcyx motion. The --task id is Tracking-Dance-Flat-RobanS17.
Run every command from the repository root, in the same Python environment.
English
Results
| tasks | Isaac Lab | Mujoco | sim2real |
|---|---|---|---|
| fcyx | ![]() | ![]() | ![]() |
1. Example
The example below uses the fcyx dance: prepare the motion, replay the reference clip, train, and export the policy in simulation. The task id passed to --task is Tracking-Dance-Flat-RobanS17.
The robot model used by training and play is:
source/leju_robot/leju_robot/assets/robots/robanS17/urdf/biped_s17.urdf
tracking_env_cfg.py loads it through RobanS17_CYLINDER_CFG (RobanS17ArticulationCfg in source/leju_robot/leju_robot/assets/leju.py).
2. Environment
Install Python 3.10, Isaac Sim 4.5.0, and Isaac Lab 2.1. Follow the Isaac Lab 2.1 installation guide: https://isaac-sim.github.io/IsaacLab/v2.1.0/source/setup/installation/index.html
Use that same environment for every command below. From the repository root:
pip install -e source/leju_robotSaving a checkpoint imports onnx. If import onnx fails, install it in this environment before training.
Stay at the repository root for the rest of the commands. Relative motion paths and the logs/ directory are resolved from the current working directory.
3. Motion files
This example starts from the fcyx CSV. It does not retarget a motion onto the robot.
The repository already contains three files:
- CSV already in the repository, 120 FPS. Conversion reads this file.
source/leju_robot/leju_robot/assets/motion_data/mimic/csv_data/robanS17_fcyx_120fps.csv- NPZ already in the repository, 50 FPS. Use it when skipping conversion.
source/leju_robot/leju_robot/assets/motion_data/mimic/npz_data/robanS17_fcyx_50fps.npz- Deploy CSV already in the repository, 50 FPS.
source/leju_robot/leju_robot/assets/motion_data/mimic/deploy_data/robanS17_fcyx_50fps_deploy.csvThe source CSV has no header and 28 columns:
- Root position
x y z(3) - Root quaternion
x y z w(4) - 21 joint positions, in this order:
waist_yaw_joint
leg_l1_joint leg_l2_joint leg_l3_joint leg_l4_joint leg_l5_joint leg_l6_joint
leg_r1_joint leg_r2_joint leg_r3_joint leg_r4_joint leg_r5_joint leg_r6_joint
zarm_l1_joint zarm_l2_joint zarm_l3_joint zarm_l4_joint
zarm_r1_joint zarm_r2_joint zarm_r3_joint zarm_r4_jointThat order is ROBANS17_MDP_JOINT_ORDER_CFG in source/leju_robot/leju_robot/assets/leju.py. The converter maps columns onto the robot in this sequence and stops if the joint count differs.
The NPZ stores fps 50, joint_pos with 21 joints, and body_pos_w with 22 bodies. Training and replay read this file.
The deploy CSV has a header. Its quaternion columns are body_quat_w body_quat_x body_quat_y body_quat_z. It is a conversion product for deployment. Training does not read it.
Conversion reads the CSV under mimic/ and writes a new NPZ and deploy CSV to output/. output/ is gitignored, so the files already in the repository stay unchanged. Replay, training, and play in this example all use output/robanS17_fcyx_50fps.npz.
To skip conversion, pass the NPZ already in the repository instead:
source/leju_robot/leju_robot/assets/motion_data/mimic/npz_data/robanS17_fcyx_50fps.npz
Use that same path for replay, training, and play.
4. Convert CSV to NPZ
Input is 120 FPS. Output is 50 FPS. The source quaternion is xyzw, so the command includes --input_quat_xyzw. The converter reorders it to wxyz. The robot argument is robanS17, with that capitalization.
The script name contains &. Quote the path.
python "scripts/motion_tool/csv_to_npz&deploycsv.py" \
--input_file source/leju_robot/leju_robot/assets/motion_data/mimic/csv_data/robanS17_fcyx_120fps.csv \
--input_fps 120 \
--output_fps 50 \
--robot robanS17 \
--input_quat_xyzw \
--npz_output output/robanS17_fcyx_50fps.npz \
--csv_output output/robanS17_fcyx_50fps_deploy.csv \
--headless--input_file: Source CSV.--input_fps: Frame rate of the source CSV.--output_fps: Frame rate of the NPZ and deploy CSV. This example uses 50.--robot: Robot used while converting. UserobanS17.--input_quat_xyzw: Read the root quaternion as xyzw and write wxyz.--npz_output: Output path of the training NPZ. Written tooutput/.--csv_output: Output path of the deploy CSV.--headless: Headless mode. The simulation still runs.
5. Replay the reference motion
Replay the NPZ produced in the previous step:
python scripts/motion_tool/replay_npz.py \
--robot robanS17 \
--motion_file output/robanS17_fcyx_50fps.npz--robot: Robot to display. UserobanS17.--motion_file: NPZ from the conversion step.
Check that the robot faces the expected direction and that the joints follow the clip.
This step plays the reference clip. The trained policy is exercised in the play step later.
6. Train
Training and play both load source/leju_robot/leju_robot/assets/robots/robanS17/urdf/biped_s17.urdf.
Pass the same fcyx NPZ on every train and play command. CommandsCfg.motion.motion_file in source/leju_robot/leju_robot/tasks/tracking/config/robanS17/dance/tracking_env_cfg.py is only a fallback, and that default can change. The current fallback is robanS17_fcyx_50fps.npz. Leaving --motion_file out trains whatever file is written there.
Training:
python scripts/reinforcement_learning/rsl_rl/train.py \
--task Tracking-Dance-Flat-RobanS17 \
--motion_file output/robanS17_fcyx_50fps.npz \
--run_name fcyx \
--num_envs 8192 \
--max_iterations 80000 \
--headless--task: Training task. This guide usesTracking-Dance-Flat-RobanS17.--motion_file: Reference NPZ. Pass it so training does not use the fallback file intracking_env_cfg.py.--run_name: Suffix of the new run directory,<timestamp>_fcyx.--num_envs: Number of parallel environments. This example uses 8192. The task default is 4096.--max_iterations: Number of PPO updates. This example uses 80000. The task default is 60000.--headless: Train without a window.
7. Play and export
Play uses the -Play task, the same NPZ, and a checkpoint produced by the training run above. The same URDF is loaded: source/leju_robot/leju_robot/assets/robots/robanS17/urdf/biped_s17.urdf.
python scripts/reinforcement_learning/rsl_rl/play.py \
--task Tracking-Dance-Flat-RobanS17-Play \
--motion_file output/robanS17_fcyx_50fps.npz \
--load_run <run_directory> \
--checkpoint <checkpoint> \
--num_envs 1--task: Play task,Tracking-Dance-Flat-RobanS17-Play.--motion_file: The same NPZ used for training.--load_run: Directory name of the run to watch.--checkpoint: Checkpoint file from that run.--num_envs: Number of robots in the viewer. Use 1.
<run_directory> and <checkpoint> are the folder and file from the run you want to watch. There is no pre-seeded checkpoint in this repository.
Play writes two more files under that run:
exported/policy.ptexported/policy.onnx
Artifacts:
| File | Where it comes from |
|---|---|
model_<iteration>.pt | Training checkpoint |
<run_directory>.onnx | ONNX written when training saves a checkpoint |
exported/policy.pt | JIT written by play |
exported/policy.onnx | ONNX written by play |
output/robanS17_fcyx_50fps_deploy.csv | Deploy motion CSV from conversion |
8. Troubleshooting
Import errors, or onnx missing when a checkpoint is saved
The shell is using a different Python than the one where leju_robot and Isaac Lab were installed. Activate that environment again and run from the repository root. If the failure is import onnx, install onnx in that same environment.
Unknown robot 'robans17'
The converter and replay scripts accept robanS17. The key is case-sensitive.
The shell backgrounds the converter, or it cannot find the script
The script filename contains &. Quote it: "scripts/motion_tool/csv_to_npz&deploycsv.py".
Training follows a different dance
--motion_file was omitted, so the task used the fallback in tracking_env_cfg.py. That fallback can change and is currently robanS17_fcyx_50fps.npz. Pass output/robanS17_fcyx_50fps.npz on train and play.
The replayed robot is tilted, the clip duration looks wrong, or conversion raises a joint-count error
The source quaternion is xyzw. Keep --input_quat_xyzw. Keep --input_fps 120 and --output_fps 50. The CSV must contain 21 joints in the order listed in section 3.
No runs present or No checkpoints
--load_run must be the directory name under logs/rsl_rl/robanS17_dance, and --checkpoint must be a model_*.pt inside it.
License
Apache 2.0.
中文
效果展示
| tasks | Isaac Lab | Mujoco | sim2real |
|---|---|---|---|
风吹一夏 | ![]() | ![]() | ![]() |
1. 示例
下面以风吹一夏舞蹈作为示例,走一遍:准备动作、回放参考片段、训练,并在仿真里导出策略。传给 --task 的任务 ID 是 Tracking-Dance-Flat-RobanS17。
训练和测试加载的机器人模型是:
source/leju_robot/leju_robot/assets/robots/robanS17/urdf/biped_s17.urdf
tracking_env_cfg.py 通过 RobanS17_CYLINDER_CFG 加载它,定义在 source/leju_robot/leju_robot/assets/leju.py 的 RobanS17ArticulationCfg。
2. 环境
安装 Python 3.10、Isaac Sim 4.5.0 和 Isaac Lab 2.1。按 Isaac Lab 2.1 的安装说明操作:https://isaac-sim.github.io/IsaacLab/v2.1.0/source/setup/installation/index.html
后面的命令使用同一个环境。在仓库根目录执行:
pip install -e source/leju_robot保存检查点时会导入 onnx。如果 import onnx 失败,先在这个环境里安装再训练。
后续命令都留在仓库根目录。相对动作路径和 logs/ 都按当前工作目录解析。
3. 动作文件
本流程从风吹一夏这份 CSV 开始,不包含动作重定向。
仓库里已经有三个文件:
- 仓库里已有的 CSV,120 FPS。转换读取这个文件。
source/leju_robot/leju_robot/assets/motion_data/mimic/csv_data/robanS17_fcyx_120fps.csv- 仓库里已有的 NPZ,50 FPS。跳过转换时用它。
source/leju_robot/leju_robot/assets/motion_data/mimic/npz_data/robanS17_fcyx_50fps.npz- 仓库里已有的部署 CSV,50 FPS。
source/leju_robot/leju_robot/assets/motion_data/mimic/deploy_data/robanS17_fcyx_50fps_deploy.csv原始 CSV 没有表头,共 28 列:
- 根位置
x y z(3) - 根四元数
x y z w(4) - 21 个关节位置,顺序为:
waist_yaw_joint
leg_l1_joint leg_l2_joint leg_l3_joint leg_l4_joint leg_l5_joint leg_l6_joint
leg_r1_joint leg_r2_joint leg_r3_joint leg_r4_joint leg_r5_joint leg_r6_joint
zarm_l1_joint zarm_l2_joint zarm_l3_joint zarm_l4_joint
zarm_r1_joint zarm_r2_joint zarm_r3_joint zarm_r4_joint这个顺序是 source/leju_robot/leju_robot/assets/leju.py 里的 ROBANS17_MDP_JOINT_ORDER_CFG。转换脚本按该顺序映射到机器人上,关节数量不一致会直接报错。
NPZ 中 fps 为 50,joint_pos 有 21 个关节,body_pos_w 有 22 个刚体。训练和回放读的是这个文件。
部署 CSV 有表头,四元数列是 body_quat_w body_quat_x body_quat_y body_quat_z。它是给部署用的转换结果。训练不读这个文件。
转换读取 mimic/ 里的 CSV,把新的 NPZ 和部署 CSV 写到 output/。output/ 已被 gitignore,所以不会覆盖仓库里已有的文件。本示例后面的回放、训练、测试都使用 output/robanS17_fcyx_50fps.npz。
如果跳过转换,改为传入仓库里已有的 NPZ:
source/leju_robot/leju_robot/assets/motion_data/mimic/npz_data/robanS17_fcyx_50fps.npz
回放、训练、测试使用同一个路径。
4. 把 CSV 转成 NPZ
输入 120 FPS,输出 50 FPS。原始四元数是 xyzw,所以命令带 --input_quat_xyzw,转换脚本会把它重排成 wxyz。机器人参数是 robanS17,大小写按这个写。
脚本名里有 &,路径必须加引号。
python "scripts/motion_tool/csv_to_npz&deploycsv.py" \
--input_file source/leju_robot/leju_robot/assets/motion_data/mimic/csv_data/robanS17_fcyx_120fps.csv \
--input_fps 120 \
--output_fps 50 \
--robot robanS17 \
--input_quat_xyzw \
--npz_output output/robanS17_fcyx_50fps.npz \
--csv_output output/robanS17_fcyx_50fps_deploy.csv \
--headless--input_file:原始 CSV。--input_fps:原始 CSV 的帧率--output_fps:NPZ 和部署 CSV 的帧率,本流程用 50。--robot:转换时使用的机器人,写robanS17。--input_quat_xyzw:按 xyzw 读取根四元数,并写成 wxyz。--npz_output:训练 NPZ 的输出路径。写到output/。--csv_output:部署 CSV 的输出路径。--headless:无头模式,仿真仍会运行。
5. 回放参考动作
回放上一步生成的 NPZ:
python scripts/motion_tool/replay_npz.py \
--robot robanS17 \
--motion_file output/robanS17_fcyx_50fps.npz--robot:显示用的机器人,写robanS17。--motion_file:上一步生成的 NPZ。
看机器人朝向是否符合预期,关节是否跟着片段走。
这一步播放的是参考片段。训练出来的策略要到后面的测试步骤里看。
6. 训练
训练和测试加载的都是 source/leju_robot/leju_robot/assets/robots/robanS17/urdf/biped_s17.urdf。
训练、测试每次都传入同一份风吹一夏 NPZ。source/leju_robot/leju_robot/tasks/tracking/config/robanS17/dance/tracking_env_cfg.py 里 CommandsCfg.motion.motion_file 只是备用值,而且这个默认值以后可能改。当前备用文件是 robanS17_fcyx_50fps.npz。不写 --motion_file 时,训练用的就是配置里当时写着的那份文件。
正式训练:
python scripts/reinforcement_learning/rsl_rl/train.py \
--task Tracking-Dance-Flat-RobanS17 \
--motion_file output/robanS17_fcyx_50fps.npz \
--run_name fcyx \
--num_envs 8192 \
--max_iterations 80000 \
--headless--task:训练任务,本指南用Tracking-Dance-Flat-RobanS17。--motion_file:参考 NPZ。每次都传入,避免用到tracking_env_cfg.py里的备用文件。--run_name:新运行目录的后缀,目录名为<时间戳>_fcyx。--num_envs:并行环境数。本示例用 8192。任务配置默认是 4096,显存不够就减小。--max_iterations:PPO 更新次数。本示例用 80000。任务配置默认是 60000。--headless:训练时不打开窗口。
7. 测试与导出
测试使用带 -Play 的任务、同一份 NPZ,以及上面某次训练实际生成的检查点。加载的 URDF 同样是 source/leju_robot/leju_robot/assets/robots/robanS17/urdf/biped_s17.urdf。
python scripts/reinforcement_learning/rsl_rl/play.py \
--task Tracking-Dance-Flat-RobanS17-Play \
--motion_file output/robanS17_fcyx_50fps.npz \
--load_run <run_directory> \
--checkpoint <checkpoint> \
--num_envs 1--task:测试任务,Tracking-Dance-Flat-RobanS17-Play。--motion_file:与训练相同的 NPZ。--load_run:要查看的运行目录名。--checkpoint:该次运行里的检查点。--num_envs:窗口里的机器人数量,看策略时用 1。
<run_directory> 和 <checkpoint> 换成你要看的那次运行。仓库里没有可以直接拿来跑的历史检查点。
测试还会在该运行目录下写出:
exported/policy.ptexported/policy.onnx
产物对照:
| 文件 | 来源 |
|---|---|
model_<iteration>.pt | 训练检查点 |
<run_directory>.onnx | 训练保存检查点时写出的 ONNX |
exported/policy.pt | 测试写出的 JIT |
exported/policy.onnx | 测试写出的 ONNX |
output/robanS17_fcyx_50fps_deploy.csv | 转换得到的部署动作 CSV |
8. 错误排查
导入失败,或保存检查点时提示缺少 onnx
当前 shell 用的 Python 和安装 leju_robot、Isaac Lab 的环境不一致。重新激活那个环境,并在仓库根目录执行。如果是 import onnx 失败,在同一个环境里安装 onnx。
Unknown robot 'robans17'
转换和回放接受的名字是 robanS17,大小写敏感。
转换命令被 shell 放到后台,或找不到脚本
脚本文件名含有 &。路径要加引号:"scripts/motion_tool/csv_to_npz&deploycsv.py"。
训练跟踪的是另一段舞
没有传 --motion_file,任务用了 tracking_env_cfg.py 里的备用文件。这个备用值可能被改掉,当前是 robanS17_fcyx_50fps.npz。训练、测试都传入 output/robanS17_fcyx_50fps.npz。
回放时机器人姿态歪了、片段时长不对,或转换报关节数量错误
原始四元数是 xyzw,保留 --input_quat_xyzw。--input_fps 保持 120,--output_fps 保持 50。CSV 必须是第 3 节列出的 21 个关节,顺序一致。
No runs present 或 No checkpoints
--load_run 是 logs/rsl_rl/robanS17_dance 下的目录名,--checkpoint 是该目录里的 model_*.pt。
许可证
Apache 2.0。


