plcopen 0.22.0
载入中...
搜索中...
未找到
path_table.h
浏览该文件的文档.
1#pragma once
2
3#include <array>
4#include <cmath>
5#include <cstddef>
6#include <cstdint>
7
8#include "axis/group.h"
9#include "axis/state.h"
10#include "fb/motion.h"
11#include "rt/error.h"
12
13namespace plcopen::core::fb
14{
15
16// Part 4 path table and transform FBs (approved matrix 2026-07-07).
17
18// Waypoint for MC_PathSelect/MC_MovePath.
30
31// Supplier-specific MC_PATH_REF. The caller owns this fixed-capacity source
32// description and may reuse it after PathSelect returns.
34{
35 static constexpr std::size_t MaxWaypoints = 32;
36
38 std::size_t count = 0;
39};
40
41// Supplier-specific MC_PATH_DATA_REF. The caller owns the selected result;
42// PathSelect copies a validated description into it and MovePath consumes it.
44{
45 static constexpr std::size_t MaxWaypoints = PathDescription::MaxWaypoints;
46
48 std::size_t count = 0;
49 std::uint32_t handle = 0;
50 std::size_t axis_count = 0;
51};
52
54 std::size_t axis_count)
55{
56 if(waypoint.target.size != axis_count) return rt::ErrorCode::invalid_argument;
57 for(std::size_t axis_index = 0; axis_index < axis_count; ++axis_index) {
58 if(!std::isfinite(waypoint.target.value[axis_index])) {
60 }
61 }
62 if(!std::isfinite(waypoint.velocity) || waypoint.velocity <= 0.0 ||
63 !std::isfinite(waypoint.acceleration) || waypoint.acceleration <= 0.0 ||
64 !std::isfinite(waypoint.deceleration) || waypoint.deceleration <= 0.0 ||
65 !std::isfinite(waypoint.jerk) || waypoint.jerk <= 0.0 ||
66 !std::isfinite(waypoint.transition_parameter)) {
68 }
72 }
74 return waypoint.transition_parameter == 0.0
77 }
79 return waypoint.transition_parameter > 0.0
82 }
84}
85
86// MC_PathSelect: validate a source description and publish a selected result.
88{
89public:
91 PathTable *path_data = nullptr;
93 bool execute = false;
95
96 void call()
97 {
98 const bool rising = execute && !last_execute_;
99 last_execute_ = execute;
100 if(!execute) {
101 clear(outputs);
102 return;
103 }
104 if(!rising) {
105 return;
106 }
107 clear(outputs);
108 if(group_ref == nullptr || path_data == nullptr || path_description == nullptr) {
109 outputs.error = true;
111 return;
112 }
113 if(path_description->count < 2 ||
115 outputs.error = true;
117 return;
118 }
119 const std::size_t n_axes = group_ref->member_count();
120 if(n_axes < 2) {
121 outputs.error = true;
123 return;
124 }
125 for(std::size_t i = 0; i < path_description->count; ++i) {
126 const PathWaypoint &wp = path_description->waypoints[i];
127 const rt::ErrorCode valid = validate_path_waypoint(wp, n_axes);
128 if(valid != rt::ErrorCode::ok) {
129 outputs.error = true;
130 outputs.error_id = valid;
131 return;
132 }
133 }
134 PathTable selected{};
135 selected.count = path_description->count;
136 selected.axis_count = n_axes;
137 selected.handle = ++next_handle_;
138 if(selected.handle == 0) {
139 selected.handle = ++next_handle_;
140 }
141 for(std::size_t i = 0; i < selected.count; ++i) {
142 selected.waypoints[i] = path_description->waypoints[i];
143 }
144 *path_data = selected;
145 outputs.done = true;
146 }
147
148private:
149 bool last_execute_ = false;
150 std::uint32_t next_handle_ = 0;
151};
152
153// MC_MovePath: consume a validated path table handle and submit all
154// waypoints through the group's window machine as blending commands.
156{
157public:
163
164 void call()
165 {
166 if(rising_edge()) {
167 if(group_ref == nullptr || path_data == nullptr || path_data->handle == 0 ||
168 path_data->count < 2 ||
170 path_data->axis_count != group_ref->member_count()) {
172 return;
173 }
174 const rt::ErrorCode options = validate_options();
175 if(options != rt::ErrorCode::ok) {
177 return;
178 }
179 for(std::size_t i = 0; i < path_data->count; ++i) {
180 const rt::ErrorCode valid =
181 validate_path_waypoint(path_data->waypoints[i], path_data->axis_count);
182 if(valid != rt::ErrorCode::ok) {
184 return;
185 }
186 }
187 const PathWaypoint &first = path_data->waypoints[0];
188 axis::GroupCommand cmd{};
189 cmd.target = first.target;
190 cmd.velocity = first.velocity;
191 cmd.acceleration = first.acceleration;
192 cmd.deceleration = first.deceleration;
193 cmd.jerk = first.jerk;
199 const auto result = group_ref->submit_linear(cmd);
200 if(!result) {
201 accept(result);
202 return;
203 }
204 for(std::size_t i = 1; i < path_data->count; ++i) {
205 const PathWaypoint &wp = path_data->waypoints[i];
206 axis::GroupCommand seg{};
207 seg.target = wp.target;
208 seg.velocity = wp.velocity;
209 seg.acceleration = wp.acceleration;
210 seg.deceleration = wp.deceleration;
211 seg.jerk = wp.jerk;
216 if(i < path_data->count - 1 &&
219 } else {
221 }
222 const auto seg_result = group_ref->submit_linear(seg);
223 if(!seg_result) {
224 accept(seg_result);
225 return;
226 }
227 }
228 accept(result);
229 }
231 }
232
233private:
234 rt::ErrorCode validate_options() const
235 {
236 switch(coord_system) {
240 break;
245 default:
247 }
248 switch(buffer_mode) {
253 break;
254 default:
256 }
257 if(!std::isfinite(transition_parameter)) {
259 }
261 return transition_parameter == 0.0
264 }
267 }
270 }
273 }
274 return rt::ErrorCode::ok;
275 }
276};
277
279{
280public:
282 {
283 tuc_numerator.fill(1);
284 tuc_denominator.fill(1);
285 }
286
290 bool execute = false;
292 std::array<int, axis::AxisGroup::MaxAxes> tuc_numerator{};
293 std::array<int, axis::AxisGroup::MaxAxes> tuc_denominator{};
294 double acceleration = 0.0;
295 double deceleration = 0.0;
296 double jerk = 0.0;
300 bool in_sync = false;
301
302 void call()
303 {
304 const bool rising = execute && !last_execute_;
305 last_execute_ = execute;
306 if(!execute) {
307 clear(outputs);
308 in_sync = false;
309 tracked_command_id_ = 0;
310 return;
311 }
312 if(rising) {
313 submit();
314 }
315 observe();
316 }
317
318private:
319 void submit()
320 {
321 clear(outputs);
322 if(master_ref == nullptr || group_ref == nullptr || path_data == nullptr ||
324 !std::isfinite(acceleration) || !std::isfinite(deceleration) ||
325 !std::isfinite(jerk) || acceleration < 0.0 || deceleration < 0.0 || jerk < 0.0) {
326 outputs.error = true;
328 return;
329 }
330 for(std::size_t i = 0; i < path_data->count; ++i) {
331 sync_path_[i] = path_data->waypoints[i].target;
332 }
333 const rt::Result<std::uint32_t> accepted = group_ref->sync_group_to_axis(
334 *master_ref, sync_path_.data(), path_data->count, mode, tuc_numerator,
336 if(!accepted) {
337 outputs.error = true;
338 outputs.error_id = accepted.error();
339 return;
340 }
341 tracked_command_id_ = accepted.value();
342 outputs.command_id = tracked_command_id_;
344 outputs.busy = true;
345 outputs.active = true;
346 in_sync = true;
347 }
348
349 void observe()
350 {
351 if(tracked_command_id_ == 0 || group_ref == nullptr) return;
352 if(group_ref->group_to_axis_sync_active(tracked_command_id_)) {
353 outputs.busy = true;
354 outputs.active = true;
355 in_sync = true;
356 return;
357 }
358 if(group_ref->group_to_axis_sync_aborted(tracked_command_id_)) {
359 outputs.command_aborted = true;
360 }
361 outputs.busy = false;
362 outputs.active = false;
363 in_sync = false;
364 tracked_command_id_ = 0;
365 }
366
367 std::array<axis::GroupPosition, PathTable::MaxWaypoints> sync_path_{};
368 bool last_execute_ = false;
369 std::uint32_t tracked_command_id_ = 0;
370};
371
372// MC_SetKinTransform: FB facade for set_pose_kinematics / set_kinematics.
374{
375public:
378 double max_joint_step = 0.01;
380
381 void call()
382 {
383 if(rising_edge()) {
384 if(group_ref == nullptr) {
386 } else {
387 accept(group_ref->submit_kinematics(
390 }
391 }
392 observe();
393 }
394
395private:
396 void observe()
397 {
398 if(!execute || tracked_command_id_ == 0 || group_ref == nullptr ||
402 outputs.busy = false;
403 outputs.active = false;
404 return;
405 }
407 if(error != rt::ErrorCode::ok) {
408 outputs.error = true;
410 outputs.busy = false;
411 outputs.active = false;
412 return;
413 }
415 outputs.done = true;
416 outputs.busy = false;
417 outputs.active = false;
418 return;
419 }
420 outputs.busy = true;
422 }
423};
424
425// MC_ReadCartesianTransform: enable-based readback of frame configuration.
427{
428public:
430 bool enable = false;
431 bool valid = false;
432 bool error = false;
436 double trans_x = 0.0;
437 double trans_y = 0.0;
438 double trans_z = 0.0;
439 double rot_angle1 = 0.0;
440 double rot_angle2 = 0.0;
441 double rot_angle3 = 0.0;
442
443 void call()
444 {
445 if(!enable) {
446 valid = false;
447 error = false;
449 transform = {};
450 clear_scalars();
451 return;
452 }
453 if(group_ref == nullptr) {
454 valid = false;
455 error = true;
457 return;
458 }
459 transform = {};
460 const rt::ErrorCode result = group_ref->coordinate_transform(
462 if(result != rt::ErrorCode::ok) {
463 valid = false;
464 error = true;
465 error_id = result;
466 clear_scalars();
467 return;
468 }
469 trans_x = transform.value[0];
470 trans_y = transform.value[1];
471 trans_z = transform.value[2];
472 rot_angle1 = transform.value[3];
473 rot_angle2 = transform.value[4];
474 rot_angle3 = transform.value[5];
475 valid = true;
476 error = false;
478 }
479
480private:
481 void clear_scalars()
482 {
483 trans_x = trans_y = trans_z = 0.0;
485 }
486};
487
489{
490public:
494
495 void call()
496 {
497 if(rising_edge()) {
498 if(group_ref == nullptr) {
500 } else {
501 accept(group_ref->submit_coordinate_transform(
503 }
504 }
505 observe();
506 }
507
508private:
509 void observe()
510 {
511 if(!execute || tracked_command_id_ == 0 || group_ref == nullptr ||
515 outputs.busy = false;
516 outputs.active = false;
517 return;
518 }
520 if(error != rt::ErrorCode::ok) {
521 outputs.error = true;
523 outputs.busy = false;
524 outputs.active = false;
525 return;
526 }
528 outputs.done = true;
529 outputs.busy = false;
530 outputs.active = false;
531 return;
532 }
533 outputs.busy = true;
535 }
536};
537
539{
540public:
543 double trans_x = 0.0;
544 double trans_y = 0.0;
545 double trans_z = 0.0;
546 double rot_angle1 = 0.0;
547 double rot_angle2 = 0.0;
548 double rot_angle3 = 0.0;
549
550 void call()
551 {
552 if(rising_edge()) {
553 if(group_ref == nullptr) {
555 } else {
556 axis::ToolData transform{};
557 transform.value = {trans_x, trans_y, trans_z,
559 accept(group_ref->submit_coordinate_transform(
560 coordinate_system, transform, execution_mode));
561 }
562 }
563 observe();
564 }
565
566private:
567 void observe()
568 {
569 if(!execute || tracked_command_id_ == 0 || group_ref == nullptr ||
573 outputs.busy = false;
574 outputs.active = false;
575 return;
576 }
578 if(error != rt::ErrorCode::ok) {
579 outputs.error = true;
581 outputs.busy = false;
582 outputs.active = false;
583 return;
584 }
586 outputs.done = true;
587 outputs.busy = false;
588 outputs.active = false;
589 return;
590 }
591 outputs.busy = true;
593 }
594};
595
597{
598public:
600 bool enable = false;
601 bool valid = false;
602 bool error = false;
605
606 void call()
607 {
608 if(!enable) {
609 valid = false;
610 error = false;
612 kin_transform = {};
613 return;
614 }
615 if(group_ref == nullptr) {
616 valid = false;
617 error = true;
619 kin_transform = {};
620 return;
621 }
622 kin_transform = group_ref->kin_transform();
623 valid = true;
624 error = false;
626 }
627};
628
630{
631public:
633 bool enable = false;
635 bool valid = false;
636 bool error = false;
639
640 void call()
641 {
642 if(!enable) {
643 valid = false;
644 error = false;
646 transform = {};
647 return;
648 }
649 if(group_ref == nullptr) {
650 valid = false;
651 error = true;
653 return;
654 }
655 const rt::ErrorCode result =
656 group_ref->coordinate_transform(coordinate_system, transform);
657 valid = result == rt::ErrorCode::ok;
658 error = !valid;
659 error_id = result;
660 }
661};
662
664{
665public:
667 bool enable = false;
671 bool valid = false;
672 bool busy = false;
673 bool error = false;
676 bool singular_position = false;
677
678 void call()
679 {
680 if(!enable) {
681 valid = false;
682 busy = false;
683 error = false;
685 output_position = {};
686 singular_position = false;
687 return;
688 }
689 if(group_ref == nullptr) {
690 valid = false;
691 busy = false;
692 error = true;
694 return;
695 }
696 const rt::ErrorCode result = group_ref->transform_position(
698 valid = result == rt::ErrorCode::ok;
699 busy = false;
700 error = !valid;
701 error_id = result;
702 }
703};
704
705} // namespace plcopen::core::fb
bool management_command_active(std::uint32_t command_id) const
rt::Result< std::uint32_t > sync_group_to_axis(AxisModel &master, const GroupPosition *waypoints, std::size_t count, PathMode mode, const std::array< int, MaxAxes > &tuc_numerator, const std::array< int, MaxAxes > &tuc_denominator, CoordSystem coord_system, BufferMode buffer_mode)
bool management_command_aborted(std::uint32_t command_id) const
bool management_command_done(std::uint32_t command_id) const
std::size_t member_count() const
rt::ErrorCode management_command_error(std::uint32_t command_id) const
axis::TransitionMode transition_mode
const PathDescription * path_description
std::array< int, axis::AxisGroup::MaxAxes > tuc_denominator
std::array< int, axis::AxisGroup::MaxAxes > tuc_numerator
void accept(rt::Result< std::uint32_t > accepted)
static constexpr Result failure(ErrorCode error)
定义 error.h:29
void clear(MotionOutputs &outputs)
rt::ErrorCode validate_path_waypoint(const PathWaypoint &waypoint, std::size_t axis_count)
InterpolationSpace interpolation_space
std::array< double, MaxAxes > value
定义 group.h:30
std::array< double, 6 > value
PathWaypoint waypoints[MaxWaypoints]
static constexpr std::size_t MaxWaypoints
PathWaypoint waypoints[MaxWaypoints]
static constexpr std::size_t MaxWaypoints
axis::TransitionMode transition_mode
axis::InterpolationSpace interpolation_space