plcopen 0.22.0
载入中...
搜索中...
未找到
group_cartesian.h
浏览该文件的文档.
1#pragma once
2
3#include <array>
4#include <cstddef>
5#include <cstdint>
6#include <memory>
7
8#include "geom/frame.h"
9#include "geom/geometry.h"
10#include "otg/profile1d.h"
11#include "rt/error.h"
12#include "rt/static_vector.h"
13
14namespace plcopen::core::axis
15{
16
17class AxisGroup;
18
19// Internal: precomputed Cartesian segment geometry, resolved by the
20// submit_linear pre-validation. Not a user input.
22{
23 bool pose = false;
24 bool angle_driven = false;
25 bool arc_path = false;
27 bool chain = false;
28 double line1 = 0.0;
29 double line2 = 0.0;
36 double rotation_start[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
37 double axis[3] = {0.0, 0.0, 1.0};
38 double angle = 0.0;
39 double length = 0.0;
41};
42
43// Cartesian path/window runtime state. Frame, tool, kinematics and the
44// Cartesian/Jog overlay scratch deliberately remain owned by AxisGroup.
45template <std::size_t MaxAxes>
47{
48 friend class AxisGroup;
49
50 static constexpr std::size_t WindowCapacity = 32; // <= 16 segments
51
52 struct Piece
53 {
54 bool corner = false;
55 bool pose = false;
56 geom::Vec3 start{};
57 geom::Vec3 dir{};
58 double length = 0.0;
60 double rotation_start[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
61 double axis[3] = {0.0, 0.0, 1.0};
62 double angle = 0.0;
63 double v_in = 0.0;
64 double v_out = 0.0;
65 double cap = 0.0;
66 otg::Profile1D profile{};
67 std::int64_t duration = 0;
68 };
69
70 class Storage
71 {
72 public:
73 Storage()
74 : data_(new rt::StaticVector<Piece, WindowCapacity>())
75 {
76 }
77
78 bool empty() const { return data_->empty(); }
79 std::size_t size() const { return data_->size(); }
80 Piece &operator[](std::size_t index) { return (*data_)[index]; }
81 const Piece &operator[](std::size_t index) const { return (*data_)[index]; }
82 rt::ErrorCode push_back(const Piece &value) { return data_->push_back(value); }
83 void pop_back() { data_->pop_back(); }
84 void clear() { data_->clear(); }
85 void copy_from(const Storage &other)
86 {
87 data_->clear();
88 for(std::size_t i = 0; i < other.size(); ++i) {
89 (void)data_->push_back(other[i]);
90 }
91 }
92 void swap(Storage &other) noexcept { data_.swap(other.data_); }
93
94 private:
95 std::unique_ptr<rt::StaticVector<Piece, WindowCapacity>> data_;
96 };
97
98 double joints_[MaxAxes] = {};
99 double window_joints_[MaxAxes] = {};
100 CartesianSegment active_segment_{};
101 otg::Profile1D halt_profile_{};
102 Storage window_{};
103 Storage staging_window_{};
104 rt::ErrorCode last_error_ = rt::ErrorCode::ok;
105 std::uint32_t window_last_id_ = 0;
106 std::size_t piece_index_ = 0;
107 std::int64_t piece_tick_ = 0;
108 std::int64_t halt_tick_ = 0;
109 std::int64_t halt_duration_ = 0;
110 double halt_origin_ = 0.0;
111 double halt_piece_offset_ = 0.0;
112 double window_entry_velocity_ = 0.0;
113 double window_entry_acceleration_ = 0.0;
114 double window_acceleration_ = 0.0;
115 double window_deceleration_ = 0.0;
116 double window_jerk_ = 0.0;
117 bool window_active_ = false;
118 bool window_stopping_ = false;
119 bool window_pose_ = false;
120
121 // Math-Max Step 5 (Y7b2b): fixed-capacity Cartesian LINE takeover connector state.
122 std::array<otg::Profile1D, 3> takeover_residuals_{};
123 std::int64_t takeover_residual_duration_ = 0;
124 double takeover_tcp_tube_ = 0.0;
125 bool takeover_active_ = false;
126 bool takeover_stopping_ = false;
127 bool active_safe_envelope_ = false;
128 bool active_replay_only_takeover_ = false;
129 otg::Limits1D active_safe_limits_{};
130 bool pending_takeover_grid_valid_ = false;
131 std::array<std::array<double, 3>, 33> pending_takeover_grid_{};
132
133 // Pre-abort_motion() verified staging slot (atomic rejection if unprovable).
134 bool staged_takeover_valid_ = false;
135 bool staged_takeover_is_connector_ = false;
136 bool staged_takeover_has_safe_envelope_ = false;
137 otg::Profile1D staged_base_profile_{};
138 std::int64_t staged_base_duration_ = 0;
139 std::array<otg::Profile1D, 3> staged_residuals_{};
140 std::int64_t staged_residual_duration_ = 0;
141 double staged_tcp_tube_ = 0.0;
142 otg::Limits1D staged_safe_limits_{};
143
144 void clear_takeover()
145 {
146 takeover_active_ = false;
147 takeover_stopping_ = false;
148 takeover_residual_duration_ = 0;
149 takeover_tcp_tube_ = 0.0;
150 for(std::size_t i = 0; i < 3; ++i) {
151 takeover_residuals_[i] = otg::Profile1D{};
152 }
153 }
154
155 void clear_envelope()
156 {
157 active_safe_envelope_ = false;
158 active_replay_only_takeover_ = false;
159 active_safe_limits_ = otg::Limits1D{};
160 }
161
162 void clear_staged_takeover()
163 {
164 staged_takeover_valid_ = false;
165 staged_takeover_is_connector_ = false;
166 staged_takeover_has_safe_envelope_ = false;
167 staged_base_profile_ = otg::Profile1D{};
168 staged_base_duration_ = 0;
169 staged_residual_duration_ = 0;
170 staged_tcp_tube_ = 0.0;
171 staged_safe_limits_ = otg::Limits1D{};
172 for(std::size_t i = 0; i < 3; ++i) {
173 staged_residuals_[i] = otg::Profile1D{};
174 }
175 }
176};
177
178} // namespace plcopen::core::axis