pinocchio  UNKNOWN
spatial-axis.hpp
1 //
2 // Copyright (c) 2017-2018 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef __se3_spatial_axis_hpp__
19 #define __se3_spatial_axis_hpp__
20 
21 #include "pinocchio/spatial/fwd.hpp"
22 #include "pinocchio/spatial/cartesian-axis.hpp"
23 #include "pinocchio/spatial/motion.hpp"
24 #include "pinocchio/spatial/force.hpp"
25 
26 namespace se3
27 {
28  template<int axis> struct SpatialAxis;
29 
30  namespace internal
31  {
32  template<int axis, typename MotionDerived>
33  struct MotionAlgebraAction<SpatialAxis<axis>, MotionDerived>
34  { typedef typename MotionDerived::MotionPlain ReturnType; };
35  }
36 
37  template<int _axis>
38  struct SpatialAxis //: MotionBase< SpatialAxis<_axis> >
39  {
40  enum { axis = _axis, dim = 6 };
42 
43  enum { LINEAR = 0, ANGULAR = 3 };
44 
45  template<typename Derived1, typename Derived2>
46  inline static void cross(const MotionDense<Derived1> & min,
47  const MotionDense<Derived2> & mout);
48 
49  template<typename Derived>
50  static typename traits<Derived>::MotionPlain cross(const MotionDense<Derived> & min)
51  {
53  cross(min,res);
54  return res;
55  }
56 
57  template<typename Derived1, typename Derived2>
58  inline static void cross(const ForceDense<Derived1> & fin,
59  const ForceDense<Derived2> & fout);
60 
61  template<typename Derived>
62  static typename traits<Derived>::ForcePlain cross(const ForceDense<Derived> & fin)
63  {
64  typename ForceDense<Derived>::ForcePlain fout;
65  cross(fin,fout);
66  return fout;
67  }
68 
69  template<typename Scalar>
70  MotionTpl<Scalar> operator*(const Scalar & s) const
71  {
72  typedef MotionTpl<Scalar> ReturnType;
73  ReturnType res;
74  for(Eigen::DenseIndex i = 0; i < dim; ++i)
75  res.toVector()[i] = i == axis ? s : Scalar(0);
76 
77  return res;
78  }
79 
80  template<typename Scalar>
81  friend inline MotionTpl<Scalar>
82  operator*(const Scalar & s, const SpatialAxis &)
83  {
84  return SpatialAxis() * s;
85  }
86 
87  template<typename Derived>
88  friend Derived & operator<<(MotionDense<Derived> & min,
89  const SpatialAxis &)
90  {
91  typedef typename traits<Derived>::Scalar Scalar;
92  min.setZero();
93  min.toVector()[axis] = Scalar(1);
94  return min.derived();
95  }
96 
97  template<typename MotionDerived>
98  typename MotionDerived::MotionPlain
99  motionAction(const MotionDense<MotionDerived> & m) const
100  {
101  typename MotionDerived::MotionPlain res;
102  if((LINEAR == 0 && axis<3) || (LINEAR == 3 && axis >= 3))
103  {
104  res.angular().setZero();
105  CartesianAxis3::cross(-m.angular(),res.linear());
106  }
107  else
108  {
109  CartesianAxis3::cross(-m.linear(),res.linear());
110  CartesianAxis3::cross(-m.angular(),res.angular());
111  }
112 
113  return res;
114  }
115 
116  }; // struct SpatialAxis
117 
118  template<int axis>
119  template<typename Derived1, typename Derived2>
120  inline void SpatialAxis<axis>::cross(const MotionDense<Derived1> & min,
121  const MotionDense<Derived2> & mout)
122  {
123  Derived2 & mout_ = const_cast<MotionDense<Derived2> &>(mout).derived();
124  if((LINEAR == 0 && axis<3) || (LINEAR == 3 && axis >= 3))
125  {
126  mout_.angular().setZero();
127  CartesianAxis3::cross(min.angular(),mout_.linear());
128  }
129  else
130  {
131  CartesianAxis3::cross(min.linear(),mout_.linear());
132  CartesianAxis3::cross(min.angular(),mout_.angular());
133  }
134  }
135 
136  template<int axis>
137  template<typename Derived1, typename Derived2>
138  inline void SpatialAxis<axis>::cross(const ForceDense<Derived1> & fin,
139  const ForceDense<Derived2> & fout)
140  {
141  Derived2 & fout_ = const_cast<ForceDense<Derived2> &>(fout).derived();
142  if((LINEAR == 0 && axis<3) || (LINEAR == 3 && axis >= 3))
143  {
144  fout_.linear().setZero();
145  CartesianAxis3::cross(fin.linear(),fout_.angular());
146  }
147  else
148  {
149  CartesianAxis3::cross(fin.linear(),fout_.linear());
150  CartesianAxis3::cross(fin.angular(),fout_.angular());
151  }
152  }
153 
154  typedef SpatialAxis<0> AxisVX;
155  typedef SpatialAxis<1> AxisVY;
156  typedef SpatialAxis<2> AxisVZ;
157 
158  typedef SpatialAxis<3> AxisWX;
159  typedef SpatialAxis<4> AxisWY;
160  typedef SpatialAxis<5> AxisWZ;
161 }
162 
163 #endif // __se3_spatial_axis_hpp__
ConstAngularType angular() const
Return the angular part of the force vector.
Definition: force-base.hpp:53
ConstLinearType linear() const
Return the linear part of the force vector.
Definition: force-base.hpp:60
void cross(const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3xIn > &Min, const Eigen::MatrixBase< Matrix3xOut > &Mout)
Applies the cross product onto the columns of M.
Definition: skew.hpp:203