joint-mimic.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019 INRIA
3 //
4 
7 
8 #include <boost/test/unit_test.hpp>
9 #include <boost/utility/binary.hpp>
10 
11 using namespace pinocchio;
12 
13 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
14 
15 typedef Eigen::Matrix<double, 6, Eigen::Dynamic> Matrix6x;
16 
17 template<typename JointModel>
19 {
20  typedef typename traits<JointModel>::JointDerived Joint;
21  typedef typename traits<Joint>::Constraint_t ConstraintType;
23  typedef ScaledJointMotionSubspace<ConstraintType> ScaledJointMotionSubspaceType;
24 
25  JointData jdata = jmodel.createData();
26 
27  const double scaling_factor = 2.;
28  ConstraintType constraint_ref(jdata.S), constraint_ref_shared(jdata.S);
29  ScaledJointMotionSubspaceType scaled_constraint(constraint_ref_shared, scaling_factor);
30 
31  BOOST_CHECK(constraint_ref.nv() == scaled_constraint.nv());
32 
33  typedef typename JointModel::TangentVector_t TangentVector_t;
34  TangentVector_t v = TangentVector_t::Random();
35 
36  Motion m = scaled_constraint * v;
37  Motion m_ref = scaling_factor * (Motion)(constraint_ref * v);
38 
39  BOOST_CHECK(m.isApprox(m_ref));
40 
41  {
42  SE3 M = SE3::Random();
43  typename ScaledJointMotionSubspaceType::DenseBase S = M.act(scaled_constraint);
44  typename ScaledJointMotionSubspaceType::DenseBase S_ref =
45  scaling_factor * M.act(constraint_ref);
46 
47  BOOST_CHECK(S.isApprox(S_ref));
48  }
49 
50  {
51  typename ScaledJointMotionSubspaceType::DenseBase S = scaled_constraint.matrix();
52  typename ScaledJointMotionSubspaceType::DenseBase S_ref =
53  scaling_factor * constraint_ref.matrix();
54 
55  BOOST_CHECK(S.isApprox(S_ref));
56  }
57 
58  {
60  typename ScaledJointMotionSubspaceType::DenseBase S = v.cross(scaled_constraint);
61  typename ScaledJointMotionSubspaceType::DenseBase S_ref =
62  scaling_factor * v.cross(constraint_ref);
63 
64  BOOST_CHECK(S.isApprox(S_ref));
65  }
66 
67  // Test transpose operations
68  {
69  const Eigen::DenseIndex dim = 20;
70  const Matrix6x Fin = Matrix6x::Random(6, dim);
71  Eigen::MatrixXd Fout = scaled_constraint.transpose() * Fin;
72  Eigen::MatrixXd Fout_ref = scaling_factor * (constraint_ref.transpose() * Fin);
73  BOOST_CHECK(Fout.isApprox(Fout_ref));
74 
75  Force force_in(Force::Random());
76  Eigen::MatrixXd Stf = (scaled_constraint.transpose() * force_in);
77  Eigen::MatrixXd Stf_ref = scaling_factor * (constraint_ref.transpose() * force_in);
78  BOOST_CHECK(Stf_ref.isApprox(Stf));
79  }
80 
81  // CRBA Y*S
82  {
84  Eigen::MatrixXd YS = Y * scaled_constraint;
85  Eigen::MatrixXd YS_ref = scaling_factor * (Y * constraint_ref);
86 
87  BOOST_CHECK(YS.isApprox(YS_ref));
88  }
89 }
90 
92 {
93 
94  template<typename JointModel>
96  {
97  JointModel jmodel;
98  jmodel.setIndexes(0, 0, 0);
99 
100  test_constraint_mimic(jmodel);
101  }
102 
104  {
105  JointModelRevoluteUnaligned jmodel(1.5, 1., 0.);
106  jmodel.setIndexes(0, 0, 0);
107 
108  test_constraint_mimic(jmodel);
109  }
110 
112  {
113  JointModelPrismaticUnaligned jmodel(1.5, 1., 0.);
114  jmodel.setIndexes(0, 0, 0);
115 
116  test_constraint_mimic(jmodel);
117  }
118 };
119 
120 BOOST_AUTO_TEST_CASE(test_constraint)
121 {
122  using namespace pinocchio;
123  typedef boost::variant<
127  Variant;
128 
129  boost::mpl::for_each<Variant::types>(TestJointConstraint());
130 }
131 
132 template<typename JointModel>
134 {
135  typedef typename traits<JointModel>::JointDerived Joint;
137 
138  JointData jdata = jmodel.createData();
139 
140  const double scaling_factor = 1.;
141  const double offset = 0.;
142 
143  typedef JointMimic<Joint> JointMimicType;
144  typedef typename traits<JointMimicType>::JointModelDerived JointModelMimicType;
145  typedef typename traits<JointMimicType>::JointDataDerived JointDataMimicType;
146 
147  // test constructor
148  JointModelMimicType jmodel_mimic(jmodel.derived(), scaling_factor, offset);
149  JointDataMimicType jdata_mimic = jmodel_mimic.createData();
150 
151  BOOST_CHECK(jmodel_mimic.nq() == 0);
152  BOOST_CHECK(jmodel_mimic.nv() == 0);
153 
154  BOOST_CHECK(jmodel_mimic.idx_q() == jmodel.idx_q());
155  BOOST_CHECK(jmodel_mimic.idx_v() == jmodel.idx_v());
156 
157  BOOST_CHECK(jmodel_mimic.idx_q() == 0);
158  BOOST_CHECK(jmodel_mimic.idx_v() == 0);
159 
160  typedef typename JointModelMimicType::ConfigVector_t ConfigVectorType;
161  typedef typename LieGroup<JointModel>::type LieGroupType;
162  ConfigVectorType q0 =
163  LieGroupType().randomConfiguration(-ConfigVectorType::Ones(), ConfigVectorType::Ones());
164 
165  jmodel.calc(jdata, q0);
166  jmodel_mimic.calc(jdata_mimic, q0);
167 
168  BOOST_CHECK(((SE3)jdata.M).isApprox((SE3)jdata_mimic.M()));
169  BOOST_CHECK(jdata.S.matrix().isApprox(jdata_mimic.S.matrix()));
170 
171  typedef typename JointModelMimicType::TangentVector_t TangentVectorType;
172 
173  q0 = LieGroupType().randomConfiguration(-ConfigVectorType::Ones(), ConfigVectorType::Ones());
174  TangentVectorType v0 = TangentVectorType::Random();
175  jmodel.calc(jdata, q0, v0);
176  jmodel_mimic.calc(jdata_mimic, q0, v0);
177 
178  BOOST_CHECK(((SE3)jdata.M).isApprox((SE3)jdata_mimic.M()));
179  BOOST_CHECK(jdata.S.matrix().isApprox(jdata_mimic.S.matrix()));
180  BOOST_CHECK(((Motion)jdata.v).isApprox((Motion)jdata_mimic.v()));
181 }
182 
184 {
185 
186  template<typename JointModel>
188  {
189  JointModel jmodel;
190  jmodel.setIndexes(0, 0, 0);
191 
192  test_joint_mimic(jmodel);
193  }
194 
196  {
197  JointModelRevoluteUnaligned jmodel(1.5, 1., 0.);
198  jmodel.setIndexes(0, 0, 0);
199 
200  test_joint_mimic(jmodel);
201  }
202 
204  {
205  JointModelPrismaticUnaligned jmodel(1.5, 1., 0.);
206  jmodel.setIndexes(0, 0, 0);
207 
208  test_joint_mimic(jmodel);
209  }
210 };
211 
213 {
214  using namespace pinocchio;
215  typedef boost::variant<
219  Variant;
220 
221  boost::mpl::for_each<Variant::types>(TestJointMimic());
222 }
223 
224 BOOST_AUTO_TEST_CASE(test_transform_linear_affine)
225 {
226  typedef JointModelRX::ConfigVector_t ConfigVectorType;
227  double scaling = 1., offset = 0.;
228 
229  ConfigVectorType q0 = ConfigVectorType::Random();
230  ConfigVectorType q1;
231  LinearAffineTransform::run(q0, scaling, offset, q1);
232  BOOST_CHECK(q0 == q1);
233 
234  offset = 2.;
235  LinearAffineTransform::run(ConfigVectorType::Zero(), scaling, offset, q1);
236  BOOST_CHECK(q1 == ConfigVectorType::Constant(offset));
237 }
238 
239 BOOST_AUTO_TEST_CASE(test_transform_linear_revolute)
240 {
241  typedef JointModelRUBX::ConfigVector_t ConfigVectorType;
242  double scaling = 1., offset = 0.;
243 
244  ConfigVectorType q0 = ConfigVectorType::Random().normalized();
245  ConfigVectorType q1;
246  UnboundedRevoluteAffineTransform::run(q0, scaling, offset, q1);
247  BOOST_CHECK(q0.isApprox(q1));
248 
249  offset = 2.;
250  UnboundedRevoluteAffineTransform::run(ConfigVectorType::Zero(), scaling, offset, q1);
251  BOOST_CHECK(q1 == ConfigVectorType(math::cos(offset), math::sin(offset)));
252 }
253 
254 BOOST_AUTO_TEST_CASE(test_joint_generic_cast)
255 {
256  JointModelRX jmodel_ref;
257  jmodel_ref.setIndexes(1, 2, 3);
258 
259  JointModelMimic<JointModelRX> jmodel(jmodel_ref, 2., 1.);
260  jmodel.setIndexes(1, -1, -1);
261 
262  BOOST_CHECK(jmodel.id() == jmodel_ref.id());
263  BOOST_CHECK(jmodel.idx_q() == jmodel_ref.idx_q());
264  BOOST_CHECK(jmodel.idx_v() == jmodel_ref.idx_v());
265 
266  JointModel jmodel_generic(jmodel);
267  jmodel_generic.setIndexes(1, -2, -2);
268 
269  BOOST_CHECK(jmodel_generic.id() == jmodel_ref.id());
270 }
271 BOOST_AUTO_TEST_SUITE_END()
pinocchio::InertiaTpl< context::Scalar, context::Options >
pinocchio::JointModelRevoluteUnalignedTpl::setIndexes
void setIndexes(JointIndex id, int q, int v)
Definition: joint-model-base.hpp:186
pinocchio::JointModelBase::createData
JointDataDerived createData() const
Definition: joint-model-base.hpp:91
pinocchio::JointDataTpl::v
Motion_t v() const
Definition: joint-generic.hpp:131
pinocchio::JointModelMimic::idx_q
int idx_q() const
Definition: joint-model-base.hpp:160
Eigen
pinocchio::JointModelRevoluteTpl::idx_q
int idx_q() const
Definition: joint-model-base.hpp:160
test-cpp2pybind11.m
m
Definition: test-cpp2pybind11.py:25
pinocchio::ScaledJointMotionSubspace
Definition: joint-mimic.hpp:15
pinocchio::JointModelMimic
Definition: joint-mimic.hpp:307
TestJointMimic::operator()
void operator()(const JointModelBase< JointModel > &) const
Definition: joint-mimic.cpp:187
pinocchio::JointMimic
Definition: joint-mimic.hpp:305
meshcat-viewer.v0
int v0
Definition: meshcat-viewer.py:88
pinocchio::JointModelBase
Definition: joint-model-base.hpp:75
pinocchio::UnboundedRevoluteAffineTransform::run
static void run(const Eigen::MatrixBase< ConfigVectorIn > &q, const Scalar &scaling, const Scalar &offset, const Eigen::MatrixBase< ConfigVectorOut > &dest)
Definition: joint-revolute-unbounded.hpp:236
pinocchio::SE3Tpl< context::Scalar, context::Options >
pinocchio::JointModelRX
JointModelRevoluteTpl< context::Scalar, context::Options, 0 > JointModelRX
Definition: joint-revolute.hpp:873
pinocchio::JointDataTpl< context::Scalar >
pinocchio::Joint
JointTpl< context::Scalar > Joint
Definition: joint-generic.hpp:22
TestJointMimic
Definition: joint-mimic.cpp:183
pinocchio::JointModelRevoluteTpl::setIndexes
void setIndexes(JointIndex id, int q, int v)
Definition: joint-model-base.hpp:186
pinocchio::JointModelRY
JointModelRevoluteTpl< context::Scalar, context::Options, 1 > JointModelRY
Definition: joint-revolute.hpp:877
pinocchio::JointModelTpl::setIndexes
void setIndexes(JointIndex id, int nq, int nv)
Definition: joint-generic.hpp:414
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_constraint)
Definition: joint-mimic.cpp:120
simulation-contact-dynamics.S
S
Definition: simulation-contact-dynamics.py:80
pinocchio::JointData
JointDataTpl< context::Scalar > JointData
Definition: multibody/joint/fwd.hpp:162
TestJointConstraint
Definition: joint-mimic.cpp:91
TestJointConstraint::operator()
void operator()(const JointModelBase< JointModelRevoluteUnaligned > &) const
Definition: joint-mimic.cpp:103
joint-generic.hpp
pinocchio::Dynamic
const int Dynamic
Definition: fwd.hpp:140
pinocchio::JointModelTpl< context::Scalar >
pinocchio::ForceTpl
Definition: context/casadi.hpp:25
pinocchio::JointModelRZ
JointModelRevoluteTpl< context::Scalar, context::Options, 2 > JointModelRZ
Definition: joint-revolute.hpp:881
pinocchio::JointModelPY
JointModelPrismaticTpl< context::Scalar, context::Options, 1 > JointModelPY
Definition: joint-prismatic.hpp:781
test_joint_mimic
void test_joint_mimic(const JointModelBase< JointModel > &jmodel)
Definition: joint-mimic.cpp:133
pinocchio::q0
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > & q0
Definition: joint-configuration.hpp:1137
pinocchio::InertiaTpl< context::Scalar, context::Options >::Random
static InertiaTpl Random()
Definition: spatial/inertia.hpp:361
test_constraint_mimic
void test_constraint_mimic(const JointModelBase< JointModel > &jmodel)
Definition: joint-mimic.cpp:18
pinocchio::JointModelRevoluteTpl::idx_v
int idx_v() const
Definition: joint-model-base.hpp:164
M
M
pinocchio::JointDataTpl::S
Constraint_t S() const
Definition: joint-generic.hpp:123
pinocchio::MotionTpl::Random
static MotionTpl Random()
Definition: motion-tpl.hpp:140
pinocchio::JointModelRevoluteTpl
Definition: multibody/joint/fwd.hpp:33
pinocchio::Motion
MotionTpl<::CppAD::AD< double >, 0 > Motion
Definition: context/cppad.hpp:37
pinocchio::ForceTpl::Random
static ForceTpl Random()
Definition: force-tpl.hpp:114
pinocchio::JointModelPZ
JointModelPrismaticTpl< context::Scalar, context::Options, 2 > JointModelPZ
Definition: joint-prismatic.hpp:785
pinocchio::LinearAffineTransform::run
static void run(const Eigen::MatrixBase< ConfigVectorIn > &q, const Scalar &scaling, const Scalar &offset, const Eigen::MatrixBase< ConfigVectorOut > &dest)
Definition: joint-common-operations.hpp:53
pinocchio::JointModelRUBX
JointModelRevoluteUnboundedTpl< context::Scalar, context::Options, 0 > JointModelRUBX
Definition: joint-revolute-unbounded.hpp:264
Matrix6x
Eigen::Matrix< double, 6, Eigen::Dynamic > Matrix6x
Definition: joint-mimic.cpp:15
pinocchio::JointModelBase::idx_v
int idx_v() const
Definition: joint-model-base.hpp:164
pinocchio::v
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
Definition: joint-configuration.hpp:1084
pinocchio::JointModelMimic::id
JointIndex id() const
Definition: joint-model-base.hpp:168
TestJointMimic::operator()
void operator()(const JointModelBase< JointModelPrismaticUnaligned > &) const
Definition: joint-mimic.cpp:203
pinocchio::JointModelRevoluteUnalignedTpl
Definition: multibody/joint/fwd.hpp:38
pinocchio::JointModelPrismaticUnalignedTpl
Definition: multibody/joint/fwd.hpp:94
pinocchio::JointModelBase::idx_q
int idx_q() const
Definition: joint-model-base.hpp:160
pinocchio::SE3Tpl::Random
static SE3Tpl Random()
Definition: spatial/se3-tpl.hpp:154
TestJointConstraint::operator()
void operator()(const JointModelBase< JointModel > &) const
Definition: joint-mimic.cpp:95
liegroup.hpp
pinocchio::JointModelBase::calc
void calc(JointDataDerived &data, const Eigen::MatrixBase< ConfigVectorType > &qs) const
Definition: joint-model-base.hpp:107
pinocchio::JointModelPrismaticUnalignedTpl::setIndexes
void setIndexes(JointIndex id, int q, int v)
Definition: joint-model-base.hpp:186
pinocchio::q1
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > const Eigen::MatrixBase< ConfigVectorIn2 > & q1
Definition: joint-configuration.hpp:1138
Y
Y
pinocchio::JointModelPX
JointModelPrismaticTpl< context::Scalar, context::Options, 0 > JointModelPX
Definition: joint-prismatic.hpp:777
pinocchio::traits
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:71
pinocchio::VectorSpaceOperationTpl
Definition: vector-space.hpp:16
pinocchio::JointModelRevoluteUnaligned
JointModelRevoluteUnalignedTpl< context::Scalar > JointModelRevoluteUnaligned
Definition: multibody/joint/fwd.hpp:38
TestJointMimic::operator()
void operator()(const JointModelBase< JointModelRevoluteUnaligned > &) const
Definition: joint-mimic.cpp:195
dim
int dim
TestJointConstraint::operator()
void operator()(const JointModelBase< JointModelPrismaticUnaligned > &) const
Definition: joint-mimic.cpp:111
pinocchio::JointModelPrismaticUnaligned
JointModelPrismaticUnalignedTpl< context::Scalar > JointModelPrismaticUnaligned
Definition: multibody/joint/fwd.hpp:94
pinocchio::MotionTpl
Definition: context/casadi.hpp:27
pinocchio::JointModelMimic::idx_v
int idx_v() const
Definition: joint-model-base.hpp:164
pinocchio::JointModelRevoluteUnboundedTpl
Definition: multibody/joint/fwd.hpp:55
pinocchio::JointDataTpl::M
Transformation_t M() const
Definition: joint-generic.hpp:127
pinocchio::JointModelMimic::setIndexes
void setIndexes(JointIndex id, int q, int v)
Definition: joint-model-base.hpp:186
pinocchio::JointModelBase::derived
JointModelDerived & derived()
Definition: joint-model-base.hpp:82
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
pinocchio::JointModelRUBY
JointModelRevoluteUnboundedTpl< context::Scalar, context::Options, 1 > JointModelRUBY
Definition: joint-revolute-unbounded.hpp:268
pinocchio::JointModelRevoluteTpl::id
JointIndex id() const
Definition: joint-model-base.hpp:168


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:10