Skip to content

Policy Deployment

The policy runner base class PolicyRunnerBase defines input observation, output action, and inference lifecycle.

virtual RobotAction getRobotAction(const RobotBasicState&, const UserCommand&) = 0;
virtual void OnEnter(const RobotBasicState&) = 0;
virtual void SetDecimation(int d);

Lite3PolicyRunner is the ONNX policy implementation for Lite3.

session_ = Ort::Session(env_, policy_path_.c_str(), session_options_);
const int motor_num = 12;
const int observation_dim = 45;
const int action_dim = 12;

Observation vector composition:

current_observation_ << base_omega, // 3D (angular velocity * 0.25)
projected_gravity, // 3D (gravity projection)
command, // 3D (velocity command)
joint_pos_rl, // 12D (joint position - default position)
joint_vel_rl, // 12D (joint velocity * 0.05)
last_action_eigen; // 12D (previous action)
VecXf current_action_eigen = Onnx_infer(current_observation_);
for (int i = 0; i < 4; ++i){
robot_action.goal_joint_pos.segment(i*3, 3) = tmp_action_eigen.segment(i*3, 3);
}
robot_action.kp = kp_; // Vec3f(30, 30, 30).replicate(4, 1)
robot_action.kd = kd_; // Vec3f(1, 1, 1).replicate(4, 1)

The policy and robot may have different joint orderings. Permutation indices are automatically computed via name mapping:

std::vector<std::string> robot_order = {
"FL_HipX_joint", "FL_HipY_joint", "FL_Knee_joint",
"FR_HipX_joint", "FR_HipY_joint", "FR_Knee_joint",
"HL_HipX_joint", "HL_HipY_joint", "HL_Knee_joint",
"HR_HipX_joint", "HR_HipY_joint", "HR_Knee_joint"};
robot2policy_idx = generate_permutation(robot_order, policy_order);
policy2robot_idx = generate_permutation(policy_order, robot_order);

The model file is located at:

src/Lite3_sdk_deploy/policy/policy.onnx
dof_default_eigen_policy << 0.0000, -0.8000, 1.6000,
0.0000, -0.8000, 1.6000,
0.0000, -0.8000, 1.6000,
0.0000, -0.8000, 1.6000;
std::vector<float> action_scale_robot = {0.125, 0.25, 0.25,
0.125, 0.25, 0.25,
0.125, 0.25, 0.25,
0.125, 0.25, 0.25};