pinocchio  2.4.5
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
cppad.hpp
1 //
2 // Copyright (c) 2018-2020 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_autodiff_ccpad_hpp__
6 #define __pinocchio_autodiff_ccpad_hpp__
7 
8 #include "pinocchio/math/fwd.hpp"
9 
10 // Do not include this file directly.
11 // Copy and use directly the intructions from <cppad/example/cppad_eigen.hpp>
12 // to avoid redifinition of EIGEN_MATRIXBASE_PLUGIN for Eigen 3.3.0 and later
13 //#include <cppad/example/cppad_eigen.hpp>
14 
15 #ifdef PINOCCHIO_CPPAD_REQUIRES_MATRIX_BASE_PLUGIN
16  #define EIGEN_MATRIXBASE_PLUGIN <cppad/example/eigen_plugin.hpp>
17 #endif
18 
19 #include <cppad/cppad.hpp>
20 #include <Eigen/Dense>
21 
22 namespace boost
23 {
24  namespace math
25  {
26  namespace constants
27  {
28  namespace detail
29  {
30  template<typename Scalar>
31  struct constant_pi< CppAD::AD<Scalar> > : constant_pi<Scalar>
32  {
33  typedef CppAD::AD<Scalar> ADScalar;
34 
35  template <int N>
36  static inline ADScalar get(const mpl::int_<N>& n)
37  {
38  return ADScalar(constant_pi<Scalar>::get(n));
39  }
40 
41  };
42  }
43  }
44  }
45 }
46 
47 namespace Eigen
48 {
49  namespace internal
50  {
51  // Specialization of Eigen::internal::cast_impl for CppAD input types
52  template<typename Scalar>
53  struct cast_impl<CppAD::AD<Scalar>,Scalar>
54  {
55 #if EIGEN_VERSION_AT_LEAST(3,2,90)
56  EIGEN_DEVICE_FUNC
57 #endif
58  static inline Scalar run(const CppAD::AD<Scalar> & x)
59  {
60  return CppAD::Value(x);
61  }
62  };
63  }
64 } //namespace Eigen
65 
66 // Source from #include <cppad/example/cppad_eigen.hpp>
67 namespace Eigen
68 {
69  template <class Base> struct NumTraits< CppAD::AD<Base> >
70  { // type that corresponds to the real part of an AD<Base> value
71  typedef CppAD::AD<Base> Real;
72  // type for AD<Base> operations that result in non-integer values
73  typedef CppAD::AD<Base> NonInteger;
74  // type to use for numeric literals such as "2" or "0.5".
75  typedef CppAD::AD<Base> Literal;
76  // type for nested value inside an AD<Base> expression tree
77  typedef CppAD::AD<Base> Nested;
78 
79  enum {
80  // does not support complex Base types
81  IsComplex = 0 ,
82  // does not support integer Base types
83  IsInteger = 0 ,
84  // only support signed Base types
85  IsSigned = 1 ,
86  // must initialize an AD<Base> object
87  RequireInitialization = 1 ,
88  // computational cost of the corresponding operations
89  ReadCost = 1 ,
90  AddCost = 2 ,
91  MulCost = 2
92  };
93 
94  // machine epsilon with type of real part of x
95  // (use assumption that Base is not complex)
96  static CppAD::AD<Base> epsilon(void)
97  { return CppAD::numeric_limits< CppAD::AD<Base> >::epsilon(); }
98 
99  // relaxed version of machine epsilon for comparison of different
100  // operations that should result in the same value
101  static CppAD::AD<Base> dummy_precision(void)
102  { return 100. *
103  CppAD::numeric_limits< CppAD::AD<Base> >::epsilon();
104  }
105 
106  // minimum normalized positive value
107  static CppAD::AD<Base> lowest(void)
108  { return CppAD::numeric_limits< CppAD::AD<Base> >::min(); }
109 
110  // maximum finite value
111  static CppAD::AD<Base> highest(void)
112  { return CppAD::numeric_limits< CppAD::AD<Base> >::max(); }
113 
114  // number of decimal digits that can be represented without change.
115  static int digits10(void)
116  { return CppAD::numeric_limits< CppAD::AD<Base> >::digits10; }
117  };
118 } // namespace Eigen
119 
120 // Source from #include <cppad/example/cppad_eigen.hpp>
121 namespace CppAD
122 {
123  // functions that return references
124  template <class Base> const AD<Base>& conj(const AD<Base>& x)
125  { return x; }
126  template <class Base> const AD<Base>& real(const AD<Base>& x)
127  { return x; }
128 
129  // functions that return values (note abs is defined by cppad.hpp)
130  template <class Base> AD<Base> imag(const AD<Base>& /*x*/)
131  { return CppAD::AD<Base>(0.); }
132  template <class Base> AD<Base> abs2(const AD<Base>& x)
133  { return x * x; }
134 } // namespace CppAD
135 
136 #include "pinocchio/utils/static-if.hpp"
137 
138 namespace pinocchio
139 {
140  template<typename Scalar>
141  struct TaylorSeriesExpansion< CppAD::AD<Scalar> > : TaylorSeriesExpansion<Scalar>
142  {
144  typedef CppAD::AD<Scalar> ADScalar;
145 
146  template<int degree>
147  static ADScalar precision()
148  {
149  return ADScalar(Base::template precision<degree>());
150  }
151 
152  };
153 
154 } // namespace pinocchio
155 
156 #include "pinocchio/autodiff/cppad/spatial/se3-tpl.hpp"
157 #include "pinocchio/autodiff/cppad/spatial/log.hxx"
158 #include "pinocchio/autodiff/cppad/utils/static-if.hpp"
159 #include "pinocchio/autodiff/cppad/math/quaternion.hpp"
160 
161 #endif // #ifndef __pinocchio_autodiff_ccpad_hpp__
Definition: casadi.hpp:13
Definition: casadi.hpp:47
Definition: cppad.hpp:121
Main pinocchio namespace.
Definition: treeview.dox:24