plcopen 0.22.0
载入中...
搜索中...
未找到
parameter.h
浏览该文件的文档.
1#pragma once
2
3#include "axis/state.h"
4#include "fb/base.h"
5#include "fb/motion.h"
6#include "rt/error.h"
7
8namespace plcopen::core::fb
9{
10
11// Enable-based numeric read (MC_ReadParameter). Unsupported parameters report
12// rt::ErrorCode::unsupported; a missing axis reports invalid_argument.
14{
15 public:
18 double value = 0.0;
19
20 void call()
21 {
22 if (!begin_enable())
23 {
24 if (!enable)
25 value = 0.0;
26 return;
27 }
28 if (axis_ref == nullptr)
29 {
30 value = 0.0;
32 return;
33 }
34 const rt::Result<double> read = axis_ref->read_parameter(parameter_number);
35 if (!read)
36 {
37 value = 0.0;
38 fail_enable(read.error());
39 return;
40 }
41 value = read.value();
43 }
44};
45
47{
48 public:
51 bool value = false;
52
53 void call()
54 {
55 if (!begin_enable())
56 {
57 if (!enable)
58 value = false;
59 return;
60 }
61 if (axis_ref == nullptr)
62 {
63 value = false;
65 return;
66 }
67 const rt::Result<bool> read = axis_ref->read_bool_parameter(parameter_number);
68 if (!read)
69 {
70 value = false;
71 fail_enable(read.error());
72 return;
73 }
74 value = read.value();
76 }
77};
78
79// Execute-based writes use the axis management-command lifecycle. Immediate
80// mode applies in the triggering scan; queued mode remains Busy until the axis
81// motion queue drains and AxisModel executes the write.
108
135
136// Enable-based snapshot reads. The selector indirection keeps one implementation
137// for the five MC_Read* value blocks.
139{
140 public:
142 double value = 0.0;
143
144 protected:
153
154 void read(Field field)
155 {
156 if (!begin_enable())
157 {
158 if (!enable)
159 value = 0.0;
160 return;
161 }
162 if (axis_ref == nullptr)
163 {
164 value = 0.0;
166 return;
167 }
168 const axis::AxisSnapshot &snapshot = axis_ref->snapshot();
169 switch (field)
170 {
172 value = snapshot.actual_position;
173 break;
175 value = snapshot.actual_velocity;
176 break;
178 value = snapshot.actual_torque;
179 break;
181 value = snapshot.command_position;
182 break;
184 value = snapshot.command_velocity;
185 break;
186 }
188 }
189};
190
192{
193 public:
195};
196
198{
199 public:
201};
202
204{
205 public:
207};
208
210{
211 public:
213};
214
216{
217 public:
219};
220
221// MC_ReadStatus: one boolean per PLCopen axis state.
223{
224 public:
226 bool disabled = false;
227 bool standstill = false;
228 bool homing = false;
229 bool discrete_motion = false;
230 bool continuous_motion = false;
232 bool stopping = false;
233 bool error_stop = false;
234
235 void call()
236 {
237 clear_states();
238 if (!begin_enable())
239 {
240 return;
241 }
242 if (axis_ref == nullptr)
243 {
245 return;
246 }
247 const axis::AxisStatus status = axis_ref->status();
257 }
258
259 private:
260 void clear_states()
261 {
262 disabled = false;
263 standstill = false;
264 homing = false;
265 discrete_motion = false;
266 continuous_motion = false;
267 synchronized_motion = false;
268 stopping = false;
269 error_stop = false;
270 }
271};
272
274{
275 public:
277 bool axis_error = false;
279
280 void call()
281 {
282 if (!begin_enable())
283 {
284 if (!enable)
285 {
286 axis_error = false;
288 }
289 return;
290 }
291 if (axis_ref == nullptr)
292 {
293 axis_error = false;
296 return;
297 }
298 axis_error = axis_ref->snapshot().error;
299 axis_error_id = axis_ref->snapshot().error_id;
301 }
302};
303
304// MC_SetPosition: atomically remaps the public coordinate domain. Relative
305// mode is based on actual position and therefore applies the requested delta.
329
330} // namespace plcopen::core::fb
bool rising_edge(bool retain_active_on_falling=false)
void accept(rt::Result< std::uint32_t > accepted)
void accept_management(rt::Result< std::uint32_t > accepted)
void fail_enable(rt::ErrorCode code)
定义 base.h:142
static constexpr Result failure(ErrorCode error)
定义 error.h:29