Skip to content

Commit ac5918e

Browse files
author
earlaud
committed
Properly test contacts
1 parent 145732f commit ac5918e

File tree

1 file changed

+67
-27
lines changed

1 file changed

+67
-27
lines changed

tests/inverse_dynamics.cpp

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
#include <boost/test/tools/old/interface.hpp>
33
#include <boost/test/unit_test.hpp>
4+
#include <pinocchio/algorithm/center-of-mass.hpp>
5+
#include <pinocchio/algorithm/frames.hpp>
46

57
#include "simple-mpc/inverse-dynamics.hpp"
68
#include "simple-mpc/robot-handler.hpp"
@@ -48,10 +50,14 @@ class TestKinoID
4850
solver.getAccelerations(ddq);
4951

5052
// Integrate
53+
step_i += 1;
5154
t += dt;
5255
q = pinocchio::integrate(model_handler.getModel(), q, (dq + ddq / 2. * dt) * dt);
5356
dq += ddq * dt;
5457

58+
// Update data handler
59+
data_handler.updateInternalData(q, dq, true);
60+
5561
// Check common to all tests
5662
check_joint_limits();
5763
}
@@ -92,6 +98,7 @@ class TestKinoID
9298
KinodynamicsID solver;
9399

94100
double t = 0.;
101+
int step_i = 0;
95102
Eigen::VectorXd q;
96103
Eigen::VectorXd dq;
97104
Eigen::VectorXd ddq;
@@ -132,59 +139,92 @@ BOOST_AUTO_TEST_CASE(KinodynamicsID_postureTask)
132139
}
133140
}
134141

135-
BOOST_AUTO_TEST_CASE(KinodynamicsID_contact)
142+
void test_contact(TestKinoID test)
136143
{
137-
TestKinoID test(
138-
getSoloHandler(), KinodynamicsID::Settings()
139-
.set_kp_posture(10.0)
140-
.set_kp_contact(10.0)
141-
.set_w_base(10.)
142-
.set_w_contact_motion(1.0)
143-
.set_w_contact_force(1.0));
144-
145144
// Easy access
146145
const RobotModelHandler & model_handler = test.model_handler;
146+
const RobotDataHandler & data_handler = test.data_handler;
147147
const size_t nq = model_handler.getModel().nq;
148148
const size_t nv = model_handler.getModel().nv;
149149

150150
// No need to set target as KinodynamicsID sets it by default to reference state
151151
const Eigen::VectorXd q_target = model_handler.getReferenceState().head(nq);
152152

153-
// Change initial state
154-
test.q = solo_q_start(model_handler);
155-
156153
// Let the robot stabilize
157-
const int N_STEP_ON_GROUND = 6000;
158-
const int N_STEP_FREE_FALL = 2000;
159-
for (int i = 0; i < N_STEP_ON_GROUND + N_STEP_FREE_FALL; i++)
154+
const int N_STEP = 500;
155+
while (test.step_i < N_STEP)
160156
{
161157
// Solve
162158
test.step();
163159

164-
if (i == N_STEP_ON_GROUND)
160+
for (int i = 0; i < test.q.size(); i++)
165161
{
166-
// Robot had time to reach permanent regime, is it stable on ground ?
167-
BOOST_CHECK_SMALL(test.dq.head(3).norm(), 1e-4);
168-
BOOST_CHECK_SMALL(test.ddq.head(3).norm(), 1e-4);
169-
170-
// Remove contacts
171-
test.solver.setTarget(
172-
q_target, Eigen::VectorXd::Zero(nv), Eigen::VectorXd::Zero(nv), {false, false, false, false}, {});
162+
std::cout << test.q[i] << " ";
173163
}
174-
if (i == N_STEP_ON_GROUND + N_STEP_FREE_FALL - 1)
164+
std::cout << std::endl;
165+
166+
// Check that contact velocity is null
167+
for (int foot_nb = 0; foot_nb < model_handler.getFeetNb(); foot_nb++)
175168
{
176-
// Robot had time to reach permanent regime, is it robot free falling ?
177-
BOOST_CHECK_SMALL(test.ddq.head(3).norm() - model_handler.getModel().gravity.linear().norm(), 0.01);
169+
const pinocchio::Motion foot_vel = pinocchio::getFrameVelocity(
170+
model_handler.getModel(), data_handler.getData(), model_handler.getFootFrameId(foot_nb), pinocchio::WORLD);
171+
BOOST_CHECK_LE(foot_vel.linear().norm(), 1e-2);
172+
if (model_handler.getFootType(foot_nb) == RobotModelHandler::FootType::QUAD)
173+
{
174+
// Rotation should also be null for quadrilateral contacts
175+
BOOST_CHECK_LE(foot_vel.angular().norm(), 1e-1);
176+
}
178177
}
179178
}
180179
}
181180

181+
BOOST_AUTO_TEST_CASE(KinodynamicsID_contactPoint_cost)
182+
{
183+
TestKinoID simu(
184+
getSoloHandler(), KinodynamicsID::Settings()
185+
.set_kp_base(1.0)
186+
.set_kp_contact(10.0)
187+
.set_w_base(1.)
188+
.set_w_contact_motion(10.0)
189+
.set_w_contact_force(1.0));
190+
simu.q = solo_q_start(simu.model_handler); // Set initial configuration
191+
test_contact(simu);
192+
}
193+
194+
BOOST_AUTO_TEST_CASE(KinodynamicsID_contactPoint_equality)
195+
{
196+
TestKinoID simu(
197+
getSoloHandler(), KinodynamicsID::Settings()
198+
.set_kp_base(1.0)
199+
.set_kp_contact(10.0)
200+
.set_w_base(1.)
201+
.set_w_contact_motion(10.0)
202+
.set_w_contact_force(1.0)
203+
.set_contact_motion_equality(true));
204+
simu.q = solo_q_start(simu.model_handler); // Set initial configuration
205+
test_contact(simu);
206+
}
207+
208+
BOOST_AUTO_TEST_CASE(KinodynamicsID_contactQuad_equality)
209+
{
210+
TestKinoID simu(
211+
getTalosModelHandler(), KinodynamicsID::Settings()
212+
.set_kp_base(1.0)
213+
.set_kp_posture(1.)
214+
.set_kp_contact(10.0)
215+
.set_w_base(1.)
216+
.set_w_posture(0.1)
217+
.set_w_contact_motion(10.0)
218+
.set_contact_motion_equality(true));
219+
test_contact(simu);
220+
}
221+
182222
BOOST_AUTO_TEST_CASE(KinodynamicsID_baseTask)
183223
{
184224
TestKinoID test(
185225
getSoloHandler(), KinodynamicsID::Settings()
186226
.set_kp_base(7.)
187-
.set_kp_contact(10.0)
227+
.set_kp_contact(.1)
188228
.set_w_base(100.0)
189229
.set_w_contact_force(1.0)
190230
.set_w_contact_motion(1.0));

0 commit comments

Comments
 (0)