Skip to content

Commit 9905c04

Browse files
committed
World algined base vel and acc computed properly at solve
1 parent 0ea2e03 commit 9905c04

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

include/simple-mpc/inverse-dynamics/kinodynamics-id.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ namespace simple_mpc
8585
tsid::solvers::HQPOutput last_solution_;
8686
tsid::trajectories::TrajectorySample samplePosture_;
8787
tsid::trajectories::TrajectorySample sampleBase_;
88+
pinocchio::Motion targetVelBase_;
89+
pinocchio::Motion targetAccBase_;
8890
};
8991

9092
} // namespace simple_mpc

src/inverse-dynamics/kinodynamics-id.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ void KinodynamicsID::setTarget(
133133
postureTask_->setReference(samplePosture_);
134134

135135
// Base task
136-
const pinocchio::SE3 oMb{data_handler_.getBaseFramePose()};
137-
const pinocchio::SE3 oMb_rotation(oMb.rotation(), Eigen::Vector3d::Zero());
138-
const pinocchio::Motion v_world_aligned{oMb_rotation.act(pinocchio::Motion(v_target.head<6>()))};
139-
const pinocchio::Motion a_world_aligned{oMb_rotation.act(pinocchio::Motion(a_target.head<6>()))};
140-
baseTask_->setReference(oMb, v_world_aligned, a_world_aligned);
136+
tsid::math::SE3ToVector(data_handler_.getBaseFramePose(), sampleBase_.pos);
137+
/* Velocity and acceleration not set here since the actual position of the robot is needed to transform from local to
138+
* world-aligned frame. Will be done in solve()
139+
*/
140+
targetVelBase_ = v_target.head<6>();
141+
targetAccBase_ = a_target.head<6>();
141142

142143
// Foot contacts
143144
for (std::size_t foot_nb = 0; foot_nb < model_handler_.getFeetNb(); foot_nb++)
@@ -215,6 +216,15 @@ void KinodynamicsID::solve(
215216
}
216217
}
217218

219+
// Convert robot base vel/acc from local to world-aligned frame using actual robot pose
220+
const pinocchio::SE3 oMb_rotation(data_handler_.getBaseFramePose().rotation(), Eigen::Vector3d::Zero());
221+
const pinocchio::Motion v_world_aligned{oMb_rotation.act(pinocchio::Motion(targetVelBase_))};
222+
const pinocchio::Motion a_world_aligned{oMb_rotation.act(pinocchio::Motion(targetAccBase_))};
223+
sampleBase_.setDerivative(v_world_aligned.toVector());
224+
sampleBase_.setDerivative(a_world_aligned.toVector());
225+
baseTask_->setReference(sampleBase_);
226+
227+
// Solve QP
218228
const tsid::solvers::HQPData & solver_data = formulation_.computeProblemData(t, q_meas, v_meas);
219229
last_solution_ = solver_.solve(solver_data);
220230
assert(last_solution_.status == tsid::solvers::HQPStatus::HQP_STATUS_OPTIMAL);

0 commit comments

Comments
 (0)