Skip to content

Commit

Permalink
fix: add hip_scale_reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
fan-ziqi committed Mar 7, 2024
1 parent 825b7c7 commit 1213f3c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/unitree_rl/lib/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ torch::Tensor Model::quat_rotate_inverse(torch::Tensor q, torch::Tensor v)

torch::Tensor Model::compute_torques(torch::Tensor actions)
{
actions *= this->params.action_scale;
torch::Tensor torques = this->params.p_gains * (actions + this->params.default_dof_pos - this->obs.dof_pos) - this->params.d_gains * this->obs.dof_vel;
torch::Tensor actions_scaled = actions * this->params.action_scale;
int indices[] = {0, 3, 6, 9};
for (int i : indices)
{
actions_scaled[0][i] *= this->params.hip_scale_reduction;
}

torch::Tensor torques = this->params.p_gains * (actions_scaled + this->params.default_dof_pos - this->obs.dof_pos) - this->params.d_gains * this->obs.dof_vel;
torch::Tensor clamped = torch::clamp(torques, -(this->params.torque_limits), this->params.torque_limits);
return clamped;
}
Expand Down
1 change: 1 addition & 0 deletions src/unitree_rl/lib/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct ModelParams {
float damping;
float stiffness;
float action_scale;
float hip_scale_reduction;
float num_of_dofs;
float lin_vel_scale;
float ang_vel_scale;
Expand Down
1 change: 1 addition & 0 deletions src/unitree_rl/src/unitree_rl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Unitree_RL::Unitree_RL()
this->params.d_gains = torch::ones(12) * this->params.damping;
this->params.p_gains = torch::ones(12) * this->params.stiffness;
this->params.action_scale = 0.25;
this->params.hip_scale_reduction = 0.5;
this->params.num_of_dofs = 12;
this->params.lin_vel_scale = 2.0;
this->params.ang_vel_scale = 0.25;
Expand Down

0 comments on commit 1213f3c

Please sign in to comment.