Skip to content

fix bug about collapse in mujoco #25

@HazinTihoa

Description

@HazinTihoa

when i run the sim2tim cmd below:
ros2 launch motion_tracking_controller mujoco.launch.py policy_path:=~/whole_body_tracking/logs/rsl_rl/g1_flat/exported/policy.onnx
it reported error:

[mujoco_sim-3] [ERROR] [1762352259.045921687] [walking_controller]: Original error: OnnxPolicy: 'anchor_body_name' not found in model metadata. Please check the model.
[mujoco_sim-3] [WARN] [1762352259.045944157] [walking_controller]: Error occurred while doing error handling.
[mujoco_sim-3] [ERROR] [1762352259.045960838] [controller_manager]: After configuring, controller 'walking_controller' is in state 'unconfigured' , expected inactive.
[spawner-1] [ERROR] [1762352259.049161804] [spawner_state_estimator]: Failed to configure controller

basically, it due to attach_onnx_metadata() does not name anchor_body_name in .onnx file.

to fix this,you need to specify it in attach_onnx_matadata():

` def attach_onnx_metadata(env: ManagerBasedRLEnv, run_path: str, path: str, filename="policy.onnx") -> None:
onnx_path = os.path.join(path, filename)

motion_cmd: MotionCommand = env.command_manager.get_term("motion")                   # new

metadata = {
    "run_path": run_path,
    "joint_names": env.scene["robot"].data.joint_names,
    "joint_stiffness": env.scene["robot"].data.joint_stiffness[0].cpu().tolist(),
    "joint_damping": env.scene["robot"].data.joint_damping[0].cpu().tolist(),
    "default_joint_pos": env.scene["robot"].data.default_joint_pos_nominal.cpu().tolist(),
    "command_names": env.command_manager.active_terms,
    "observation_names": env.observation_manager.active_terms["policy"],
    "action_scale": env.action_manager.get_term("joint_pos")._scale[0].cpu().tolist(),
    "anchor_body_name": motion_cmd.cfg.anchor_body,                                                      #new
}

model = onnx.load(onnx_path)

for k, v in metadata.items():
    entry = onnx.StringStringEntryProto()
    entry.key = k
    entry.value = list_to_csv_str(v) if isinstance(v, list) else str(v)
    model.metadata_props.append(entry)

onnx.save(model, onnx_path)`

then run the play.py to export a new .onnx file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions