COPP C++ API 0.2.3
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
124 bool force_positive_a(Span<const double> s, double a_min = 1.0e-12);
125
133 };
134
137 double a_min,
139 {
140 return detail::expected_from([&] { return force_positive_a(s, a_min); });
141 }
142
144 {
145 return force_positive_a(s, 1.0e-12, tag);
146 }
147
148} // namespace copp
149
150namespace copp::interpolation
151{
152
158 {
159 double t_final = 0.0;
160 std::vector<double> t_s;
161 };
162
168 {
169 double t0 = 0.0;
170 bool include_final = true;
171 };
172
187 {
188 return detail::expected_from([&] { return a_to_b_topp2(s, a); });
189 }
190
217 double t0,
219 {
220 return detail::expected_from([&] { return s_to_t_topp2(s, a, t0); });
221 }
222
226 NoThrowTag tag)
227 {
228 return s_to_t_topp2(s, a, 0.0, tag);
229 }
230
237 COPP_API std::vector<double> t_to_s_topp2_uniform(
241 double dt,
242 TimeGridOptions options = {});
247 double dt,
248 TimeGridOptions options,
250 {
251 return detail::expected_from([&] { return t_to_s_topp2_uniform(s, a, t_s, dt, options); });
252 }
253
258 double dt,
259 NoThrowTag tag)
260 {
261 return t_to_s_topp2_uniform(s, a, t_s, dt, TimeGridOptions{}, tag);
262 }
263
268 COPP_API std::vector<double> t_to_s_topp2_samples(
272 Span<const double> t_sample);
277 Span<const double> t_sample,
279 {
280 return detail::expected_from([&] { return t_to_s_topp2_samples(s, a, t_s, t_sample); });
281 }
282
303 const Profile3rd &profile,
304 double t0 = 0.0);
307 Profile3rdRef profile,
308 double t0 = 0.0);
311 const Profile3rd &profile,
312 double t0,
314 {
315 return detail::expected_from([&] { return s_to_t_topp3(s, profile, t0); });
316 }
317
320 const Profile3rd &profile,
321 NoThrowTag tag)
322 {
323 return s_to_t_topp3(s, profile, 0.0, tag);
324 }
325
328 Profile3rdRef profile,
329 double t0,
331 {
332 return detail::expected_from([&] { return s_to_t_topp3(s, profile, t0); });
333 }
334
337 Profile3rdRef profile,
338 NoThrowTag tag)
339 {
340 return s_to_t_topp3(s, profile, 0.0, tag);
341 }
342
347 COPP_API std::vector<double> t_to_s_topp3_uniform(
349 const Profile3rd &profile,
351 double dt,
352 TimeGridOptions options = {});
353 COPP_API std::vector<double> t_to_s_topp3_uniform(
355 Profile3rdRef profile,
357 double dt,
358 TimeGridOptions options = {});
361 const Profile3rd &profile,
363 double dt,
364 TimeGridOptions options,
366 {
368 [&] { return t_to_s_topp3_uniform(s, profile, t_s, dt, options); });
369 }
370
373 const Profile3rd &profile,
375 double dt,
376 NoThrowTag tag)
377 {
378 return t_to_s_topp3_uniform(s, profile, t_s, dt, TimeGridOptions{}, tag);
379 }
380
383 Profile3rdRef profile,
385 double dt,
386 TimeGridOptions options,
388 {
390 [&] { return t_to_s_topp3_uniform(s, profile, t_s, dt, options); });
391 }
392
395 Profile3rdRef profile,
397 double dt,
398 NoThrowTag tag)
399 {
400 return t_to_s_topp3_uniform(s, profile, t_s, dt, TimeGridOptions{}, tag);
401 }
402
411 COPP_API std::vector<double> t_to_s_topp3_samples(
413 const Profile3rd &profile,
415 Span<const double> t_sample);
416 COPP_API std::vector<double> t_to_s_topp3_samples(
418 Profile3rdRef profile,
420 Span<const double> t_sample);
423 const Profile3rd &profile,
425 Span<const double> t_sample,
427 {
428 return detail::expected_from([&] { return t_to_s_topp3_samples(s, profile, t_s, t_sample); });
429 }
430
433 Profile3rdRef profile,
435 Span<const double> t_sample,
437 {
438 return detail::expected_from([&] { return t_to_s_topp3_samples(s, profile, t_s, t_sample); });
439 }
440
441} // 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.
bool force_positive_a(Span< const double > s, double a_min=1.0e-12)
Adjust a and b in place so interpolated a(s) stays strictly positive on every interval.
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.