cartesian-product-liegroups.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 INRIA
3 //
4 
10 
12 
13 #include <iostream>
14 #include <boost/test/unit_test.hpp>
15 #include <boost/utility/binary.hpp>
16 #include <boost/algorithm/string.hpp>
17 
18 using namespace pinocchio;
19 
20 namespace pinocchio
21 {
22  template<typename Derived>
23  std::ostream & operator<<(std::ostream & os, const LieGroupBase<Derived> & lg)
24  {
25  return os << lg.name();
26  }
27  template<typename LieGroupCollection>
28  std::ostream & operator<<(std::ostream & os, const LieGroupGenericTpl<LieGroupCollection> & lg)
29  {
30  return os << lg.name();
31  }
32 } // namespace pinocchio
33 
34 template<typename Scalar, int Options, template<typename S, int O> class LieGroupCollectionTpl>
36 {
37 
38  typedef LieGroupCollectionTpl<Scalar, Options> LieGroupCollection;
39 
41  typedef typename LieGroupGeneric::ConfigVector_t ConfigVector_t;
42  typedef typename LieGroupGeneric::TangentVector_t TangentVector_t;
43 
46 
47  template<typename Derived>
48  void operator()(const LieGroupBase<Derived> & lg) const
49  {
51  CartesianProduct cp(lg_generic);
52  test(lg, cp);
53 
54  CartesianProduct cp2;
55  cp2.append(lg);
56  BOOST_CHECK(cp == cp2);
57  }
58 
59  template<typename LieGroup>
60  static void test(const LieGroupBase<LieGroup> & lg, const CartesianProduct & cp)
61  {
62  BOOST_CHECK(lg.nq() == cp.nq());
63  BOOST_CHECK(lg.nv() == cp.nv());
64 
65  std::cout << "name: " << cp.name() << std::endl;
66 
67  BOOST_CHECK(lg.neutral() == cp.neutral());
68 
69  typedef typename LieGroup::ConfigVector_t ConfigVector;
70  typedef typename LieGroup::TangentVector_t TangentVector;
71  typedef typename LieGroup::JacobianMatrix_t JacobianMatrix;
72 
73  ConfigVector q0 = lg.random();
74  ConfigVector q1 = lg.random();
75  TangentVector v = TangentVector_t::Random(lg.nv());
78  ConfigVector qout_ref(lg.nq()), qout(lg.nq());
79  lg.integrate(q0, v, qout_ref);
80  cp.integrate(q0, v, qout);
82 
83  BOOST_CHECK(qout.isApprox(qout_ref));
84 
87  TangentVector v_diff_ref(lg.nv()), v_diff(lg.nv());
88  lg.difference(q0, q1, v_diff_ref);
89  cp.difference(q0, q1, v_diff);
91 
92  BOOST_CHECK(v_diff_ref.isApprox(v_diff));
93  BOOST_CHECK_EQUAL(lg.squaredDistance(q0, q1), cp.squaredDistance(q0, q1));
94  BOOST_CHECK_EQUAL(lg.distance(q0, q1), cp.distance(q0, q1));
95 
96  JacobianMatrix J_ref(JacobianMatrix::Zero(lg.nv(), lg.nv())),
97  J(JacobianMatrix::Zero(lg.nv(), lg.nv()));
98 
99  lg.dDifference(q0, q1, J_ref, ARG0);
100  cp.dDifference(q0, q1, J, ARG0);
101 
102  BOOST_CHECK(J.isApprox(J_ref));
103 
104  lg.dDifference(q0, q1, J_ref, ARG1);
105  cp.dDifference(q0, q1, J, ARG1);
106 
107  BOOST_CHECK(J.isApprox(J_ref));
108 
109  lg.dIntegrate(q0, v, J_ref, ARG0);
110  cp.dIntegrate(q0, v, J, ARG0);
111 
112  BOOST_CHECK(J.isApprox(J_ref));
113 
114  lg.dIntegrate(q0, v, J_ref, ARG1);
115  cp.dIntegrate(q0, v, J, ARG1);
116 
117  BOOST_CHECK(J.isApprox(J_ref));
118 
119  BOOST_CHECK(cp.isSameConfiguration(q0, q0));
122  ConfigVector q_rand;
123  cp.random(q_rand);
124  ConfigVector q_rand_copy = q_rand;
125 
126  lg.normalize(q_rand_copy);
127  cp.normalize(q_rand);
128  BOOST_CHECK(q_rand.isApprox(q_rand_copy));
129 
130  const ConfigVector lb(-ConfigVector::Ones(lg.nq()));
131  const ConfigVector ub(ConfigVector::Ones(lg.nq()));
132 
133  cp.randomConfiguration(lb, ub, q_rand);
135  }
136 };
137 
138 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
139 
140 BOOST_AUTO_TEST_CASE(test_cartesian_product_with_liegroup_variant)
141 {
142  boost::mpl::for_each<LieGroupCollectionDefault::LieGroupVariant::types>(
144 }
145 
146 BOOST_AUTO_TEST_CASE(test_cartesian_product_vs_cartesian_product_variant)
147 {
150 
153 
154  SE3 lg1;
155  Rn lg2;
156  typedef LieGroupGenericTpl<CP::LieGroupCollection> LieGroupGeneric;
157  LieGroupGeneric lg1_variant(lg1);
158  LieGroupGeneric lg2_variant(lg2);
159 
160  CP cartesian_product(lg1_variant, lg2_variant);
161  CP cartesian_product2(lg1_variant);
162  cartesian_product2.append(lg2_variant);
163  std::cout << "cartesian_product: " << cartesian_product << std::endl;
164 
165  BOOST_CHECK(cartesian_product == cartesian_product2);
166  CPRef cartesian_product_ref;
167 
169  cartesian_product_ref, cartesian_product);
170 }
171 
172 BOOST_AUTO_TEST_SUITE_END()
pinocchio::CartesianProductOperation
Definition: cartesian-product.hpp:40
cassie-simulation.qout
def qout
Definition: cassie-simulation.py:251
pinocchio::LieGroupGenericTpl
Definition: multibody/liegroup/fwd.hpp:13
pinocchio::CartesianProductOperationVariantTpl::append
void append(const LieGroupGeneric &lg)
Append a Lie group to the Cartesian product.
pinocchio::SpecialEuclideanOperationTpl
Definition: special-euclidean.hpp:25
TestCartesianProduct::ConfigVector_t
LieGroupGeneric::ConfigVector_t ConfigVector_t
Definition: cartesian-product-liegroups.cpp:41
TestCartesianProduct::CartesianProduct
CartesianProductOperationVariantTpl< Scalar, Options, LieGroupCollectionTpl > CartesianProduct
Definition: cartesian-product-liegroups.cpp:45
TestCartesianProduct::TangentVector_t
LieGroupGeneric::TangentVector_t TangentVector_t
Definition: cartesian-product-liegroups.cpp:42
pinocchio::LieGroupBase::dDifference
void dDifference(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1, const Eigen::MatrixBase< JacobianOut_t > &J) const
Computes the Jacobian of the difference operation with respect to q0 or q1.
test
def test(type SolverType)
TestCartesianProduct::test
static void test(const LieGroupBase< LieGroup > &lg, const CartesianProduct &cp)
Definition: cartesian-product-liegroups.cpp:60
cartesian-product.hpp
TestCartesianProduct::LieGroupGeneric
LieGroupGenericTpl< LieGroupCollection > LieGroupGeneric
Definition: cartesian-product-liegroups.cpp:40
pinocchio::SE3Tpl< context::Scalar, context::Options >
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_cartesian_product_with_liegroup_variant)
Definition: cartesian-product-liegroups.cpp:140
pinocchio::CartesianProductOperationVariantTpl
Dynamic Cartesian product composed of elementary Lie groups defined in LieGroupVariant.
Definition: cartesian-product-variant.hpp:20
PINOCCHIO_COMPILER_DIAGNOSTIC_POP
#define PINOCCHIO_COMPILER_DIAGNOSTIC_POP
Definition: include/pinocchio/macros.hpp:130
pinocchio::LieGroupBase::normalize
void normalize(const Eigen::MatrixBase< Config_t > &qout) const
Normalize the joint configuration given as input. For instance, the quaternion must be unitary.
inverse-kinematics-3d.J
J
Definition: inverse-kinematics-3d.py:28
pinocchio::ARG0
@ ARG0
Definition: fwd.hpp:123
PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED
#define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED
Definition: include/pinocchio/macros.hpp:134
pinocchio::LieGroupBase::name
std::string name() const
Get name of instance.
cartesian-product-variant.hpp
pinocchio::LieGroupGenericTpl::name
std::string name() const
Definition: liegroup-generic.hpp:92
pinocchio::LieGroupBase::derived
Derived & derived()
Definition: liegroup-base.hpp:707
joint-generic.hpp
pinocchio::LieGroupBase::nv
Index nv() const
Get dimension of Lie Group tangent space.
liegroup-generic.hpp
pinocchio::LieGroupBase::dIntegrate
void dIntegrate(const Eigen::MatrixBase< Config_t > &q, const Eigen::MatrixBase< Tangent_t > &v, const Eigen::MatrixBase< JacobianOut_t > &J, AssignmentOperatorType op=SETTO) const
Computes the Jacobian of a small variation of the configuration vector or the tangent vector into tan...
Definition: liegroup-base.hpp:112
pinocchio::ARG1
@ ARG1
Definition: fwd.hpp:124
pinocchio::LieGroupBase::neutral
ConfigVector_t neutral() const
Get neutral element as a vector.
pinocchio::LieGroupBase::random
void random(const Eigen::MatrixBase< Config_t > &qout) const
Generate a random joint configuration, normalizing quaternions when necessary.
pinocchio::q0
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > & q0
Definition: joint-configuration.hpp:1137
pinocchio::LieGroupBase::squaredDistance
Scalar squaredDistance(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1) const
Squared distance between two joint configurations.
PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
#define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
macros for pragma push/pop/ignore deprecated warnings
Definition: include/pinocchio/macros.hpp:129
TestCartesianProduct
Definition: cartesian-product-liegroups.cpp:35
pinocchio::operator<<
std::ostream & operator<<(std::ostream &os, const FrameTpl< Scalar, Options > &f)
Definition: multibody/frame.hpp:253
pinocchio::LieGroupBase
Definition: liegroup-base.hpp:44
collisions.cp
cp
Definition: collisions.py:51
pinocchio::v
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
Definition: joint-configuration.hpp:1084
pinocchio::LieGroupBase::integrate
void integrate(const Eigen::MatrixBase< ConfigIn_t > &q, const Eigen::MatrixBase< Tangent_t > &v, const Eigen::MatrixBase< ConfigOut_t > &qout) const
Integrate a joint's configuration with a tangent vector during one unit time duration.
liegroup.hpp
TestCartesianProduct::operator()
void operator()(const LieGroupBase< Derived > &lg) const
Definition: cartesian-product-liegroups.cpp:48
pinocchio::q1
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > const Eigen::MatrixBase< ConfigVectorIn2 > & q1
Definition: joint-configuration.hpp:1138
pinocchio::LieGroupBase::difference
void difference(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1, const Eigen::MatrixBase< Tangent_t > &v) const
Computes the tangent vector that must be integrated during one unit time to go from q0 to q1.
pinocchio::VectorSpaceOperationTpl
Definition: vector-space.hpp:16
liegroup-collection.hpp
pinocchio::LieGroupBase::nq
Index nq() const
pinocchio::SE3
SE3Tpl< context::Scalar, context::Options > SE3
Definition: spatial/fwd.hpp:64
pinocchio::LieGroupBase::distance
Scalar distance(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1) const
Distance between two configurations of the joint.
TestCartesianProduct::LieGroupCollection
LieGroupCollectionTpl< Scalar, Options > LieGroupCollection
Definition: cartesian-product-liegroups.cpp:38
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


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