Skip to content

Commit 756e40e

Browse files
committed
Add test on centroidalID com task
1 parent 9b72b70 commit 756e40e

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/inverse-dynamics/centroidal.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,60 @@ BOOST_AUTO_TEST_CASE(CentroidalID_baseTask)
288288
}
289289
}
290290

291+
BOOST_AUTO_TEST_CASE(CentroidalID_comTask)
292+
{
293+
CentroidalID::Settings settings;
294+
settings.kp_com = 7.;
295+
settings.kp_contact = .1;
296+
settings.w_com = 100.0;
297+
settings.w_contact_force = 1.0;
298+
settings.w_contact_motion = 1.0;
299+
300+
TestCentroidalID test(getSoloHandler(), settings);
301+
test.q = solo_q_start(test.model_handler);
302+
303+
// Easy access
304+
const RobotModelHandler & model_handler = test.model_handler;
305+
RobotDataHandler & data_handler = test.data_handler;
306+
const int feet_nb = test.model_handler.getFeetNb();
307+
308+
// Set target
309+
const Eigen::Vector3d com_target{-0.01, -0.01, 0.15};
310+
const Eigen::Vector3d com_vel{0., 0., 0.};
311+
data_handler.updateInternalData(test.q, test.dq, false);
312+
CentroidalID::FeetPoseVector feet_pose_vec(feet_nb);
313+
CentroidalID::FeetVelocityVector feet_vel_vec(feet_nb);
314+
std::vector<bool> feet_contact(feet_nb);
315+
std::vector<CentroidalID::TargetContactForce> feet_force;
316+
for (int i = 0; i < feet_nb; i++)
317+
{
318+
feet_pose_vec[i] = data_handler.getFootPose(i);
319+
feet_vel_vec[i].setZero();
320+
feet_contact[i] = true;
321+
feet_force.push_back(CentroidalID::TargetContactForce::Zero(3));
322+
feet_force[i][2] = 9.81 * model_handler.getMass() / feet_nb;
323+
}
324+
test.solver.setTarget(com_target, com_vel, feet_pose_vec, feet_vel_vec, feet_contact, feet_force);
325+
326+
const int N_STEP = 5000;
327+
for (int i = 0; i < N_STEP; i++)
328+
{
329+
// Solve
330+
test.step();
331+
332+
// Compute error
333+
data_handler.updateInternalData(test.q, test.dq, false);
334+
const Eigen::VectorXd delta_position = data_handler.getData().com[0] - com_target;
335+
const double error = delta_position.norm();
336+
337+
// Checks
338+
if (error > 1e-3) // If haven't converged yet, should be strictly decreasing
339+
BOOST_CHECK(test.is_error_decreasing("com_position", error));
340+
if (i > 9 * N_STEP / 10) // Should have converged by now
341+
BOOST_CHECK(error < 1e-3);
342+
}
343+
}
344+
291345
BOOST_AUTO_TEST_CASE(CentroidalID_allTasks)
292346
{
293347
CentroidalID::Settings settings;

0 commit comments

Comments
 (0)