hpp-constraints  4.9.1
Definition of basic geometric constraints for motion planning
generic-transformation.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016 CNRS
3 // Authors: Joseph Mirabel
4 //
5 //
6 // This file is part of hpp-constraints.
7 // hpp-constraints is free software: you can redistribute it
8 // and/or modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation, either version
10 // 3 of the License, or (at your option) any later version.
11 //
12 // hpp-constraints is distributed in the hope that it will be
13 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Lesser Public License for more details. You should have
16 // received a copy of the GNU Lesser General Public License along with
17 // hpp-constraints. If not, see
18 // <http://www.gnu.org/licenses/>.
19 
20 #ifndef HPP_CONSTRAINTS_GENERIC_TRANSFORMATION_HH
21 # define HPP_CONSTRAINTS_GENERIC_TRANSFORMATION_HH
22 
23 # include <pinocchio/spatial/se3.hpp>
24 
25 # include <hpp/pinocchio/joint.hh>
26 
27 # include <hpp/constraints/fwd.hh>
28 # include <hpp/constraints/config.hh>
31 
32 namespace hpp {
33  namespace constraints {
35  template <bool rel> struct GenericTransformationModel
36  {
37  JointConstPtr_t joint2;
38  bool R1isID, R2isID, t1isZero, t2isZero;
39  Transform3f F1inJ1, F2inJ2;
40  bool fullPos, fullOri;
41  size_type rowOri;
42  const size_type cols;
43 
44  inline JointConstPtr_t getJoint1() const { return JointConstPtr_t(); }
45  inline void setJoint1(const JointConstPtr_t&) {}
46  GenericTransformationModel (const size_type nCols) :
47  joint2(), R1isID(true), R2isID(true), t1isZero(true), t2isZero(true),
48  fullPos(false), fullOri(false), cols (nCols)
49  { F1inJ1.setIdentity(); F2inJ2.setIdentity(); }
50  void checkIsIdentity1() {
51  R1isID = F1inJ1.rotation().isIdentity();
52  t1isZero = F1inJ1.translation().isZero();
53  }
54  void checkIsIdentity2() {
55  R2isID = F2inJ2.rotation().isIdentity();
56  t2isZero = F2inJ2.translation().isZero();
57  }
58  };
59  template <> struct GenericTransformationModel<true> :
60  GenericTransformationModel<false>
61  {
62  JointConstPtr_t joint1;
63  inline JointConstPtr_t getJoint1() const { return joint1; }
64  void setJoint1(const JointConstPtr_t& j);
65  GenericTransformationModel (const size_type nCols) :
66  GenericTransformationModel<false>(nCols), joint1() {}
67  };
69 
72 
108  template <int _Options>
109  class HPP_CONSTRAINTS_DLLAPI GenericTransformation :
110  public DifferentiableFunction
111  {
112  public:
113  typedef boost::shared_ptr <GenericTransformation> Ptr_t;
114  typedef boost::weak_ptr <GenericTransformation> WkPtr_t;
115 #if __cplusplus >= 201103L
116  static constexpr bool
117  IsRelative = _Options & RelativeBit,
118  ComputeOrientation = _Options & OrientationBit,
119  ComputePosition = _Options & PositionBit,
120  OutputSE3 = _Options & OutputSE3Bit,
121  IsPosition = ComputePosition && !ComputeOrientation,
122  IsOrientation = !ComputePosition && ComputeOrientation,
123  IsTransform = ComputePosition && ComputeOrientation;
124  static constexpr int
125  ValueSize = (ComputePosition?3:0) + (ComputeOrientation?(OutputSE3?4:3):0),
126  DerSize = (ComputePosition?3:0) + (ComputeOrientation ?3:0);
127 #else
128  enum {
129  IsRelative = _Options & RelativeBit,
130  ComputeOrientation = _Options & OrientationBit,
131  ComputePosition = _Options & PositionBit,
132  OutputSE3 = _Options & OutputSE3Bit,
133  IsPosition = ComputePosition && !ComputeOrientation,
134  IsOrientation = !ComputePosition && ComputeOrientation,
135  IsTransform = ComputePosition && ComputeOrientation,
136  ValueSize = (ComputePosition?3:0) + (ComputeOrientation?(OutputSE3?4:3):0),
137  DerSize = (ComputePosition?3:0) + (ComputeOrientation ?3:0)
138  };
139 #endif
140 
142  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
144 
155  static Ptr_t create (const std::string& name, const DevicePtr_t& robot,
156  const JointConstPtr_t& joint2, const Transform3f& reference,
157  std::vector <bool> mask = std::vector<bool>(DerSize,true));
158 
173  static Ptr_t create (const std::string& name, const DevicePtr_t& robot,
174  /* World frame */ const JointConstPtr_t& joint2,
175  const Transform3f& frame2, const Transform3f& frame1,
176  std::vector <bool> mask = std::vector<bool>(DerSize,true));
177 
190  static Ptr_t create (const std::string& name, const DevicePtr_t& robot,
191  const JointConstPtr_t& joint1, const JointConstPtr_t& joint2,
192  const Transform3f& reference,
193  std::vector <bool> mask = std::vector<bool>(DerSize,true));
194 
213  static Ptr_t create (const std::string& name, const DevicePtr_t& robot,
214  const JointConstPtr_t& joint1, const JointConstPtr_t& joint2,
215  const Transform3f& frame1, const Transform3f& frame2,
216  std::vector <bool> mask = std::vector<bool>(DerSize,true));
217 
219 
222  inline void reference (const Transform3f& reference)
223  {
224  m_.F1inJ1 = reference;
225  m_.checkIsIdentity1();
226  m_.F2inJ2.setIdentity ();
227  m_.checkIsIdentity2();
228  }
229 
231  inline Transform3f reference () const
232  {
233  return m_.F1inJ1.actInv(m_.F2inJ2);
234  }
235 
237  inline void joint1 (const JointConstPtr_t& joint) {
238  // static_assert(IsRelative);
239  m_.setJoint1(joint);
240  computeActiveParams();
241  assert (!joint || joint->robot () == robot_);
242  }
243 
245  inline JointConstPtr_t joint1 () const {
246  return m_.getJoint1();
247  }
248 
250  inline void joint2 (const JointConstPtr_t& joint) {
251  m_.joint2 = joint;
252  computeActiveParams();
253  assert (!joint || (joint->index() > 0 && joint->robot () == robot_));
254  }
255 
257  inline JointConstPtr_t joint2 () const {
258  return m_.joint2;
259  }
260 
262  inline void frame1InJoint1 (const Transform3f& M) {
263  m_.F1inJ1 = M;
264  m_.checkIsIdentity1();
265  }
267  inline const Transform3f& frame1InJoint1 () const {
268  return m_.F1inJ1;
269  }
271  inline void frame2InJoint2 (const Transform3f& M) {
272  m_.F2inJ2 = M;
273  m_.checkIsIdentity2();
274  }
276  inline const Transform3f& frame2InJoint2 () const {
277  return m_.F2inJ2;
278  }
279 
280  virtual std::ostream& print (std::ostream& o) const;
281 
289  GenericTransformation (const std::string& name,
290  const DevicePtr_t& robot,
291  std::vector <bool> mask);
292 
293  protected:
294  void init (const WkPtr_t& self)
295  {
296  self_ = self;
297  computeActiveParams();
298  }
299 
304  virtual void impl_compute (LiegroupElementRef result,
305  ConfigurationIn_t argument) const;
306  virtual void impl_jacobian (matrixOut_t jacobian,
307  ConfigurationIn_t arg) const;
308  private:
309  void computeActiveParams ();
310  DevicePtr_t robot_;
311  GenericTransformationModel<IsRelative> m_;
312  Eigen::RowBlockIndices Vindices_;
313  const std::vector <bool> mask_;
314  WkPtr_t self_;
315  }; // class GenericTransformation
317  } // namespace constraints
318 } // namespace hpp
319 #endif // HPP_CONSTRAINTS_GENERIC_TRANSFORMATION_HH
void joint2(const JointConstPtr_t &joint)
Set joint 2.
Definition: generic-transformation.hh:250
pinocchio::DevicePtr_t DevicePtr_t
Definition: fwd.hh:91
void init(const WkPtr_t &self)
Definition: generic-transformation.hh:294
ObjectFactory * create(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
matrix_t::Index size_type
void frame2InJoint2(const Transform3f &M)
Set position of frame 2 in joint 2.
Definition: generic-transformation.hh:271
const Transform3f & frame1InJoint1() const
Get position of frame 1 in joint 1.
Definition: generic-transformation.hh:267
pinocchio::ConfigurationIn_t ConfigurationIn_t
Definition: fwd.hh:88
assert(d.lhs()._blocks()==d.rhs()._blocks())
void reference(const Transform3f &reference)
Definition: generic-transformation.hh:222
pinocchio::JointConstPtr_t JointConstPtr_t
Definition: fwd.hh:38
void joint1(const JointConstPtr_t &joint)
Set joint 1.
Definition: generic-transformation.hh:237
const Transform3f & frame2InJoint2() const
Get position of frame 2 in joint 2.
Definition: generic-transformation.hh:276
JointConstPtr_t joint1() const
Get joint 1.
Definition: generic-transformation.hh:245
boost::shared_ptr< GenericTransformation > Ptr_t
Definition: generic-transformation.hh:113
boost::weak_ptr< GenericTransformation > WkPtr_t
Definition: generic-transformation.hh:114
JointConstPtr_t joint2() const
Get joint 2.
Definition: generic-transformation.hh:257
::pinocchio::SE3 Transform3f
virtual ~GenericTransformation()
Definition: generic-transformation.hh:218
Eigen::Ref< matrix_t > matrixOut_t
Definition: fwd.hh:44
boost::shared_ptr< const Joint > JointConstPtr_t
Transform3f reference() const
Get desired relative orientation.
Definition: generic-transformation.hh:231
void frame1InJoint1(const Transform3f &M)
Set position of frame 1 in joint 1.
Definition: generic-transformation.hh:262
pinocchio::Transform3f Transform3f
Definition: fwd.hh:50
Vec3f o