COPP C++ API
C++ interface for COPP trajectory optimization
Loading...
Searching...
No Matches
interpolation.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4#include <vector>
5
6#include "copp/core.hpp"
7
8namespace copp
9{
10
22 {
25 std::size_t num_stationary_start = 0;
26 std::size_t num_stationary_end = 0;
27
28 Profile3rdRef() = default;
31 Span<const double> a_values,
32 Span<const double> b_values,
33 std::pair<std::size_t, std::size_t> num_stationary);
35 Span<const double> a_values,
36 Span<const double> b_values,
37 std::size_t stationary_start,
38 std::size_t stationary_end);
39
40 std::size_t len() const noexcept { return a.size(); }
41 std::size_t size() const noexcept { return a.size(); }
42 bool empty() const noexcept { return a.empty(); }
43 std::pair<std::size_t, std::size_t> num_stationary() const noexcept
44 {
46 }
47
55 Profile3rdRef slice(std::size_t idx_s_start, std::size_t idx_s_final) const;
56
58 Profile3rdRef segment(std::size_t idx_s) const;
59 };
60
69 {
70 std::vector<double> a;
71 std::vector<double> b;
72 std::size_t num_stationary_start = 0;
73 std::size_t num_stationary_end = 0;
74
75 Profile3rd() = default;
76 Profile3rd(std::vector<double> a_values, std::vector<double> b_values);
78 std::vector<double> a_values,
79 std::vector<double> b_values,
80 std::pair<std::size_t, std::size_t> num_stationary);
82 std::vector<double> a_values,
83 std::vector<double> b_values,
84 std::size_t stationary_start,
85 std::size_t stationary_end);
86
87 std::size_t len() const noexcept { return a.size(); }
88 std::size_t size() const noexcept { return a.size(); }
89 bool empty() const noexcept { return a.empty(); }
90 std::pair<std::size_t, std::size_t> num_stationary() const noexcept
91 {
93 }
94
97
99 Profile3rdRef slice(std::size_t idx_s_start, std::size_t idx_s_final) const;
100
102 Profile3rdRef segment(std::size_t idx_s) const;
103 };
104
105} // namespace copp
106
107namespace copp::interpolation
108{
109
115 {
116 double t_final = 0.0;
117 std::vector<double> t_s;
118 };
119
125 {
126 double t0 = 0.0;
127 bool include_final = true;
128 };
129
144 {
145 return detail::expected_from([&] { return a_to_b_topp2(s, a); });
146 }
147
174 double t0,
176 {
177 return detail::expected_from([&] { return s_to_t_topp2(s, a, t0); });
178 }
179
183 NoThrowTag tag)
184 {
185 return s_to_t_topp2(s, a, 0.0, tag);
186 }
187
194 COPP_API std::vector<double> t_to_s_topp2_uniform(
198 double dt,
199 TimeGridOptions options = {});
204 double dt,
205 TimeGridOptions options,
207 {
208 return detail::expected_from([&] { return t_to_s_topp2_uniform(s, a, t_s, dt, options); });
209 }
210
215 double dt,
216 NoThrowTag tag)
217 {
218 return t_to_s_topp2_uniform(s, a, t_s, dt, TimeGridOptions{}, tag);
219 }
220
225 COPP_API std::vector<double> t_to_s_topp2_samples(
229 Span<const double> t_sample);
234 Span<const double> t_sample,
236 {
237 return detail::expected_from([&] { return t_to_s_topp2_samples(s, a, t_s, t_sample); });
238 }
239
260 const Profile3rd &profile,
261 double t0 = 0.0);
264 Profile3rdRef profile,
265 double t0 = 0.0);
268 const Profile3rd &profile,
269 double t0,
271 {
272 return detail::expected_from([&] { return s_to_t_topp3(s, profile, t0); });
273 }
274
277 const Profile3rd &profile,
278 NoThrowTag tag)
279 {
280 return s_to_t_topp3(s, profile, 0.0, tag);
281 }
282
285 Profile3rdRef profile,
286 double t0,
288 {
289 return detail::expected_from([&] { return s_to_t_topp3(s, profile, t0); });
290 }
291
294 Profile3rdRef profile,
295 NoThrowTag tag)
296 {
297 return s_to_t_topp3(s, profile, 0.0, tag);
298 }
299
304 COPP_API std::vector<double> t_to_s_topp3_uniform(
306 const Profile3rd &profile,
308 double dt,
309 TimeGridOptions options = {});
310 COPP_API std::vector<double> t_to_s_topp3_uniform(
312 Profile3rdRef profile,
314 double dt,
315 TimeGridOptions options = {});
318 const Profile3rd &profile,
320 double dt,
321 TimeGridOptions options,
323 {
325 [&] { return t_to_s_topp3_uniform(s, profile, t_s, dt, options); });
326 }
327
330 const Profile3rd &profile,
332 double dt,
333 NoThrowTag tag)
334 {
335 return t_to_s_topp3_uniform(s, profile, t_s, dt, TimeGridOptions{}, tag);
336 }
337
340 Profile3rdRef profile,
342 double dt,
343 TimeGridOptions options,
345 {
347 [&] { return t_to_s_topp3_uniform(s, profile, t_s, dt, options); });
348 }
349
352 Profile3rdRef profile,
354 double dt,
355 NoThrowTag tag)
356 {
357 return t_to_s_topp3_uniform(s, profile, t_s, dt, TimeGridOptions{}, tag);
358 }
359
368 COPP_API std::vector<double> t_to_s_topp3_samples(
370 const Profile3rd &profile,
372 Span<const double> t_sample);
373 COPP_API std::vector<double> t_to_s_topp3_samples(
375 Profile3rdRef profile,
377 Span<const double> t_sample);
380 const Profile3rd &profile,
382 Span<const double> t_sample,
384 {
385 return detail::expected_from([&] { return t_to_s_topp3_samples(s, profile, t_s, t_sample); });
386 }
387
390 Profile3rdRef profile,
392 Span<const double> t_sample,
394 {
395 return detail::expected_from([&] { return t_to_s_topp3_samples(s, profile, t_s, t_sample); });
396 }
397
398} // namespace copp::interpolation
Small C++17 expected-like result used by no-throw overloads.
Definition core.hpp:527
Non-owning view of a contiguous one-dimensional array.
Definition core.hpp:139
#define COPP_API
Definition core.hpp:23
auto expected_from(Fn &&fn) -> Expected< typename std::decay< decltype(fn())>::type >
Definition core.hpp:580
Time-conversion helpers for TOPP2/TOPP3 profiles, including s -> t, uniform t -> s,...
COPP_API std::vector< double > t_to_s_topp2_uniform(Span< const double > s, Span< const double > a, Span< const double > t_s, double dt, TimeGridOptions options={})
Sample the inverse TOPP2 mapping s(t) on a uniform time grid.
COPP_API std::vector< double > a_to_b_topp2(Span< const double > s, Span< const double > a)
Compute segment profile b from node profile a.
COPP_API TimeProfile s_to_t_topp2(Span< const double > s, Span< const double > a, double t0=0.0)
Convert a second-order path profile a(s) = ds/dt squared to t(s).
COPP_API std::vector< double > t_to_s_topp3_samples(Span< const double > s, const Profile3rd &profile, Span< const double > t_s, Span< const double > t_sample)
Sample the inverse TOPP3 mapping s(t) at explicit query times.
COPP_API std::vector< double > t_to_s_topp2_samples(Span< const double > s, Span< const double > a, Span< const double > t_s, Span< const double > t_sample)
Sample the inverse TOPP2 mapping s(t) at explicit query times.
COPP_API TimeProfile s_to_t_topp3(Span< const double > s, const Profile3rd &profile, double t0=0.0)
Convert a third-order profile to cumulative time t(s).
COPP_API std::vector< double > t_to_s_topp3_uniform(Span< const double > s, const Profile3rd &profile, Span< const double > t_s, double dt, TimeGridOptions options={})
Sample the inverse TOPP3 mapping s(t) on a uniform time grid.
Root namespace for the C++ facade: paths, robots, constraints, matrices, profiles,...
Tag object selecting no-throw overloads.
Definition core.hpp:608
Owned third-order TOPP/COPP profile.
Profile3rd()=default
std::vector< double > b
std::size_t size() const noexcept
std::vector< double > a
Profile3rd(std::vector< double > a_values, std::vector< double > b_values)
bool empty() const noexcept
std::size_t num_stationary_start
std::pair< std::size_t, std::size_t > num_stationary() const noexcept
Profile3rd(std::vector< double > a_values, std::vector< double > b_values, std::size_t stationary_start, std::size_t stationary_end)
std::size_t len() const noexcept
Profile3rdRef slice(std::size_t idx_s_start, std::size_t idx_s_final) const
Borrow a closed station subrange idx_s_start..=idx_s_final.
Profile3rdRef segment(std::size_t idx_s) const
Borrow one segment as the two-node profile idx_s..=idx_s+1.
std::size_t num_stationary_end
Profile3rdRef ref() const
Borrow this owned profile without copying arrays.
Profile3rd(std::vector< double > a_values, std::vector< double > b_values, std::pair< std::size_t, std::size_t > num_stationary)
Borrowed third-order TOPP/COPP profile view.
std::size_t num_stationary_start
bool empty() const noexcept
std::pair< std::size_t, std::size_t > num_stationary() const noexcept
Span< const double > b
Profile3rdRef()=default
Profile3rdRef(Span< const double > a_values, Span< const double > b_values, std::size_t stationary_start, std::size_t stationary_end)
Profile3rdRef(Span< const double > a_values, Span< const double > b_values, std::pair< std::size_t, std::size_t > num_stationary)
Span< const double > a
Profile3rdRef slice(std::size_t idx_s_start, std::size_t idx_s_final) const
Borrow a closed station subrange idx_s_start..=idx_s_final.
std::size_t len() const noexcept
std::size_t size() const noexcept
std::size_t num_stationary_end
Profile3rdRef segment(std::size_t idx_s) const
Borrow one segment as the two-node profile idx_s..=idx_s+1.
Profile3rdRef(Span< const double > a_values, Span< const double > b_values)
Options for generating a uniform s(t) sampling grid.
Cumulative time profile returned by s_to_t_topp2.