5 #include "pinocchio/autodiff/cppad.hpp" 7 #include "pinocchio/multibody/joint/joint-generic.hpp" 8 #include "pinocchio/multibody/liegroup/liegroup.hpp" 9 #include "pinocchio/multibody/liegroup/liegroup-algo.hpp" 13 #include <boost/test/unit_test.hpp> 14 #include <boost/utility/binary.hpp> 16 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
21 using CppAD::NearEqual;
23 typedef AD<double> AD_double;
33 typedef Eigen::Matrix<AD_double,Eigen::Dynamic,1> VectorXAD;
34 typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> MatrixX;
37 typedef JointModelRXAD::ConfigVector_t ConfigVectorAD;
42 typedef JointModelRX::ConfigVector_t ConfigVector;
43 typedef JointModelRX::TangentVector_t TangentVector;
46 JointModelRX jmodel; jmodel.setIndexes(0,0,0);
47 JointDataRX jdata(jmodel.createData());
49 JointModelRXAD jmodel_ad = jmodel.cast<AD_double>();
50 JointDataRXAD jdata_ad(jmodel_ad.createData());
53 ConfigVector
q(jmodel.nq()); JointOperation().random(
q);
54 ConfigVectorAD q_ad(
q.cast<AD_double>());
57 jmodel_ad.calc(jdata_ad,q_ad);
62 BOOST_CHECK(M1.isApprox(M2.cast<
double>()));
65 TangentVector
v(TangentVector::Random(jmodel.nv()));
66 VectorXAD
X(jmodel_ad.nv());
68 for(Eigen::DenseIndex k = 0; k < jmodel.nv(); ++k)
72 CppAD::Independent(
X);
73 jmodel_ad.calc(jdata_ad,q_ad,
X);
74 jmodel.calc(jdata,
q,v);
76 MotionAD m_ad(jdata_ad.v);
78 ConstraintXd Sref(jdata.S.matrix());
80 for(Eigen::DenseIndex k = 0; k < 3; ++k)
82 Y[k+Motion::LINEAR] = m_ad.linear()[k];
83 Y[k+Motion::ANGULAR] = m_ad.angular()[k];
86 CppAD::ADFun<double> vjoint(
X,Y);
88 CPPAD_TESTVECTOR(
double)
x((
size_t)jmodel_ad.nv());
89 for(Eigen::DenseIndex k = 0; k < jmodel.nv(); ++k)
94 CPPAD_TESTVECTOR(
double) jac = vjoint.Jacobian(
x);
95 MatrixX S(6,jac.size()/6);
96 S = Eigen::Map<MatrixX>(jac.data(),S.rows(),S.cols());
98 BOOST_CHECK(m.isApprox(m_ad.cast<
double>()));
100 BOOST_CHECK(Sref.matrix().isApprox(S));
105 template<
typename Jo
intModel>
114 template<
typename Scalar,
int Options>
118 typedef typename JointModel::Vector3 Vector3;
119 JointModel jmodel(Vector3::Random().normalized());
120 jmodel.setIndexes(0,0,0);
125 template<
typename Scalar,
int Options>
129 typedef typename JointModel::Vector3 Vector3;
130 JointModel jmodel(Vector3::Random().normalized());
131 jmodel.setIndexes(0,0,0);
136 template<
typename Scalar,
int Options>
140 typedef typename JointModel::Vector3 Vector3;
141 JointModel jmodel(Vector3::Random().normalized());
142 jmodel.setIndexes(0,0,0);
147 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollection>
153 jmodel.setIndexes(0,0,0);
159 template<
typename Jo
intModel_>
165 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollection>
173 jmodel.setIndexes(0,0,0);
178 template<
typename Jo
intModel>
182 using CppAD::NearEqual;
185 typedef typename JointModel::JointDataDerived
JointData;
187 typedef AD<Scalar> AD_scalar;
195 typedef Eigen::Matrix<AD_scalar,Eigen::Dynamic,1> VectorXAD;
196 typedef Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic> MatrixX;
199 typedef typename JointModelAD::JointDataDerived JointDataAD;
201 typedef typename JointModelAD::ConfigVector_t ConfigVectorAD;
203 typedef typename JointModel::ConfigVector_t ConfigVector;
204 typedef typename JointModel::TangentVector_t TangentVector;
209 JointModelAD jmodel_ad = jmodel.template cast<AD_scalar>();
210 JointDataAD jdata_ad(jmodel_ad.createData());
213 ConfigVector
q(jmodel.
nq());
214 ConfigVector lb(ConfigVector::Constant(jmodel.
nq(),-1.));
215 ConfigVector ub(ConfigVector::Constant(jmodel.
nq(),1.));
217 typedef pinocchio::RandomConfigurationStep<pinocchio::LieGroupMap,ConfigVector,ConfigVector,ConfigVector> RandomConfigAlgo;
220 ConfigVectorAD q_ad(
q.template cast<AD_scalar>());
223 jmodel_ad.calc(jdata_ad,q_ad);
224 jmodel.
calc(jdata,
q);
226 SE3 M1(jdata_base.M());
227 SE3AD M2(jdata_ad_base.M());
228 BOOST_CHECK(M1.isApprox(M2.template cast<Scalar>()));
231 TangentVector
v(TangentVector::Random(jmodel.
nv()));
232 VectorXAD
X(jmodel_ad.nv());
234 for(Eigen::DenseIndex k = 0; k < jmodel.
nv(); ++k)
238 CppAD::Independent(
X);
239 jmodel_ad.calc(jdata_ad,q_ad,
X);
240 jmodel.
calc(jdata,
q,v);
242 MotionAD m_ad(jdata_ad_base.v());
243 Motion
m(jdata_base.v());
244 ConstraintXd Sref(jdata_base.S().matrix());
246 for(Eigen::DenseIndex k = 0; k < 3; ++k)
248 Y[k+Motion::LINEAR] = m_ad.linear()[k];
249 Y[k+Motion::ANGULAR] = m_ad.angular()[k];
252 CppAD::ADFun<Scalar> vjoint(
X,Y);
254 CPPAD_TESTVECTOR(Scalar)
x((
size_t)jmodel_ad.nv());
255 for(Eigen::DenseIndex k = 0; k < jmodel.
nv(); ++k)
260 CPPAD_TESTVECTOR(Scalar) jac = vjoint.Jacobian(
x);
261 MatrixX S(6,jac.size()/6);
262 S = Eigen::Map<typename PINOCCHIO_EIGEN_PLAIN_ROW_MAJOR_TYPE(MatrixX)>(jac.data(),S.rows(),S.cols());
264 BOOST_CHECK(
m.isApprox(m_ad.template cast<Scalar>()));
266 BOOST_CHECK(Sref.matrix().isApprox(S));
278 BOOST_AUTO_TEST_SUITE_END()
JointDataRevoluteTpl< double, 0, 0 > JointDataRX
JointDataTpl< double > JointData
static void test(const pinocchio::JointModelMimic< JointModel_ > &)
void operator()(const pinocchio::JointModelCompositeTpl< Scalar, Options, JointCollection > &) const
JointDataDerived createData() const
JointModelRevoluteTpl< double, 0, 1 > JointModelRY
void operator()(const pinocchio::JointModelRevoluteUnalignedTpl< Scalar, Options > &) const
void operator()(const pinocchio::JointModelPrismaticUnalignedTpl< Scalar, Options > &) const
MotionTpl< double, 0 > Motion
boost::variant< JointModelRX, JointModelRY, JointModelRZ, JointModelMimicRX, JointModelMimicRY, JointModelMimicRZ, JointModelFreeFlyer, JointModelPlanar, JointModelRevoluteUnaligned, JointModelSpherical, JointModelSphericalZYX, JointModelPX, JointModelPY, JointModelPZ, JointModelPrismaticUnaligned, JointModelTranslation, JointModelRUBX, JointModelRUBY, JointModelRUBZ, JointModelRevoluteUnboundedUnaligned, boost::recursive_wrapper< JointModelComposite > > JointModelVariant
JointModelDerived & derived()
void calc(JointDataDerived &data, const Eigen::MatrixBase< ConfigVectorType > &qs) const
void setIndexes(JointIndex id, int nq, int nv)
ConstraintTpl< Eigen::Dynamic, double, 0 > ConstraintXd
BOOST_AUTO_TEST_CASE(test_jointRX_motion_space)
JointModelTpl< double > JointModel
void operator()(const pinocchio::JointModelMimic< JointModel_ > &) const
JointCollectionDefault::JointModelVariant JointModelVariant
static void test(const pinocchio::JointModelBase< JointModel > &jmodel)
Type of the cast of a class C templated by Scalar and Options, to a new NewScalar type...
void operator()(const pinocchio::JointModelRevoluteUnboundedUnalignedTpl< Scalar, Options > &) const
JointModelRevoluteTpl< double, 0, 0 > JointModelRX
void operator()(const pinocchio::JointModelTpl< Scalar, Options, JointCollection > &) const
void operator()(const pinocchio::JointModelBase< JointModel > &) const