hpp-core  6.0.0
Implement basic classes for canonical path planning for kinematic chains.
subchain-path.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016 CNRS
3 // Authors: Joseph Mirabel
4 //
5 
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // 2. Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28 // DAMAGE.
29 
30 #ifndef HPP_CORE_DOF_EXTRACTED_PATH_HH
31 #define HPP_CORE_DOF_EXTRACTED_PATH_HH
32 
33 #include <hpp/constraints/matrix-view.hh>
34 #include <hpp/core/path.hh>
35 
36 namespace hpp {
37 namespace core {
40 
44 class SubchainPath : public Path {
45  public:
46  typedef Path parent_t;
47 
48  virtual ~SubchainPath() {}
49 
51  virtual PathPtr_t copy() const { return createCopy(weak_.lock()); }
52 
57  virtual PathPtr_t copy(const ConstraintSetPtr_t& constraints) const {
58  return createCopy(weak_.lock(), constraints);
59  }
60 
62  static SubchainPathPtr_t create(const PathPtr_t& original,
63  const segments_t& confIntervals,
64  const segments_t& velIntervals) {
65  SubchainPath* ptr = new SubchainPath(original, confIntervals, velIntervals);
66  SubchainPathPtr_t shPtr(ptr);
67  ptr->init(shPtr);
68  return shPtr;
69  }
70 
72  SubchainPath* ptr = new SubchainPath(*path);
73  SubchainPathPtr_t shPtr(ptr);
74  ptr->init(shPtr);
75  return shPtr;
76  }
77 
80  SubchainPath* ptr = new SubchainPath(*path, constraints);
81  SubchainPathPtr_t shPtr(ptr);
82  ptr->init(shPtr);
83  return shPtr;
84  }
85 
86  virtual bool impl_compute(ConfigurationOut_t result, value_type param) const {
87  bool success = original_->eval(q_, param);
88  if (success) dofExtract(q_, result);
89  return success;
90  }
91 
93  inline Configuration_t initial() const {
95  dofExtract(original_->initial(), q);
96  return q;
97  }
98 
100  inline Configuration_t end() const {
102  dofExtract(original_->end(), q);
103  return q;
104  }
105 
107  qout = configView_.rview(qin);
108  }
109 
110  protected:
112  virtual std::ostream& print(std::ostream& os) const {
113  os << "Dof Extracted Path:" << std::endl;
114  os << "intervals: " << configView_ << std::endl;
115  os << "original path:" << std::endl;
116  os << *original_ << std::endl;
117  return os;
118  }
119 
125  SubchainPath(const PathPtr_t& original, const segments_t& confIntervals,
126  const segments_t& velIntervals)
127  : Path(original->timeRange(), Eigen::BlockIndex::cardinal(confIntervals),
128  Eigen::BlockIndex::cardinal(velIntervals)),
129  original_(original),
130  configView_(confIntervals),
131  q_(Configuration_t::Zero(original->outputSize())) {}
132 
134  : Path(path),
135  original_(path.original_),
136  configView_(path.configView_),
137  q_(path.q_),
138  weak_() {}
139 
141  : Path(path, constraints),
142  original_(path.original_),
143  configView_(path.configView_),
144  weak_() {}
145 
146  void init(SubchainPathPtr_t self) {
147  parent_t::init(self);
148  weak_ = self;
149  }
150 
151  private:
152  PathPtr_t original_;
153  Eigen::RowBlockIndices configView_, velView_;
154  mutable Configuration_t q_;
155  SubchainPathWkPtr_t weak_;
156 }; // SubchainPath
158 } // namespace core
159 } // namespace hpp
160 #endif // HPP_CORE_DOF_EXTRACTED_PATH_HH
Definition: path.hh:71
const ConstraintSetPtr_t & constraints() const
Get constraints the path is subject to.
Definition: path.hh:204
size_type outputSize() const
Get size of configuration space.
Definition: path.hh:184
void init(const PathWkPtr_t &self)
const interval_t & timeRange() const
Get interval of definition.
Definition: path.hh:190
Definition: subchain-path.hh:44
virtual PathPtr_t copy() const
Return a shared pointer to a copy of this.
Definition: subchain-path.hh:51
Configuration_t end() const
Get the final configuration.
Definition: subchain-path.hh:100
static SubchainPathPtr_t createCopy(const SubchainPathPtr_t &path)
Definition: subchain-path.hh:71
void dofExtract(ConfigurationIn_t qin, ConfigurationOut_t qout) const
Definition: subchain-path.hh:106
static SubchainPathPtr_t createCopy(const SubchainPathPtr_t &path, const ConstraintSetPtr_t &constraints)
Definition: subchain-path.hh:78
virtual std::ostream & print(std::ostream &os) const
Print path in a stream.
Definition: subchain-path.hh:112
virtual bool impl_compute(ConfigurationOut_t result, value_type param) const
Function evaluation without applying constraints.
Definition: subchain-path.hh:86
virtual ~SubchainPath()
Definition: subchain-path.hh:48
SubchainPath(const SubchainPath &path, const ConstraintSetPtr_t &constraints)
Definition: subchain-path.hh:140
static SubchainPathPtr_t create(const PathPtr_t &original, const segments_t &confIntervals, const segments_t &velIntervals)
Definition: subchain-path.hh:62
SubchainPath(const SubchainPath &path)
Definition: subchain-path.hh:133
Path parent_t
Definition: subchain-path.hh:46
SubchainPath(const PathPtr_t &original, const segments_t &confIntervals, const segments_t &velIntervals)
Definition: subchain-path.hh:125
virtual PathPtr_t copy(const ConstraintSetPtr_t &constraints) const
Definition: subchain-path.hh:57
void init(SubchainPathPtr_t self)
Definition: subchain-path.hh:146
Configuration_t initial() const
Get the initial configuration.
Definition: subchain-path.hh:93
Definition: relative-motion.hh:115
pinocchio::value_type value_type
Definition: fwd.hh:174
shared_ptr< SubchainPath > SubchainPathPtr_t
Definition: fwd.hh:147
constraints::segments_t segments_t
Definition: fwd.hh:179
Eigen::BlockIndex BlockIndex
Interval of indices as (first index, number of indices)
Definition: fwd.hh:177
pinocchio::ConfigurationOut_t ConfigurationOut_t
Definition: fwd.hh:109
pinocchio::ConfigurationIn_t ConfigurationIn_t
Definition: fwd.hh:108
pinocchio::Configuration_t Configuration_t
Definition: fwd.hh:107
shared_ptr< ConstraintSet > ConstraintSetPtr_t
Definition: fwd.hh:130
shared_ptr< Path > PathPtr_t
Definition: fwd.hh:187
Definition: bi-rrt-planner.hh:35