plcopen 0.22.0
载入中...
搜索中...
未找到
group.h
浏览该文件的文档.
1#pragma once
2
3#include <cstdint>
4
5#include "axis/group.h"
6#include "axis/state.h"
7#include "fb/motion.h"
8#include "rt/error.h"
9
10namespace plcopen::core::fb
11{
12
13// Execute-based group administration facades. The group methods complete
14// within the triggering cycle; done clears on the falling edge.
16{
17 public:
20 bool execute = false;
22
23 protected:
25 {
26 const bool rising = execute && !last_execute_;
27 last_execute_ = execute;
28 if (!execute)
29 {
31 }
32 return rising;
33 }
34
35 void finish(rt::ErrorCode result)
36 {
38 if (result != rt::ErrorCode::ok)
39 {
40 outputs.error = true;
41 outputs.error_id = result;
42 return;
43 }
44 outputs.done = true;
45 }
46
47 private:
48 bool last_execute_ = false;
49};
50
52{
53 public:
55
56 void call()
57 {
58 if (!rising_edge())
59 {
60 return;
61 }
62 if (group_ref == nullptr || axis_ref == nullptr)
63 {
65 return;
66 }
68 }
69};
70
72{
73 public:
75
76 void call()
77 {
78 if (!rising_edge())
79 {
80 return;
81 }
82 if (group_ref == nullptr)
83 {
85 return;
86 }
87 finish(axis_ref != nullptr ? group_ref->remove_axis(*axis_ref)
88 : group_ref->remove_axis(ident_in_group));
89 }
90};
91
93{
94 public:
95 void call()
96 {
97 if (!rising_edge())
98 {
99 return;
100 }
101 if (group_ref == nullptr)
102 {
104 return;
105 }
106 finish(group_ref->reset());
107 }
108};
109
110// Enable-based group status read. moving/standby fold in member-level
111// synchronization so gear/cam slaves keep the v0.x observable group state.
113{
114 public:
116 bool enable = false;
117 bool valid = false;
118 bool error = false;
120 bool disabled = false;
121 bool standby = false;
122 bool moving = false;
123 bool stopping = false;
124 bool error_stop = false;
125 bool interrupted = false;
126 bool group_homing = false;
127
128 void call()
129 {
130 disabled = false;
131 standby = false;
132 moving = false;
133 stopping = false;
134 error_stop = false;
135 interrupted = false;
136 group_homing = false;
137 if (!enable)
138 {
139 valid = false;
140 error = false;
142 return;
143 }
144 if (group_ref == nullptr)
145 {
146 valid = false;
147 error = true;
149 return;
150 }
151 const axis::GroupStatus status = group_ref->status();
152 bool member_synchronized = false;
153 bool member_homing = group_ref->group_homing();
154 for (std::size_t i = 0; i < group_ref->member_count(); ++i)
155 {
156 const axis::AxisModel *axis = group_ref->member(i);
157 if (axis != nullptr && axis->status() == axis::AxisStatus::synchronized_motion)
158 {
159 member_synchronized = true;
160 }
161 if(axis != nullptr && axis->status() == axis::AxisStatus::homing) {
162 member_homing = true;
163 }
164 }
166 group_homing = status == axis::GroupStatus::standby && member_homing;
167 standby = status == axis::GroupStatus::standby && !member_synchronized && !member_homing;
168 moving = status == axis::GroupStatus::moving ||
169 (status == axis::GroupStatus::standby && member_synchronized);
173 valid = true;
174 error = false;
176 }
177};
178
179// Enable-based member position reads. Readback batch (approved matrix
180// decision #6): the coord_system input routes MCS/PCS reads through
181// AxisGroup::read_cartesian; the ACS default stays the raw member-slot
182// read, byte-identical to the pre-batch behavior.
184{
185 public:
187 bool enable = false;
189 bool valid = false;
190 bool error = false;
191 bool gimbal_lock = false;
194
195 protected:
196 void read(bool actual)
197 {
198 gimbal_lock = false;
199 if (!enable)
200 {
201 valid = false;
202 error = false;
204 position = {};
205 return;
206 }
207 if (group_ref == nullptr)
208 {
209 valid = false;
210 error = true;
212 position = {};
213 return;
214 }
216 {
217 bool gimbal = false;
218 const rt::ErrorCode code = group_ref->read_cartesian(
220 position, &gimbal);
221 if (code != rt::ErrorCode::ok)
222 {
223 valid = false;
224 error = true;
225 error_id = code;
226 position = {};
227 return;
228 }
229 gimbal_lock = gimbal;
230 valid = true;
231 error = false;
233 return;
234 }
235 position.size = group_ref->member_count();
236 for (std::size_t i = 0; i < position.size; ++i)
237 {
238 const axis::AxisModel *axis = group_ref->member(i);
239 const axis::AxisSnapshot &snapshot = axis->snapshot();
240 position.value[i] = actual ? snapshot.actual_position : snapshot.command_position;
241 }
242 valid = true;
243 error = false;
245 }
246};
247
249{
250 public:
251 void call()
252 {
253 if (!rising_edge())
254 return;
255 if (group_ref == nullptr)
256 {
258 return;
259 }
260 finish(group_ref->ungroup_all_axes());
261 }
262};
263
265{
266 public:
268 bool enable = false;
269 bool status = false;
270 bool valid = false;
271 bool error = false;
273
274 void call()
275 {
276 if (group_ref == nullptr)
277 {
278 status = false;
279 valid = false;
280 error = true;
282 return;
283 }
284 const rt::ErrorCode result = group_ref->set_group_power(enable);
285 status = group_ref->group_powered();
286 error = result != rt::ErrorCode::ok;
287 error_id = result;
288 valid = !error;
289 }
290};
291
313
315{
316 public:
318 bool enable = false;
319 bool valid = false;
320 bool error = false;
323
324 void call()
325 {
326 if (!enable)
327 {
328 valid = false;
329 error = false;
332 return;
333 }
334 if (group_ref == nullptr)
335 {
336 valid = false;
337 error = true;
340 return;
341 }
342 group_error_id = group_ref->group_error();
343 valid = true;
344 error = false;
346 }
347};
348
350{
351 public:
353 bool enable = false;
356 bool valid = false;
357 bool busy = false;
358 bool error = false;
360 const axis::AxisModel *axis_ref = nullptr;
361 std::size_t axis_id = 0;
362
363 void call()
364 {
365 valid = false;
366 busy = false;
367 error = false;
369 axis_ref = nullptr;
370 axis_id = 0;
371 if (!enable)
372 return;
373 if (group_ref == nullptr)
376 {
377 return fail(rt::ErrorCode::unsupported);
378 }
379 axis_ref = group_ref->member(ident);
380 if (axis_ref == nullptr)
381 return fail(rt::ErrorCode::out_of_range);
382 axis_id = ident.index;
383 valid = true;
384 }
385
386 private:
387 void fail(rt::ErrorCode code)
388 {
389 error = true;
390 error_id = code;
391 axis_ref = nullptr;
392 axis_id = 0;
393 }
394};
395
397{
398 public:
399 const axis::AxisModel *axis_ref = nullptr;
400 bool enable = false;
401 bool valid = false;
402 bool busy = false;
403 bool error = false;
406 std::size_t group_id = 0;
408
409 void call()
410 {
411 valid = false;
412 busy = false;
413 error = false;
415 group_ref = nullptr;
416 group_id = 0;
417 ident = {};
418 if (!enable)
419 return;
420 if (axis_ref == nullptr || axis_ref->group_owner() == nullptr)
421 {
422 return fail(axis_ref == nullptr ? rt::ErrorCode::invalid_argument
424 }
425 group_ref = static_cast<axis::AxisGroup *>(axis_ref->group_owner());
426 ident = group_ref->member_ident(*axis_ref);
427 if (ident.index == static_cast<std::size_t>(-1))
428 {
429 group_ref = nullptr;
431 }
432 valid = true;
433 }
434
435 private:
436 void fail(rt::ErrorCode code)
437 {
438 error = true;
439 error_id = code;
440 }
441};
442
444{
445 public:
447 bool enable = false;
448 bool valid = false;
449 bool busy = false;
450 bool error = false;
453
454 void call()
455 {
456 clear();
457 if (!enable)
458 return;
459 if (group_ref == nullptr)
461 const rt::Result<axis::GroupKinematicsInfo> info = group_ref->kinematics_info();
462 if (!info)
463 return fail(info.error());
464 parameters.count = info.value().count;
465 for (std::size_t i = 0; i < parameters.count; ++i)
466 {
467 parameters.value[i] = info.value().dh[i];
468 }
469 valid = true;
470 }
471
472 private:
473 void clear()
474 {
475 valid = false;
476 busy = false;
477 error = false;
479 parameters = {};
480 }
481 void fail(rt::ErrorCode code)
482 {
483 error = true;
484 error_id = code;
485 }
486};
487
489{
490 public:
492 bool enable = false;
493 bool valid = false;
494 bool busy = false;
495 bool error = false;
498
499 void call()
500 {
501 clear();
502 if (!enable)
503 return;
504 if (group_ref == nullptr)
506 const rt::Result<axis::GroupKinematicsInfo> metadata = group_ref->kinematics_info();
507 if (!metadata)
508 return fail(metadata.error());
509 info.count = metadata.value().count;
510 for (std::size_t i = 0; i < info.count; ++i)
511 {
512 info.value[i] = metadata.value().joint[i];
513 }
514 valid = true;
515 }
516
517 private:
518 void clear()
519 {
520 valid = false;
521 busy = false;
522 error = false;
524 info = {};
525 }
526 void fail(rt::ErrorCode code)
527 {
528 error = true;
529 error_id = code;
530 }
531};
532
550
552{
553 public:
555 bool enable = false;
558 bool valid = false;
559 bool busy = false;
560 bool error = false;
563 double path_value = 0.0;
564
565 protected:
566 void read(bool acceleration)
567 {
568 valid = false;
569 busy = false;
570 error = false;
572 value = {};
573 path_value = 0.0;
574 if (!enable)
575 return;
576 if (group_ref == nullptr)
579 {
580 return fail(rt::ErrorCode::unsupported);
581 }
582 value.size = group_ref->member_count();
583 for (std::size_t i = 0; i < value.size; ++i)
584 {
585 const axis::AxisSnapshot &snapshot = group_ref->member(i)->snapshot();
587 {
588 value.value[i] =
589 acceleration ? snapshot.actual_acceleration : snapshot.actual_velocity;
590 }
591 else
592 {
593 value.value[i] =
594 acceleration ? snapshot.command_acceleration : snapshot.command_velocity;
595 }
596 }
597 path_value = group_ref->path_derivative(acceleration);
598 valid = true;
599 }
600
601 private:
602 void fail(rt::ErrorCode code)
603 {
604 error = true;
605 error_id = code;
606 }
607};
608
610{
611 public:
612 void call() { read(false); }
613};
614
616{
617 public:
618 void call() { read(true); }
619};
620
622{
623 public:
625 bool enable = false;
626 bool valid = false;
627 bool busy = false;
628 bool error = false;
630 bool tracking = false;
631 bool in_sync = false;
632 bool in_position = false;
633 bool standstill = false;
634 bool constant_velocity = false;
635 bool accelerating = false;
636 bool decelerating = false;
637 std::uint32_t active_command_id = 0;
638
639 void call()
640 {
641 valid = false;
642 busy = false;
643 error = false;
645 tracking = false;
646 in_sync = false;
647 in_position = false;
648 standstill = false;
649 constant_velocity = false;
650 accelerating = false;
651 decelerating = false;
653 if (!enable)
654 return;
655 if (group_ref == nullptr)
656 {
657 error = true;
659 return;
660 }
661 const axis::GroupMotionState state = group_ref->motion_state();
662 if (group_ref->status() == axis::GroupStatus::disabled ||
664 {
665 error = true;
667 return;
668 }
669 tracking = state.tracking;
670 in_sync = state.in_sync;
671 in_position = state.in_position;
672 standstill = state.standstill;
677 valid = true;
678 }
679};
680
682{
683 public:
685 bool enable = false;
686 std::uint32_t command_id = 0;
687 bool valid = false;
688 bool busy = false;
689 bool error = false;
692
693 void call()
694 {
695 valid = false;
696 busy = false;
697 error = false;
699 info = {};
700 if (!enable)
701 return;
702 if (group_ref == nullptr)
704 const rt::Result<axis::GroupCommandInfo> result = group_ref->command_info(command_id);
705 if (!result)
706 return fail(result.error());
707 info = result.value();
708 valid = true;
709 }
710
711 private:
712 void fail(rt::ErrorCode code)
713 {
714 error = true;
715 error_id = code;
716 }
717};
719{
720 public:
722 bool execute = false;
724
725 protected:
727 {
728 const bool rising = execute && !last_execute_;
729 last_execute_ = execute;
730 if (!execute)
731 {
732 clear(outputs);
734 }
735 return rising;
736 }
738 {
739 clear(outputs);
740 if (result == rt::ErrorCode::ok)
741 outputs.done = true;
742 else
743 {
744 outputs.error = true;
745 outputs.error_id = result;
746 }
747 }
748
750 {
751 clear(outputs);
752 if(!result) {
753 outputs.error = true;
754 outputs.error_id = result.error();
756 return;
757 }
758 tracked_command_id_ = result.value();
759 outputs.command_id = tracked_command_id_;
760 outputs.command_accepted = true;
761 outputs.busy = true;
762 }
763
765 {
766 if(!execute || tracked_command_id_ == 0 || group_ref == nullptr ||
767 outputs.done || outputs.error || outputs.command_aborted) return;
768 if(group_ref->management_command_aborted(tracked_command_id_)) {
769 outputs.command_aborted = true;
770 outputs.busy = false;
771 outputs.active = false;
772 return;
773 }
774 const rt::ErrorCode error = group_ref->management_command_error(tracked_command_id_);
775 if(error != rt::ErrorCode::ok) {
776 outputs.error = true;
777 outputs.error_id = error;
778 outputs.busy = false;
779 outputs.active = false;
780 return;
781 }
782 if(group_ref->management_command_done(tracked_command_id_)) {
783 outputs.done = true;
784 outputs.busy = false;
785 outputs.active = false;
786 return;
787 }
788 outputs.busy = true;
789 outputs.active = group_ref->management_command_active(tracked_command_id_);
790 }
791
792 std::uint32_t tracked_command_id_ = 0;
793
794 private:
795 bool last_execute_ = false;
796};
797
799{
800 public:
802 bool enable = false;
803 bool valid = false;
804 bool busy = false;
805 bool error = false;
807
808 protected:
809 bool begin()
810 {
811 valid = false;
812 busy = false;
813 error = false;
815 if (!enable)
816 return false;
817 if (group_ref == nullptr)
818 {
820 return false;
821 }
822 return true;
823 }
824 void succeed() { valid = true; }
825 void fail(rt::ErrorCode result)
826 {
827 error = true;
828 error_id = result;
829 }
830};
831
833{
834 public:
836 double value = 0.0;
837 void call()
838 {
839 value = 0.0;
840 if (!begin())
841 return;
842 const rt::Result<double> result = group_ref->read_group_parameter(parameter);
843 if (!result)
844 return fail(result.error());
845 value = result.value();
846 succeed();
847 }
848};
849
866
868{
869 public:
870 double velocity = 0.0;
871 double acceleration = 0.0;
872 double deceleration = 0.0;
873 double jerk = 0.0;
874
875 protected:
877};
878
880{
881 public:
882 void call()
883 {
884 if (!rising_edge())
885 return;
887 : group_ref->write_reference_dynamics(update()));
888 }
889};
890
892{
893 public:
894 void call()
895 {
896 if (!rising_edge())
897 return;
899 : group_ref->write_default_dynamics(update()));
900 }
901};
902
908
910{
911 public:
912 void call()
913 {
914 value = {};
915 if (!begin())
916 return;
917 value = group_ref->reference_dynamics();
918 succeed();
919 }
920};
921
923{
924 public:
925 void call()
926 {
927 value = {};
928 if (!begin())
929 return;
930 value = group_ref->default_dynamics();
931 succeed();
932 }
933};
934
936{
937 public:
939 void call()
940 {
941 if (!rising_edge())
942 return;
944 : group_ref->write_jogging_dynamics(value));
945 }
946};
947
949{
950 public:
952 void call()
953 {
954 value = {};
955 if (!begin())
956 return;
957 value = group_ref->jogging_dynamics();
958 succeed();
959 }
960};
961
963{
964 public:
966 void call()
967 {
968 limit_values = {};
969 if (!begin())
970 return;
971 const rt::Result<axis::GroupSWLimits> result = group_ref->group_sw_limits();
972 if (!result)
973 return fail(result.error());
974 limit_values = result.value();
975 succeed();
976 }
977};
978
994
1011
1013{
1014 public:
1015 std::size_t tool_number = 0;
1017 void call()
1018 {
1019 tool_data = {};
1020 if (!begin())
1021 return;
1022 const rt::Result<axis::ToolData> result = group_ref->read_tool_data(tool_number);
1023 if (!result)
1024 return fail(result.error());
1025 tool_data = result.value();
1026 succeed();
1027 }
1028};
1029
1031{
1032 public:
1033 std::size_t tool_number = 0;
1034 void call()
1035 {
1036 if (!rising_edge())
1037 return;
1039 : group_ref->select_tool(tool_number));
1040 }
1041};
1042
1044{
1045 public:
1047 std::size_t tool_number = 0;
1048 void call()
1049 {
1050 tool_number = 0;
1051 if (!begin())
1052 return;
1054 {
1056 }
1057 tool_number = group_ref->read_tool(source);
1058 succeed();
1059 }
1060};
1061
1063{
1064 public:
1065 std::size_t payload_number = 0;
1067 void call()
1068 {
1069 if (!rising_edge())
1070 return;
1072 : group_ref->write_payload_data(payload_number, payload_data));
1073 }
1074};
1075
1077{
1078 public:
1079 std::size_t payload_number = 0;
1081 void call()
1082 {
1083 payload_data = {};
1084 if (!begin())
1085 return;
1086 const rt::Result<axis::PayloadData> result = group_ref->read_payload_data(payload_number);
1087 if (!result)
1088 return fail(result.error());
1089 payload_data = result.value();
1090 succeed();
1091 }
1092};
1093
1095{
1096 public:
1097 std::size_t payload_number = 0;
1098 void call()
1099 {
1100 if (!rising_edge())
1101 return;
1103 : group_ref->select_payload(payload_number));
1104 }
1105};
1106
1108{
1109 public:
1111 std::size_t payload_number = 0;
1112 void call()
1113 {
1114 payload_number = 0;
1115 if (!begin())
1116 return;
1118 {
1120 }
1121 payload_number = group_ref->read_payload(source);
1122 succeed();
1123 }
1124};
1125
1127{
1128 public:
1129 std::size_t rigid_body_count = 0;
1130 std::array<axis::RigidBodyDynamic, axis::AxisGroup::RigidBodyCapacity> rigid_body_dynamic{};
1131
1132 void call()
1133 {
1134 if (!rising_edge())
1135 return;
1136 if (group_ref == nullptr)
1139 data.count = rigid_body_count;
1141 finish(group_ref->write_rigid_body_dynamics(data));
1142 }
1143};
1144
1146{
1147 public:
1148 std::size_t rigid_body_count = 0;
1149 std::array<axis::RigidBodyDynamic, axis::AxisGroup::RigidBodyCapacity> rigid_body_dynamic{};
1150
1151 void call()
1152 {
1153 rigid_body_count = 0;
1154 rigid_body_dynamic = {};
1155 if (!begin())
1156 return;
1157 const rt::Result<axis::RigidBodyDynamics> result = group_ref->rigid_body_dynamics();
1158 if (!result)
1159 return fail(result.error());
1160 rigid_body_count = result.value().count;
1161 rigid_body_dynamic = result.value().value;
1162 succeed();
1163 }
1164};
1165
1167{
1168 public:
1170 bool enable = false;
1172 double vel_override = 1.0;
1173 double acc_override = 1.0;
1174 bool enabled = false;
1175 bool active = false;
1176 bool command_aborted = false;
1177 bool error = false;
1179
1180 protected:
1181 void apply(const axis::GroupPosition &direction,
1182 double max_linear_distance = 0.0,
1183 double max_angular_distance = 0.0)
1184 {
1186 max_linear_distance,
1187 max_angular_distance};
1188 command_aborted = false;
1189 if (!enable)
1190 {
1191 if (last_enable_ && group_ref != nullptr && command_id_ != 0)
1192 {
1193 group_ref->release_jog(command_id_);
1194 }
1195 last_enable_ = false;
1196 command_id_ = 0;
1197 enabled = false;
1198 active = false;
1199 error = false;
1201 return;
1202 }
1203 if (group_ref == nullptr)
1205 if (last_enable_ && group_ref->jog_command_aborted(command_id_))
1206 {
1207 enabled = false;
1208 active = false;
1209 command_aborted = true;
1210 error = false;
1212 return;
1213 }
1214 if (!last_enable_)
1215 {
1216 const rt::Result<std::uint32_t> started =
1217 group_ref->begin_jog(coord_system, direction, options);
1218 if (!started)
1219 return fail(started.error());
1220 command_id_ = started.value();
1221 }
1222 else
1223 {
1224 const rt::ErrorCode updated =
1225 group_ref->update_jog(command_id_, direction, options);
1226 if (updated != rt::ErrorCode::ok)
1227 return fail(updated);
1228 }
1229 last_enable_ = true;
1230 enabled = true;
1231 active = group_ref->jog_command_active(command_id_) &&
1233 command_aborted = group_ref->jog_command_aborted(command_id_);
1234 error_id = group_ref->jog_error();
1236 if (command_aborted)
1237 {
1238 enabled = false;
1239 active = false;
1240 }
1241 }
1242
1243 private:
1244 void fail(rt::ErrorCode code)
1245 {
1246 last_enable_ = true;
1247 enabled = false;
1248 active = false;
1249 error = true;
1250 error_id = code;
1251 }
1252
1253 std::uint32_t command_id_ = 0;
1254 bool last_enable_ = false;
1255};
1256
1258{
1259 public:
1264
1265 void call()
1266 {
1267 axis::GroupPosition direction{};
1268 direction.size = jog_positive.count;
1269 if (jog_positive.count != jog_negative.count)
1270 {
1271 direction.size = 0;
1272 }
1273 else
1274 {
1275 for (std::size_t i = 0; i < direction.size; ++i)
1276 {
1277 direction.value[i] = jog_positive.value[i] == jog_negative.value[i]
1278 ? 0.0
1279 : (jog_positive.value[i] ? 1.0 : -1.0);
1280 }
1281 }
1283 }
1284};
1285
1295
1296} // namespace plcopen::core::fb
axis::JogBooleanArray jog_positive
axis::JogBooleanArray jog_negative
std::array< axis::RigidBodyDynamic, axis::AxisGroup::RigidBodyCapacity > rigid_body_dynamic
std::array< axis::RigidBodyDynamic, axis::AxisGroup::RigidBodyCapacity > rigid_body_dynamic
axis::DHParameterArray parameters
void finish(rt::ErrorCode result)
定义 group.h:35
void fail(rt::ErrorCode result)
void accept(rt::Result< std::uint32_t > result)
void finish(rt::ErrorCode result)
axis::CoordSystem coord_system
void apply(const axis::GroupPosition &direction, double max_linear_distance=0.0, double max_angular_distance=0.0)
constexpr const T & value() const
定义 error.h:49
constexpr ErrorCode error() const
定义 error.h:44
static constexpr Result failure(ErrorCode error)
定义 error.h:29
GroupArray< bool > JogBooleanArray
定义 group.h:61
GroupArray< JointInfo > JointInfoArray
定义 group.h:60
GroupArray< DHParameter > DHParameterArray
定义 group.h:59
GroupArray< GroupSWLimit > GroupSWLimits
void clear(MotionOutputs &outputs)
std::array< double, MaxAxes > value
定义 group.h:30
std::array< RigidBodyDynamic, GroupPosition::MaxAxes+1 > value