Skip to content

Commit 4ce49aa

Browse files
author
earlaud
committed
Write ID contact test
1 parent 7836cca commit 4ce49aa

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/inverse_dynamics.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,70 @@ BOOST_AUTO_TEST_CASE(KinodynamicsID_postureTask)
5656
}
5757
}
5858

59+
BOOST_AUTO_TEST_CASE(KinodynamicsID_contact)
60+
{
61+
RobotModelHandler model_handler = getSoloHandler();
62+
RobotDataHandler data_handler(model_handler);
63+
64+
KinodynamicsID solver(
65+
model_handler, KinodynamicsID::Settings::Default()
66+
.set_w_base(10.0)
67+
.set_w_posture(1e-2)
68+
.set_w_contact_motion(1e-5)
69+
.set_w_contact_force(1.0));
70+
71+
const Eigen::VectorXd q_target = model_handler.getReferenceState().head(model_handler.getModel().nq);
72+
Eigen::VectorXd f_target = Eigen::VectorXd::Zero(4 * 3);
73+
f_target[2] = model_handler.getMass() * 9.81 / 4;
74+
f_target[5] = model_handler.getMass() * 9.81 / 4;
75+
f_target[8] = model_handler.getMass() * 9.81 / 4;
76+
f_target[11] = model_handler.getMass() * 9.81 / 4;
77+
78+
solver.setTarget(
79+
q_target, Eigen::VectorXd::Zero(model_handler.getModel().nv), Eigen::VectorXd::Zero(model_handler.getModel().nv),
80+
{true, true, true, true}, f_target);
81+
82+
double t = 0;
83+
double dt = 1e-3;
84+
Eigen::VectorXd q = pinocchio::randomConfiguration(model_handler.getModel());
85+
q.head(7) = q_target.head(7);
86+
Eigen::VectorXd v = Eigen::VectorXd::Random(model_handler.getModel().nv);
87+
Eigen::VectorXd a = Eigen::VectorXd::Random(model_handler.getModel().nv);
88+
Eigen::VectorXd tau = Eigen::VectorXd::Zero(model_handler.getModel().nv - 6);
89+
90+
// Let the robot stabilize
91+
const int N_STEP_ON_GROUND = 10000;
92+
const int N_STEP_FREE_FALL = 1000;
93+
for (int i = 0; i < N_STEP_ON_GROUND + N_STEP_FREE_FALL; i++)
94+
{
95+
// Solve and get solution
96+
solver.solve(t, q, v, tau);
97+
a = solver.getAccelerations();
98+
99+
// Integrate
100+
t += dt;
101+
q = pinocchio::integrate(model_handler.getModel(), q, (v + a / 2. * dt) * dt);
102+
v += a * dt;
103+
104+
if (i == N_STEP_ON_GROUND)
105+
{
106+
// Robot had time to reach permanent regime, is it stable on ground ?
107+
BOOST_CHECK_SMALL(a.head(3).norm(), 1e-8);
108+
BOOST_CHECK_SMALL(v.head(3).norm(), 1e-8);
109+
110+
// Remove contacts
111+
solver.setTarget(
112+
q_target, Eigen::VectorXd::Zero(model_handler.getModel().nv),
113+
Eigen::VectorXd::Zero(model_handler.getModel().nv), {false, false, false, false}, f_target);
114+
}
115+
if (i == N_STEP_ON_GROUND + N_STEP_FREE_FALL - 1)
116+
{
117+
// Robot had time to reach permanent regime, is it robot free falling ?
118+
BOOST_CHECK_SMALL((a.head(3) - model_handler.getModel().gravity.linear()).norm(), 0.1);
119+
}
120+
}
121+
}
122+
59123
BOOST_AUTO_TEST_CASE(KinodynamicsID_allTasks)
60124
{
61125
RobotModelHandler model_handler = getSoloHandler();

0 commit comments

Comments
 (0)