5 #include "pinocchio/multibody/model.hpp" 6 #include "pinocchio/multibody/data.hpp" 7 #include "pinocchio/algorithm/jacobian.hpp" 8 #include "pinocchio/algorithm/frames.hpp" 9 #include "pinocchio/algorithm/rnea.hpp" 10 #include "pinocchio/spatial/act-on-set.hpp" 11 #include "pinocchio/parsers/sample-models.hpp" 12 #include "pinocchio/utils/timer.hpp" 13 #include "pinocchio/algorithm/joint-configuration.hpp" 17 #include <boost/test/unit_test.hpp> 18 #include <boost/utility/binary.hpp> 20 template<
typename Derived>
21 inline bool isFinite(
const Eigen::MatrixBase<Derived> &
x)
23 return ((x - x).
array() == (x - x).
array()).all();
27 BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
36 for(Model::FrameVector::const_iterator it = model.
frames.begin();
37 it != model.
frames.end(); ++it)
39 const Frame & frame = *it;
40 BOOST_CHECK(frame == frame);
41 Frame frame_copy(frame);
42 BOOST_CHECK(frame_copy == frame);
45 std::ostringstream os;
47 BOOST_CHECK(!os.str().empty());
55 BOOST_CHECK(frame.
cast<
double>() == frame);
56 BOOST_CHECK(frame.
cast<
double>().cast<
long double>() == frame.
cast<
long double>());
61 using namespace Eigen;
67 const std::string & frame_name = std::string( model.
names[parent_idx]+
"_frame");
76 BOOST_CHECK(data.oMf[model.
getFrameId(frame_name)].isApprox(data.oMi[parent_idx]*framePlacement));
82 using namespace Eigen;
88 const std::string & frame_name = std::string( model.
names[parent_idx]+
"_frame");
102 BOOST_CHECK(data.oMf[frame_idx].isApprox(data_ref.oMf[frame_idx]));
107 using namespace Eigen;
113 const std::string & frame_name = std::string( model.
names[parent_idx]+
"_frame");
127 BOOST_CHECK(data.oMf[frame_idx].isApprox(data_ref.oMf[frame_idx]));
132 using namespace Eigen;
138 const std::string & frame_name = std::string( model.
names[parent_idx]+
"_frame");
150 BOOST_CHECK(vf.
isApprox(framePlacement.
actInv(data.v[parent_idx])));
159 BOOST_CHECK(data_ref.oMf[frame_idx].act(v_ref).isApprox(
getFrameVelocity(model,data,frame_idx,
WORLD)));
165 using namespace Eigen;
171 const std::string & frame_name = std::string( model.
names[parent_idx]+
"_frame");
184 BOOST_CHECK(af.
isApprox(framePlacement.
actInv(data.a[parent_idx])));
199 using namespace Eigen;
205 const std::string & frame_name = std::string( model.
names[parent_idx]+
"_frame");
220 Motion acc_classical_local = acc;
222 acc_classical_local.
linear() = linear;
226 BOOST_CHECK(af.
isApprox(acc_classical_local));
232 SE3 T_ref = data_ref.oMf[frame_idx];
236 Motion acc_classical_local_ref = a_ref;
238 acc_classical_local_ref.
linear() = linear;
244 Motion acc_classical_world_ref = T_ref.
act(a_ref);
245 linear = acc_classical_world_ref.
linear() + vel_world_ref.angular().cross(vel_world_ref.linear());
246 acc_classical_world_ref.
linear() = linear;
252 linear = acc_classical_aligned_ref.
linear() + vel_aligned_ref.angular().cross(vel_aligned_ref.linear());
253 acc_classical_aligned_ref.
linear() = linear;
260 using namespace Eigen;
282 v_local.
linear() = Vector3d(0.0, 1.0, 0.0);
283 v_local.
angular() = Vector3d(0.0, 0.0, 1.0);
286 v_world.
linear() = Vector3d::Zero();
287 v_world.
angular() = Vector3d(0.0, 0.0, 1.0);
290 v_align.
linear() = Vector3d(-1.0, 0.0, 0.0);
291 v_align.
angular() = Vector3d(0.0, 0.0, 1.0);
295 ac_local.
linear() = Vector3d(-1.0, 0.0, 0.0);
296 ac_local.
angular() = Vector3d::Zero();
301 ac_align.
linear() = Vector3d(0.0, -1.0, 0.0);
302 ac_align.
angular() = Vector3d::Zero();
328 using namespace Eigen;
334 const std::string & frame_name = std::string( model.
names[parent_idx]+
"_frame");
366 BOOST_CHECK(Jjj_from_frame.isApprox(Jjj));
373 BOOST_CHECK(Jff.isApprox(Jjj));
377 BOOST_CHECK(Jff2.isApprox(Jjj));
382 using namespace Eigen;
388 const std::string & frame_name = std::string( model.
names[parent_idx]+
"_frame");
414 BOOST_CHECK(Jf.isApprox(Jf_ref));
418 BOOST_CHECK(Jf2.isApprox(Jf_ref));
423 using namespace Eigen;
429 const std::string & frame_name = std::string( model.
names[parent_idx]+
"_frame");
451 Jf_ref =
SE3(data.oMf[idx].rotation(), Eigen::Vector3d::Zero()).toActionMatrix() * Jf_ref;
454 BOOST_CHECK(Jf.isApprox(Jf_ref));
458 BOOST_CHECK(Jf2.isApprox(Jf_ref));
463 using namespace Eigen;
469 const std::string & frame_name = std::string( model.
names[parent_idx]+
"_frame");
500 const Motion & v_ref = data_ref.oMf[idx].act(v_ref_local);
502 const SE3 & wMf =
SE3(data_ref.oMf[idx].rotation(),SE3::Vector3::Zero());
503 const Motion & v_ref_local_world_aligned = wMf.
act(v_ref_local);
508 const Motion & a_ref = data_ref.oMf[idx].act(a_ref_local);
509 const Motion & a_ref_local_world_aligned = wMf.
act(a_ref_local);
510 BOOST_CHECK(a_idx.isApprox(a_ref));
512 J.fill(0.); dJ.fill(0.);
517 v_idx = (Motion::Vector6)(J*v);
518 BOOST_CHECK(v_idx.
isApprox(v_ref_local));
520 a_idx = (Motion::Vector6)(J*a + dJ*v);
521 BOOST_CHECK(a_idx.isApprox(a_ref_local));
527 v_idx = (Motion::Vector6)(J*v);
528 BOOST_CHECK(v_idx.
isApprox(v_ref_local_world_aligned));
530 a_idx = (Motion::Vector6)(J*a + dJ*v);
531 BOOST_CHECK(a_idx.isApprox(a_ref_local_world_aligned));
535 Data data_ref(model), data_ref_plus(model);
537 const double alpha = 1e-8;
542 Data::Matrix6x J_ref_world(6,model.
nv), J_ref_local(6,model.
nv), J_ref_local_world_aligned(6,model.
nv);
543 J_ref_world.fill(0.); J_ref_local.fill(0.); J_ref_local_world_aligned.fill(0.);
546 const SE3 & oMf_q = data_ref.oMf[idx];
552 Data::Matrix6x J_ref_plus_world(6,model.
nv), J_ref_plus_local(6,model.
nv), J_ref_plus_local_world_aligned(6,model.
nv);
553 J_ref_plus_world.fill(0.); J_ref_plus_local.fill(0.); J_ref_plus_local_world_aligned.fill(0.);
556 const SE3 & oMf_q_plus = data_ref_plus.oMf[idx];
562 J_ref_plus_local = (oMf_q.
inverse()*oMf_q_plus).toActionMatrix()*(J_ref_plus_local);
567 J_ref_plus_local_world_aligned = oMf_translation.
toActionMatrix()*(J_ref_plus_local_world_aligned);
569 Data::Matrix6x dJ_ref_world(6,model.
nv), dJ_ref_local(6,model.
nv), dJ_ref_local_world_aligned(6,model.
nv);
570 dJ_ref_world.fill(0.); dJ_ref_local.fill(0.); dJ_ref_local_world_aligned.fill(0.);
571 dJ_ref_world = (J_ref_plus_world - J_ref_world)/alpha;
572 dJ_ref_local = (J_ref_plus_local - J_ref_local)/alpha;
573 dJ_ref_local_world_aligned = (J_ref_plus_local_world_aligned - J_ref_local_world_aligned)/alpha;
580 dJ_world.fill(0.); dJ_local.fill(0.); dJ_local_world_aligned.fill(0.);
585 BOOST_CHECK(dJ_world.isApprox(dJ_ref_world,sqrt(alpha)));
586 BOOST_CHECK(dJ_local.isApprox(dJ_ref_local,sqrt(alpha)));
587 BOOST_CHECK(dJ_local_world_aligned.isApprox(dJ_ref_local_world_aligned,sqrt(alpha)));
591 BOOST_AUTO_TEST_SUITE_END ()
Matrix6x dJ
Derivative of the Jacobian with respect to the time.
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
The WORLD frame convention corresponds to the frame concident with the Universe/Inertial frame but mo...
void computeFrameJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const FrameIndex frameId, const ReferenceFrame reference_frame, const Eigen::MatrixBase< Matrix6xLike > &J)
Computes the Jacobian of a specific Frame expressed in the desired reference_frame given as argument...
void integrate(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v, const Eigen::MatrixBase< ReturnType > &qout)
Integrate a configuration vector for the specified model for a tangent vector during one unit time...
A Plucker coordinate frame attached to a parent joint inside a kinematic tree.
bool isZero(const Eigen::MatrixBase< MatrixLike > &m, const typename MatrixLike::RealScalar &prec=Eigen::NumTraits< typename MatrixLike::Scalar >::dummy_precision())
int njoints
Number of joints.
std::vector< std::string > names
Name of joint i
MotionTpl< Scalar, Options > getFrameVelocity(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id, const ReferenceFrame rf=LOCAL)
Returns the spatial velocity of the Frame expressed in the desired reference frame. You must first call pinocchio::forwardKinematics to update placement and velocity values in data structure.
NewScalar cast(const Scalar &value)
ConfigVectorType lowerPositionLimit
Lower joint configuration limit.
FrameVector frames
Vector of operational frames registered on the model.
void randomConfiguration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &lowerLimits, const Eigen::MatrixBase< ConfigVectorIn2 > &upperLimits, const Eigen::MatrixBase< ReturnType > &qout)
Generate a configuration vector uniformly sampled among provided limits.
void getJointJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointIndex jointId, const ReferenceFrame rf, const Eigen::MatrixBase< Matrix6Like > &J)
Computes the Jacobian of a specific joint frame expressed either in the world (rf = WORLD) frame or i...
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
static void act(const Eigen::MatrixBase< Mat > &iV, const ForceDense< ForceDerived > &f, Eigen::MatrixBase< MatRet > const &jF)
Action of a motion set on a force object. The input motion set is represented by a 6xN matrix whose e...
MotionTpl< Scalar, Options > getFrameAcceleration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id, const ReferenceFrame rf=LOCAL)
Returns the spatial acceleration of the Frame expressed in the desired reference frame. You must first call pinocchio::forwardKinematics to update placement, velocity and acceleration values in data structure.
bool existJointName(const std::string &name) const
Check if a joint given by its name exists.
void forwardKinematics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Update the joint placements according to the current joint configuration.
ActionMatrixType toActionMatrix() const
The action matrix of .
SE3GroupAction< D >::ReturnType actInv(const D &d) const
by = aXb.actInv(ay)
pinocchio::FrameIndex FrameIndex
bool isApprox(const MotionDense< M2 > &m2, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision()) const
ConstLinearType linear() const
JointIndex addJoint(const JointIndex parent, const JointModel &joint_model, const SE3 &joint_placement, const std::string &joint_name)
Add a joint to the kinematic tree with infinite bounds.
SE3Tpl inverse() const
aXb = bXa.inverse()
bool isFinite(const Eigen::MatrixBase< Derived > &x)
const DataTpl< Scalar, Options, JointCollectionTpl >::SE3 & updateFramePlacement(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id)
Updates the placement of the given frame.
The LOCAL frame convention corresponds to the frame directly attached to the moving part (Joint...
JointModelRevoluteTpl< double, 0, 2 > JointModelRZ
MotionTpl< double, 0 > Motion
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix6x & computeJointJacobiansTimeVariation(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v)
Computes the full model Jacobian variations with respect to time. It corresponds to dJ/dt which depen...
BOOST_AUTO_TEST_CASE(frame_basic)
FrameIndex getFrameId(const std::string &name, const FrameType &type=(FrameType)(JOINT|FIXED_JOINT|BODY|OP_FRAME|SENSOR)) const
Returns the index of a frame given by its name.
bool existFrame(const std::string &name, const FrameType &type=(FrameType)(JOINT|FIXED_JOINT|BODY|OP_FRAME|SENSOR)) const
Checks if a frame given by its name exists.
bool isApprox_impl(const SE3Tpl< Scalar, O2 > &m2, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision()) const
ConstLinearRef translation() const
SE3GroupAction< D >::ReturnType act(const D &d) const
ay = aXb.act(by)
FrameIndex addFrame(const Frame &frame, const bool append_inertia=true)
Adds a frame to the kinematic tree. The inertia stored within the frame will be happened to the inert...
SE3 placement
Placement of the frame wrt the parent joint.
Main pinocchio namespace.
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix6x & computeJointJacobians(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the full model Jacobian, i.e. the stack of all motion subspace expressed in the world frame...
The LOCAL_WORLD_ALIGNED frame convention corresponds to the frame centered on the moving part (Joint...
int nv
Dimension of the velocity vector space.
JointIndex getJointId(const std::string &name) const
Return the index of a joint given by its name.
void updateFramePlacements(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Updates the position of each frame contained in the model.
void getFrameJacobianTimeVariation(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id, const ReferenceFrame rf, const Eigen::MatrixBase< Matrix6xLike > &dJ)
Computes the Jacobian time variation of a specific frame (given by frame_id) expressed either in the ...
void normalize(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &qout)
Normalize a configuration vector.
ConfigVectorType upperPositionLimit
Upper joint configuration limit.
ConstAngularType angular() const
void getFrameJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id, const ReferenceFrame rf, const Eigen::MatrixBase< Matrix6xLike > &J)
Returns the jacobian of the frame expressed either expressed in the LOCAL frame coordinate system or ...
void humanoidRandom(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a humanoid kinematic tree with 6-DOF limbs and random joint placements.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
Eigen::Matrix< Scalar, 6, Eigen::Dynamic, Options > Matrix6x
The 6d jacobian type (temporary)
JointCollectionTpl & model
int nq
Dimension of the configuration vector representation.
ConstAngularRef rotation() const
void framesForwardKinematics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
First calls the forwardKinematics on the model, then computes the placement of each frame...
MotionTpl< Scalar, Options > getFrameClassicalAcceleration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const FrameIndex frame_id, const ReferenceFrame rf=LOCAL)
Returns the "classical" acceleration of the Frame expressed in the desired reference frame...
FrameTpl< NewScalar, Options > cast() const
void fill(Eigen::Ref< MatType > mat, const typename MatType::Scalar &value)