20 #include <boost/test/unit_test.hpp>
21 #include <boost/utility/binary.hpp>
35 #include <pinocchio/parsers/srdf.hpp>
41 using namespace trajectories;
43 using namespace tasks;
45 using namespace Eigen;
48 #define REQUIRE_FINITE(A) BOOST_REQUIRE_MESSAGE(isFinite(A), #A << ": " << A)
58 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
61 cout <<
"\n\n*********** TEST TASK SE3 EQUALITY ***********\n";
64 string urdfFileName =
package_dirs[0] +
"/urdf/romeo.urdf";
68 TaskSE3Equality task(
"task-se3",
robot,
"RWristPitch");
70 VectorXd
Kp = VectorXd::Ones(6);
71 VectorXd
Kd = 2 * VectorXd::Ones(6);
74 BOOST_CHECK(task.Kp().isApprox(
Kp));
75 BOOST_CHECK(task.Kd().isApprox(
Kd));
78 TrajectoryBase *
traj =
new TrajectorySE3Constant(
"traj_SE3",
M_ref);
82 const double dt = 0.001;
86 VectorXd
v = VectorXd::Zero(
robot.nv());
92 const ConstraintBase &constraint = task.compute(
t,
q,
v,
data);
93 BOOST_CHECK(constraint.rows() == 6);
97 BOOST_REQUIRE(
isFinite(constraint.vector()));
102 BOOST_CHECK(MatrixXd::Identity(6, 6).
isApprox(constraint.matrix() *
Jpinv));
104 cout <<
"Jpinv" <<
Jpinv.transpose() << endl;
105 cout <<
"b" << constraint.vector().transpose() << endl;
115 error = task.position_error().norm();
116 BOOST_REQUIRE(
isFinite(task.position_error()));
121 cout <<
"Time " <<
t <<
"\t Pos error " <<
error <<
"\t Vel error "
122 << task.velocity_error().norm() << endl;
127 cout <<
"\n\n*********** TEST TASK COM EQUALITY ***********\n";
130 string urdfFileName =
package_dirs[0] +
"/urdf/romeo.urdf";
135 const string srdfFileName =
package_dirs[0] +
"/srdf/romeo_collision.srdf";
142 std::cout <<
"q: " <<
q.transpose() << std::endl;
147 TaskComEquality task(
"task-com",
robot);
149 VectorXd
Kp = VectorXd::Ones(3);
150 VectorXd
Kd = 2.0 * VectorXd::Ones(3);
153 BOOST_CHECK(task.Kp().isApprox(
Kp));
154 BOOST_CHECK(task.Kd().isApprox(
Kd));
158 TrajectoryBase *
traj =
new TrajectoryEuclidianConstant(
"traj_com",
com_ref);
162 const double dt = 0.001;
165 VectorXd
v = VectorXd::Zero(
robot.nv());
169 task.setReference(
sample);
170 const ConstraintBase &constraint = task.compute(
t,
q,
v,
data);
171 BOOST_CHECK(constraint.rows() == 3);
174 BOOST_REQUIRE(
isFinite(constraint.matrix()));
175 BOOST_REQUIRE(
isFinite(constraint.vector()));
180 BOOST_CHECK(MatrixXd::Identity(constraint.rows(), constraint.rows())
181 .isApprox(constraint.matrix() *
Jpinv));
190 error = task.position_error().norm();
191 BOOST_REQUIRE(
isFinite(task.position_error()));
195 if (
error < 1e-8)
break;
198 cout <<
"Time " <<
t <<
"\t CoM pos error " <<
error
199 <<
"\t CoM vel error " << task.velocity_error().norm() << endl;
204 cout <<
"\n\n*********** TEST TASK JOINT POSTURE ***********\n";
207 string urdfFileName =
package_dirs[0] +
"/urdf/romeo.urdf";
210 const unsigned int na =
robot.nv() - 6;
212 cout <<
"Gonna create task\n";
213 TaskJointPosture task(
"task-posture",
robot);
215 cout <<
"Gonna set gains\n" <<
na << endl;
216 VectorXd
Kp = VectorXd::Ones(
na);
217 VectorXd
Kd = 2.0 *
Kp;
220 BOOST_CHECK(task.Kp().isApprox(
Kp));
221 BOOST_CHECK(task.Kd().isApprox(
Kd));
223 cout <<
"Gonna create reference trajectory\n";
225 TrajectoryBase *
traj =
new TrajectoryEuclidianConstant(
"traj_joint",
q_ref);
228 cout <<
"Gonna set up for simulation\n";
230 const double dt = 0.001;
234 VectorXd
v = VectorXd::Zero(
robot.nv());
239 task.setReference(
sample);
240 const ConstraintBase &constraint = task.compute(
t,
q,
v,
data);
241 BOOST_CHECK(constraint.rows() ==
na);
244 BOOST_REQUIRE(
isFinite(constraint.matrix()));
245 BOOST_REQUIRE(
isFinite(constraint.vector()));
260 error = task.position_error().norm();
261 BOOST_REQUIRE(
isFinite(task.position_error()));
266 cout <<
"Time " <<
t <<
"\t pos error " <<
error <<
"\t vel error "
267 << task.velocity_error().norm() << endl;
272 cout <<
"\n\n*********** TEST TASK JOINT BOUNDS ***********\n";
275 string urdfFileName =
package_dirs[0] +
"/urdf/romeo.urdf";
278 const unsigned int na =
robot.nv() - 6;
279 const double dt = 0.001;
281 cout <<
"Gonna create task\n";
282 TaskJointBounds task(
"task-joint-bounds",
robot,
dt);
284 cout <<
"Gonna set limits\n" <<
na << endl;
285 VectorXd dq_max = VectorXd::Ones(
na);
286 VectorXd dq_min = -dq_max;
287 task.setVelocityBounds(dq_min, dq_max);
289 BOOST_CHECK(task.getVelocityLowerBounds().isApprox(dq_min));
290 BOOST_CHECK(task.getVelocityUpperBounds().isApprox(dq_max));
292 cout <<
"Gonna set up for simulation\n";
296 VectorXd
v = VectorXd::Zero(
robot.nv());
300 const ConstraintBase &constraint = task.compute(
t,
q,
v,
data);
304 BOOST_REQUIRE(
isFinite(constraint.lowerBound()));
305 BOOST_REQUIRE(
isFinite(constraint.upperBound()));
314 cout <<
"\n\n*********** TEST TASK JOINT POS VEL ACC BOUNDS ***********\n";
317 string urdfFileName =
package_dirs[0] +
"/urdf/romeo.urdf";
320 const unsigned int na =
robot.nv() - 6;
321 const double dt = 0.001;
323 cout <<
"Gonna create task\n";
324 TaskJointPosVelAccBounds task(
"task-joint-posVelAcc-bounds",
robot,
dt);
326 cout <<
"Gonna set limits\n" <<
na << endl;
327 VectorXd dq_max = VectorXd::Ones(
na);
328 VectorXd dq_min = -dq_max;
330 task.setPositionBounds(dq_min, dq_max);
331 task.setVelocityBounds(dq_max);
332 task.setAccelerationBounds(dq_max);
334 BOOST_CHECK(task.getPositionLowerBounds().isApprox(dq_min));
335 BOOST_CHECK(task.getPositionUpperBounds().isApprox(dq_max));
336 BOOST_CHECK(task.getVelocityBounds().isApprox(dq_max));
337 BOOST_CHECK(task.getAccelerationBounds().isApprox(dq_max));
339 cout <<
"Gonna set up for simulation\n";
343 VectorXd
v = VectorXd::Zero(
robot.nv());
347 const ConstraintBase &constraint = task.compute(
t,
q,
v,
data);
351 BOOST_REQUIRE(
isFinite(constraint.lowerBound()));
352 BOOST_REQUIRE(
isFinite(constraint.upperBound()));
360 BOOST_AUTO_TEST_SUITE_END()