plcopen 0.22.0
载入中...
搜索中...
未找到
sampler.h
浏览该文件的文档.
1#pragma once
2
3#include <cstddef>
4
5#include "geom/geometry.h"
6#include "otg/profile1d.h"
7#include "rt/error.h"
8#include "rt/static_vector.h"
9
10namespace plcopen::core::exec
11{
12
13template <std::size_t Capacity> class CommittedPath
14{
15public:
17 {
18 return segments_.push_back(segment);
19 }
20
21 std::size_t size() const
22 {
23 return segments_.size();
24 }
25
26 double total_length() const
27 {
28 double total = 0.0;
29 for(std::size_t i = 0; i < segments_.size(); ++i) {
30 total += segments_[i].length();
31 }
32 return total;
33 }
34
35 geom::Vec3 sample_arclength(double arclength) const
36 {
37 double remaining = arclength;
38 for(std::size_t i = 0; i < segments_.size(); ++i) {
39 const double length = segments_[i].length();
40 if(remaining <= length) {
41 return segments_[i].sample(remaining);
42 }
43 remaining -= length;
44 }
45
46 if(segments_.empty()) {
47 return {};
48 }
49 return segments_[segments_.size() - 1].sample(segments_[segments_.size() - 1].length());
50 }
51
52private:
54};
55
56template <std::size_t Capacity>
58 const otg::Profile1D &profile,
59 rt::CycleTick tick)
60{
61 const otg::State1D scalar = otg::sample(profile, tick);
62 return path.sample_arclength(scalar.position);
63}
64
65} // namespace plcopen::core::exec
rt::ErrorCode push(geom::PathSegment segment)
geom::Vec3 sample_arclength(double arclength) const
geom::Vec3 sample_profiled_path(const CommittedPath< Capacity > &path, const otg::Profile1D &profile, rt::CycleTick tick)
State1D sample(const Profile1D &profile, rt::CycleTick tick)