GCC Code Coverage Report


Directory: ./
File: include/hpp/core/straight-path.hh
Date: 2024-12-13 16:14:03
Exec Total Coverage
Lines: 27 35 77.1%
Branches: 22 50 44.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2014 CNRS
3 // Authors: Florent Lamiraux
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_STRAIGHT_PATH_HH
31 #define HPP_CORE_STRAIGHT_PATH_HH
32
33 #include <hpp/core/config.hh>
34 #include <hpp/core/fwd.hh>
35 #include <hpp/core/path.hh>
36 #include <hpp/pinocchio/liegroup-element.hh>
37
38 namespace hpp {
39 namespace core {
40 /// \addtogroup path
41 /// \{
42
43 /// Linear interpolation between two configurations
44 ///
45 /// Degrees of freedom are interpolated depending on the type of
46 /// \link hpp::pinocchio::Joint joint \endlink
47 /// they parameterize:
48 /// \li linear interpolation for translation joints, bounded rotation
49 /// joints, and translation part of freeflyer joints,
50 /// \li angular interpolation for unbounded rotation joints,
51 /// \li constant angular velocity for SO(3) part of freeflyer joints.
52 class HPP_CORE_DLLAPI StraightPath : public Path {
53 public:
54 typedef Path parent_t;
55 /// Destructor
56 84738 virtual ~StraightPath() {}
57
58 /// Create instance and return shared pointer
59 /// \param init, end Start and end configurations of the path,
60 /// \param interval interval of definition
61 /// \param constraints the path is subject to.
62 4558 static StraightPathPtr_t create(
63 LiegroupSpacePtr_t space, vectorIn_t init, vectorIn_t end,
64 interval_t interval,
65 ConstraintSetPtr_t constraints = ConstraintSetPtr_t()) {
66 StraightPath* ptr;
67
2/2
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 4280 times.
4558 if (constraints)
68
4/8
✓ Branch 2 taken 278 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 278 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 278 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 278 times.
✗ Branch 13 not taken.
278 ptr = new StraightPath(space, init, end, interval, constraints);
69 else
70
4/8
✓ Branch 2 taken 4280 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4280 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 4280 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 4280 times.
✗ Branch 12 not taken.
4280 ptr = new StraightPath(space, init, end, interval);
71 4558 StraightPathPtr_t shPtr(ptr);
72
1/2
✓ Branch 2 taken 4558 times.
✗ Branch 3 not taken.
4558 ptr->init(shPtr);
73
1/2
✓ Branch 1 taken 4558 times.
✗ Branch 2 not taken.
4558 ptr->checkPath();
74 4558 return shPtr;
75 }
76
77 /// Create instance and return shared pointer
78 /// \param init, end Start and end configurations of the path
79 /// \param interval interval of definition
80 /// \param constraints the path is subject to.
81 static StraightPathPtr_t create(
82 LiegroupElementConstRef init, LiegroupElementConstRef end,
83 interval_t interval,
84 ConstraintSetPtr_t constraints = ConstraintSetPtr_t()) {
85 assert(init.space() == end.space());
86 return create(init.space(), init.vector(), end.vector(), interval,
87 constraints);
88 }
89
90 /// Create instance and return shared pointer
91 /// \param device Robot corresponding to configurations
92 /// \param init, end Start and end configurations of the path
93 /// \param length Distance between the configurations.
94 4129 static StraightPathPtr_t create(
95 const DevicePtr_t& device, ConfigurationIn_t init, ConfigurationIn_t end,
96 value_type length,
97 ConstraintSetPtr_t constraints = ConstraintSetPtr_t()) {
98
3/6
✓ Branch 3 taken 4129 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4129 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 4129 times.
✗ Branch 10 not taken.
4129 return create(device, init, end, interval_t(0, length), constraints);
99 }
100
101 /// Create instance and return shared pointer
102 /// \param device Robot corresponding to configurations
103 /// \param init, end Start and end configurations of the path
104 /// \param interval interval of definition.
105 /// \param constraints the path is subject to
106 static StraightPathPtr_t create(
107 const DevicePtr_t& device, ConfigurationIn_t init, ConfigurationIn_t end,
108 interval_t interval,
109 ConstraintSetPtr_t constraints = ConstraintSetPtr_t());
110
111 /// Create copy and return shared pointer
112 /// \param path path to copy
113 212 static StraightPathPtr_t createCopy(const StraightPathPtr_t& path) {
114
1/2
✓ Branch 3 taken 212 times.
✗ Branch 4 not taken.
212 StraightPath* ptr = new StraightPath(*path);
115 212 StraightPathPtr_t shPtr(ptr);
116
1/2
✓ Branch 2 taken 212 times.
✗ Branch 3 not taken.
212 ptr->init(shPtr);
117
1/2
✓ Branch 1 taken 212 times.
✗ Branch 2 not taken.
212 ptr->checkPath();
118 212 return shPtr;
119 }
120
121 /// Create copy and return shared pointer
122 /// \param path path to copy
123 /// \param constraints the path is subject to
124 static StraightPathPtr_t createCopy(const StraightPathPtr_t& path,
125 const ConstraintSetPtr_t& constraints) {
126 StraightPath* ptr = new StraightPath(*path, constraints);
127 StraightPathPtr_t shPtr(ptr);
128 ptr->init(shPtr);
129 ptr->checkPath();
130 return shPtr;
131 }
132
133 /// Return a shared pointer to this
134 ///
135 /// As StaightPath are immutable, and refered to by shared pointers,
136 /// they do not need to be copied.
137
1/2
✓ Branch 2 taken 212 times.
✗ Branch 3 not taken.
212 virtual PathPtr_t copy() const { return createCopy(weak_.lock()); }
138
139 /// Return a shared pointer to a copy of this and set constraints
140 ///
141 /// \param constraints constraints to apply to the copy
142 /// \pre *this should not have constraints.
143 virtual PathPtr_t copy(const ConstraintSetPtr_t& constraints) const {
144 return createCopy(weak_.lock(), constraints);
145 }
146
147 /// Modify initial configuration
148 /// \param initial new initial configuration
149 /// \pre input configuration should be of the same size as current initial
150 /// configuration
151 void initialConfig(ConfigurationIn_t initial) {
152 assert(initial.size() == initial_.size());
153 initial_ = initial;
154 }
155
156 /// Modify end configuration
157 /// \param end new end configuration
158 /// \pre input configuration should be of the same size as current end
159 /// configuration
160 void endConfig(ConfigurationIn_t end) {
161 assert(end.size() == end_.size());
162 end_ = end;
163 }
164
165 /// Get the initial configuration
166 30761 Configuration_t initial() const { return initial_; }
167
168 /// Get the final configuration
169 27367 Configuration_t end() const { return end_; }
170
171 protected:
172 /// Print path in a stream
173 virtual std::ostream& print(std::ostream& os) const;
174
175 /// Constructor
176 StraightPath(LiegroupSpacePtr_t space, vectorIn_t init, vectorIn_t end,
177 interval_t interval);
178
179 /// Constructor
180 StraightPath(LiegroupSpacePtr_t space, vectorIn_t init, vectorIn_t end,
181 interval_t interval, ConstraintSetPtr_t constraints);
182
183 /// Copy constructor
184 StraightPath(const StraightPath& path);
185
186 /// Copy constructor with constraints
187 StraightPath(const StraightPath& path, const ConstraintSetPtr_t& constraints);
188
189 37781 void init(StraightPathPtr_t self) {
190
1/2
✓ Branch 2 taken 37781 times.
✗ Branch 3 not taken.
37781 parent_t::init(self);
191 37781 weak_ = self;
192 37781 checkPath();
193 37781 }
194
195 virtual bool impl_compute(ConfigurationOut_t result, value_type param) const;
196 /// Virtual implementation of derivative
197 virtual void impl_derivative(vectorOut_t result, const value_type& t,
198 size_type order) const;
199
200 virtual void impl_velocityBound(vectorOut_t result, const value_type&,
201 const value_type&) const;
202
203 /// Extraction/Reversion of a sub-path
204 /// \param subInterval interval of definition of the extract path
205 /// If upper bound of subInterval is smaller than lower bound,
206 /// result is reversed.
207 PathPtr_t impl_extract(const interval_t& subInterval) const;
208
209 protected:
210 LiegroupSpacePtr_t space_;
211 Configuration_t initial_;
212 Configuration_t end_;
213
214 private:
215 StraightPathWkPtr_t weak_;
216
217 protected:
218
2/4
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
15 StraightPath() {}
219
220 private:
221 HPP_SERIALIZABLE();
222 }; // class StraightPath
223 /// \}
224 } // namespace core
225 } // namespace hpp
226
227 18 BOOST_CLASS_EXPORT_KEY(hpp::core::StraightPath)
228
229 #endif // HPP_CORE_STRAIGHT_PATH_HH
230