Skip to content

Commit 3a04d4d

Browse files
committed
Add centroidal foot tracking test
1 parent 756e40e commit 3a04d4d

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/inverse-dynamics/centroidal.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,20 @@ namespace simple_mpc
3232
const size_t n_contacts = model_handler_.getFeetNb();
3333
for (int i = 0; i < n_contacts; i++)
3434
{
35+
const RobotModelHandler::FootType foot_type = model_handler.getFootType(i);
3536
const std::string frame_name = model_handler.getFootFrameName(i);
37+
Eigen::Vector<double, 6> position_mask = Eigen::Vector<double, 6>::Ones();
38+
if (foot_type == RobotModelHandler::POINT)
39+
position_mask.tail<3>().setZero();
40+
else if (foot_type == RobotModelHandler::QUAD)
41+
position_mask.tail<3>().setOnes();
42+
else
43+
assert(false);
3644
tsid::tasks::TaskSE3Equality & trackingTask =
3745
trackingTasks_.emplace_back("task-tracking-" + frame_name, robot_, frame_name);
3846
trackingTask.Kp(settings_.kp_feet_tracking * Eigen::VectorXd::Ones(6));
3947
trackingTask.Kd(2.0 * trackingTask.Kp().cwiseSqrt());
48+
trackingTask.setMask(position_mask);
4049
// Do not add tasks ; will be done in setTarget depending on desired contacts.
4150
feet_tracked_.push_back(false);
4251
trackingSamples_.emplace_back(12, 6);

tests/inverse-dynamics/centroidal.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,73 @@ BOOST_AUTO_TEST_CASE(CentroidalID_comTask)
342342
}
343343
}
344344

345+
BOOST_AUTO_TEST_CASE(CentroidalID_footTrackingTask)
346+
{
347+
CentroidalID::Settings settings;
348+
settings.kp_feet_tracking = 5.;
349+
settings.kp_posture = 0.1;
350+
settings.kp_contact = 1.0;
351+
settings.w_feet_tracking = 1e3;
352+
settings.w_posture = 1.0;
353+
settings.w_contact_force = 0.1;
354+
settings.contact_motion_equality = true;
355+
356+
TestCentroidalID test(getSoloHandler(), settings);
357+
358+
// Rotate the robot slightly so that it doesn't fall forward due to gravity
359+
test.q.segment<4>(3) << 0, -0.17, 0, 0.98;
360+
test.q.segment<4>(3) /= test.q.segment<4>(3).norm();
361+
362+
// Easy access
363+
const RobotModelHandler & model_handler = test.model_handler;
364+
RobotDataHandler & data_handler = test.data_handler;
365+
const int feet_nb = test.model_handler.getFeetNb();
366+
367+
// Set target
368+
data_handler.updateInternalData(test.q, test.dq, false);
369+
const Eigen::Vector3d com_target{data_handler.getData().com[0]};
370+
const Eigen::Vector3d com_vel{0., 0., 0.};
371+
CentroidalID::FeetPoseVector feet_pose_vec(feet_nb);
372+
CentroidalID::FeetVelocityVector feet_vel_vec(feet_nb);
373+
std::vector<bool> feet_contact(feet_nb);
374+
std::vector<CentroidalID::TargetContactForce> feet_force;
375+
for (int i = 0; i < feet_nb; i++)
376+
{
377+
feet_pose_vec[i] = data_handler.getFootPose(i);
378+
feet_vel_vec[i].setZero();
379+
feet_contact[i] = true;
380+
feet_force.push_back(CentroidalID::TargetContactForce::Zero(3));
381+
feet_force[i][2] = 9.81 * model_handler.getMass() / (feet_nb - 1);
382+
}
383+
384+
// Lift first foot (front right)
385+
feet_contact[0] = false;
386+
feet_pose_vec[0].translation()[0] -= 0.05; // Move foot 5 cm backward
387+
feet_pose_vec[0].translation()[1] += 0.05; // Move foot 5cm to the left (inside)
388+
feet_pose_vec[0].translation()[2] += 0.05; // Lift foot 5 cm higher
389+
390+
test.solver.setTarget(com_target, com_vel, feet_pose_vec, feet_vel_vec, feet_contact, feet_force);
391+
392+
const int N_STEP = 5000;
393+
for (int i = 0; i < N_STEP; i++)
394+
{
395+
// Solve
396+
test.step();
397+
398+
// Compute error
399+
data_handler.updateInternalData(test.q, test.dq, false);
400+
const Eigen::VectorXd delta_foot_pose =
401+
pinocchio::log6(feet_pose_vec[0].actInv(data_handler.getFootPose(0))).toVector().head<3>();
402+
const double error = delta_foot_pose.norm();
403+
404+
// Checks
405+
if (error > 1e-3) // If haven't converged yet, should be strictly decreasing
406+
BOOST_CHECK(test.is_error_decreasing("foot_pose", error));
407+
if (i > 9 * N_STEP / 10) // Should have converged by now
408+
BOOST_CHECK(error < 1e-3);
409+
}
410+
}
411+
345412
BOOST_AUTO_TEST_CASE(CentroidalID_allTasks)
346413
{
347414
CentroidalID::Settings settings;

0 commit comments

Comments
 (0)