plcopen 0.22.0
载入中...
搜索中...
未找到
motion.h
浏览该文件的文档.
1#pragma once
2
3#include <cmath>
4#include <cstdint>
5
6#include "axis/group.h"
7#include "axis/state.h"
8#include "rt/error.h"
9
10namespace plcopen::core::fb
11{
12
14{
15 bool done = false;
16 bool busy = false;
17 bool active = false;
18 bool command_accepted = false;
19 bool command_aborted = false;
20 bool error = false;
22 std::uint32_t command_id = 0;
23};
24
25inline void clear(MotionOutputs &outputs)
26{
27 outputs = {};
28}
29
31{
32public:
34 bool execute = false;
36
37protected:
38 bool rising_edge(bool retain_active_on_falling = false)
39 {
40 const bool rising = execute && !last_execute_;
41 const bool falling = !execute && last_execute_;
42 last_execute_ = execute;
43 if(rising || (!execute && terminal_low_cycle_)) {
46 terminal_low_cycle_ = false;
47 } else if(falling && terminal() && !retain_active_on_falling) {
50 }
51 return rising;
52 }
53
55 {
56 outputs.command_accepted = false;
57 outputs.command_aborted = false;
58 outputs.error = false;
59 outputs.error_id = rt::ErrorCode::ok;
60 if(!accepted) {
61 outputs.error = true;
62 outputs.error_id = accepted.error();
63 outputs.busy = false;
64 outputs.active = false;
66 return;
67 }
68 tracked_command_id_ = accepted.value();
69 outputs.command_id = tracked_command_id_;
70 outputs.command_accepted = true;
71 outputs.busy = true;
72 outputs.active = true;
73 outputs.done = false;
74 }
75
77 {
78 if(tracked_command_id_ == 0 || axis_ref == nullptr) {
79 return;
80 }
81 // Done holds while Execute stays high; a later takeover command must
82 // not retroactively turn a completed command into an aborted one.
83 if(outputs.done) {
84 return;
85 }
86 const axis::AxisSnapshot &snapshot = axis_ref->snapshot();
87 const rt::ErrorCode command_error = axis_ref->command_error(tracked_command_id_);
88 if(command_error != rt::ErrorCode::ok) {
89 outputs.error = true;
90 outputs.error_id = command_error;
91 outputs.command_aborted = false;
92 outputs.done = false;
93 outputs.busy = false;
94 outputs.active = false;
96 return;
97 }
99 outputs.busy = true;
100 outputs.active = true;
101 outputs.done = false;
102 return;
103 }
104 // A completed command reports done even when a queued or blending
105 // successor started within the same cycle.
107 outputs.done = true;
108 outputs.busy = false;
109 outputs.active = false;
111 return;
112 }
113 // A command waiting in the buffered queue is busy, not aborted.
114 if(axis_ref->command_pending(tracked_command_id_)) {
115 outputs.busy = true;
116 outputs.active = false;
117 return;
118 }
119 outputs.command_aborted = true;
120 outputs.busy = false;
121 outputs.active = false;
123 }
124
126 {
127 if(tracked_command_id_ == 0 || axis_ref == nullptr || outputs.done || outputs.error) {
128 return;
129 }
130 const rt::ErrorCode command_error =
131 axis_ref->management_command_error(tracked_command_id_);
132 if(command_error != rt::ErrorCode::ok) {
133 outputs.error = true;
134 outputs.error_id = command_error;
135 outputs.busy = false;
136 outputs.active = false;
138 return;
139 }
140 if(axis_ref->management_command_done(tracked_command_id_)) {
141 outputs.done = true;
142 outputs.busy = false;
143 outputs.active = false;
145 return;
146 }
147 outputs.busy = axis_ref->management_command_pending(tracked_command_id_) ||
148 axis_ref->management_command_active(tracked_command_id_);
149 outputs.active = axis_ref->management_command_active(tracked_command_id_);
150 }
151
152 std::uint32_t tracked_command_id_ = 0;
153
155 {
156 if(axis_ref != nullptr && tracked_command_id_ != 0) {
157 axis_ref->fail_command(tracked_command_id_, code);
158 }
159 }
160
162 {
163 terminal_low_cycle_ = !execute;
164 }
165
166private:
167 bool terminal() const
168 {
170 }
171
172 bool last_execute_ = false;
173 bool terminal_low_cycle_ = false;
174};
175
177{
178public:
180 bool execute = false;
181 bool done = false;
182 bool busy = false;
183 bool error = false;
185
186protected:
188 {
189 const bool rising = execute && !last_execute_;
190 last_execute_ = execute;
191 if(!execute || rising) {
192 done = false;
193 busy = false;
194 error = false;
196 tracked_command_id_ = 0;
197 }
198 return rising;
199 }
200
202 {
203 if(!accepted) {
204 error = true;
205 error_id = accepted.error();
206 busy = false;
207 return;
208 }
209 tracked_command_id_ = accepted.value();
210 busy = true;
211 }
212
214 {
215 if(tracked_command_id_ == 0 || axis_ref == nullptr || done || error) return;
216 const rt::ErrorCode command_error =
217 axis_ref->management_command_error(tracked_command_id_);
218 if(command_error != rt::ErrorCode::ok) {
219 error = true;
220 error_id = command_error;
221 busy = false;
222 return;
223 }
224 if(axis_ref->management_command_done(tracked_command_id_)) {
225 done = true;
226 busy = false;
227 return;
228 }
229 busy = axis_ref->management_command_pending(tracked_command_id_) ||
230 axis_ref->management_command_active(tracked_command_id_);
231 }
232
233private:
234 std::uint32_t tracked_command_id_ = 0;
235 bool last_execute_ = false;
236};
237
239{
240public:
242 bool enable = false;
243 bool enable_positive = true;
244 bool enable_negative = true;
245 bool status = false;
246 bool valid = false;
247 bool error = false;
249
250 void call()
251 {
252 if(axis_ref == nullptr) {
253 valid = false;
254 status = false;
255 error = true;
257 return;
258 }
259 const rt::ErrorCode result =
261 error = result != rt::ErrorCode::ok;
262 error_id = result;
263 valid = !error;
264 status = axis_ref->powered();
265 }
266};
267
268class FbReset : public AxisExecuteFb
269{
270public:
271 void call()
272 {
273 if(!rising_edge()) {
274 observe_axis();
275 return;
276 }
277 if(axis_ref == nullptr) {
279 return;
280 }
281 const rt::ErrorCode reset = axis_ref->reset_error();
282 if(reset != rt::ErrorCode::ok) {
284 return;
285 }
287 outputs.done = true;
288 outputs.busy = false;
289 outputs.active = false;
290 }
291};
292
294{
295public:
297 bool enable = false;
298 double vel_factor = 1.0;
299 double acc_factor = 1.0;
300 double jerk_factor = 1.0;
301 bool enabled = false;
302 bool busy = false;
303 bool error = false;
305
306 void call()
307 {
308 if(!enable) {
309 enabled = false;
310 busy = false;
311 error = false;
313 return;
314 }
315 if(axis_ref == nullptr) {
316 enabled = false;
317 busy = false;
318 error = true;
320 return;
321 }
324 enabled = !error;
325 busy = false;
326 }
327};
328
330{
331public:
332 bool continuous_update = false;
333 double position = 0.0;
334 double velocity = 1.0;
335 double acceleration = 1.0;
336 double deceleration = 1.0;
337 double jerk = 1.0;
340
351
352protected:
353 void begin_continuous_update(double input)
354 {
355 continuous_update_enabled_ = continuous_update;
356 last_input_ = input;
357 start_position_ = axis_ref == nullptr
358 ? 0.0
359 : axis_ref->snapshot().command_position;
360 }
361
362 void update_target(double input, double absolute_target)
363 {
364 if(!execute || !continuous_update_enabled_ ||
365 tracked_command_id_ == 0 || axis_ref == nullptr ||
366 input == last_input_) {
367 return;
368 }
369 last_input_ = input;
370 const rt::ErrorCode updated =
371 axis_ref->update_active_target(tracked_command_id_, absolute_target);
372 if(updated != rt::ErrorCode::ok) fail_runtime(updated);
373 }
374
375 void submit(axis::CommandKind kind, double value)
376 {
377 if(axis_ref == nullptr) {
379 return;
380 }
381 axis::AxisCommand command{};
382 command.kind = kind;
383 command.value = value;
384 command.velocity = velocity;
385 command.acceleration = acceleration;
386 command.deceleration = deceleration;
387 command.jerk = jerk;
389 command.direction = direction;
390 }
391 command.lock_stopping = kind == axis::CommandKind::stop;
392 command.buffer_mode = buffer_mode;
393 accept(axis_ref->submit(command));
394 }
395
396 double start_position_ = 0.0;
397
398private:
399 double last_input_ = 0.0;
400 bool continuous_update_enabled_ = false;
401};
402
404{
405public:
406 double distance = 0.0;
407
418};
419
421{
422public:
423 double distance = 0.0;
424
435};
436
438{
439public:
440 double direction = 1.0;
442 bool continuous_update = false;
443 bool in_velocity = false;
444
445 void call()
446 {
447 if(rising_edge()) {
448 continuous_update_enabled_ = continuous_update;
449 submit_velocity();
450 } else if(execute && continuous_update_enabled_ && tracked_command_id_ != 0 &&
451 axis_ref != nullptr &&
452 (velocity != last_velocity_ || direction != last_direction_)) {
453 const double signed_direction = resolved_direction();
454 const rt::ErrorCode updated =
455 signed_direction == 0.0
457 : axis_ref->update_active_velocity(tracked_command_id_, signed_direction,
458 std::fabs(velocity));
459 if(updated != rt::ErrorCode::ok) {
460 fail_runtime(updated);
461 } else {
462 last_velocity_ = velocity;
463 last_direction_ = direction;
464 }
465 }
466 observe_axis();
467 update_in_velocity();
468 }
469
470private:
471 double resolved_direction() const
472 {
473 if(!std::isfinite(velocity) || velocity == 0.0 ||
474 !std::isfinite(direction) || direction == 0.0) {
475 return 0.0;
476 }
477 double mode = direction;
479 mode = 1.0;
481 mode = -1.0;
483 return 0.0;
484 }
485 return (mode < 0.0 ? -1.0 : 1.0) * (velocity < 0.0 ? -1.0 : 1.0);
486 }
487
488 void submit_velocity()
489 {
492 return;
493 }
494 const double signed_direction = resolved_direction();
495 if(axis_ref == nullptr || signed_direction == 0.0) {
497 return;
498 }
499 axis::AxisCommand command{};
501 command.value = signed_direction;
502 command.velocity = std::fabs(velocity);
503 command.acceleration = acceleration;
504 command.deceleration = deceleration;
505 command.jerk = jerk;
506 command.buffer_mode = buffer_mode;
507 const rt::Result<std::uint32_t> accepted = axis_ref->submit(command);
508 if(accepted) {
509 last_velocity_ = velocity;
510 last_direction_ = direction;
511 }
512 accept(accepted);
513 }
514
515 void update_in_velocity()
516 {
517 in_velocity = false;
518 in_velocity = axis_ref != nullptr &&
519 axis_ref->command_in_velocity(tracked_command_id_);
520 }
521
522 double last_velocity_ = 0.0;
523 double last_direction_ = 0.0;
524 bool continuous_update_enabled_ = false;
525};
526
527class FbHome : public FbMoveAbsolute
528{
529public:
530 void call()
531 {
532 if(rising_edge()) {
534 }
535 observe_axis();
536 }
537};
538
539class FbHalt : public FbMoveAbsolute
540{
541public:
542 void call()
543 {
544 if(rising_edge()) {
546 }
547 observe_axis();
548 }
549};
550
551class FbStop : public FbMoveAbsolute
552{
553public:
554 void call()
555 {
556 if(!execute && last_stop_execute_ && axis_ref != nullptr && stop_command_id_ != 0) {
557 axis_ref->release_stop(stop_command_id_);
558 }
559 last_stop_execute_ = execute;
560 if(rising_edge()) {
562 stop_command_id_ = outputs.command_id;
563 }
564 observe_axis();
565 }
566
567private:
568 std::uint32_t stop_command_id_ = 0;
569 bool last_stop_execute_ = false;
570};
571
572// MC_MoveContinuous*: InEndVelocity is the persistent target state. The
573// command remains Busy/Active until takeover and never aliases that state to
574// the mutually exclusive Done output.
576{
577public:
578 double position = 0.0;
579 double velocity = 1.0;
580 double end_velocity = 0.0;
581 double acceleration = 1.0;
582 double deceleration = 1.0;
583 double jerk = 1.0;
584 bool continuous_update = false;
585 bool in_end_velocity = false;
588
600
601protected:
602 void submit_continuous(axis::CommandKind kind, double value)
603 {
604 last_target_ = value;
605 if(axis_ref == nullptr) {
607 return;
608 }
609 start_position_ = axis_ref->snapshot().command_position;
610 axis::AxisCommand command{};
611 command.kind = kind;
612 command.value = value;
613 command.velocity = velocity;
614 command.acceleration = acceleration;
615 command.deceleration = deceleration;
616 command.jerk = jerk;
617 command.end_velocity = end_velocity;
618 command.direction = direction;
619 command.buffer_mode = buffer_mode;
620 accept(axis_ref->submit(command));
621 }
622
623 void update_target(double input_value, double absolute_value)
624 {
626 axis_ref == nullptr ||
627 input_value == last_target_) {
628 return;
629 }
630 last_target_ = input_value;
631 const rt::ErrorCode updated =
632 axis_ref->update_active_target(tracked_command_id_, absolute_value);
633 if(updated != rt::ErrorCode::ok) {
634 fail_runtime(updated);
635 }
636 }
637
639 {
640 if(tracked_command_id_ == 0 || axis_ref == nullptr) {
641 return;
642 }
643 const axis::AxisSnapshot &snapshot = axis_ref->snapshot();
644 const rt::ErrorCode command_error = axis_ref->command_error(tracked_command_id_);
645 if(command_error != rt::ErrorCode::ok) {
646 outputs.error = true;
647 outputs.error_id = command_error;
648 outputs.command_aborted = false;
649 outputs.done = false;
650 outputs.busy = false;
651 outputs.active = false;
653 return;
654 }
655 if(snapshot.active_command_id != tracked_command_id_) {
656 outputs.command_aborted = true;
657 outputs.done = false;
658 outputs.busy = false;
659 outputs.active = false;
661 return;
662 }
663 outputs.busy = true;
664 outputs.active = true;
665 outputs.done = false;
666 }
667
669 {
670 in_end_velocity = false;
671 in_end_velocity = axis_ref != nullptr &&
672 axis_ref->command_in_end_velocity(tracked_command_id_);
673 }
674
675 double start_position_ = 0.0;
676 double last_target_ = 0.0;
678};
679
681{
682public:
683 double distance = 0.0;
684
685 void call()
686 {
687 if(rising_edge(true)) {
690 } else {
691 // ContinuousUpdate distances re-resolve from the original command start.
693 }
696 }
697};
698
699// MC_MoveSuperimposed: independent offset profile on top of the base motion.
701{
702public:
704 double distance = 0.0;
705 double velocity = 1.0;
706 double acceleration = 1.0;
707 double deceleration = 1.0;
708 double jerk = 1.0;
709 bool continuous_update = false;
710 bool execute = false;
711 double covered_distance = 0.0;
713
714 void call()
715 {
716 const bool rising = execute && !last_execute_;
717 const bool falling = !execute && last_execute_;
718 last_execute_ = execute;
719 if(rising) {
720 clear(outputs);
721 tracked_command_id_ = 0;
722 terminal_low_cycle_ = false;
723 continuous_update_enabled_ = continuous_update;
724 last_distance_ = distance;
725 covered_distance = 0.0;
726 } else if(!execute && terminal_low_cycle_) {
727 clear(outputs);
728 tracked_command_id_ = 0;
729 terminal_low_cycle_ = false;
730 return;
731 } else if(falling &&
732 (outputs.done || outputs.command_aborted || outputs.error)) {
733 clear(outputs);
734 tracked_command_id_ = 0;
735 }
736 if(rising) {
737 submit();
738 return;
739 }
740 if(execute && continuous_update_enabled_ && tracked_command_id_ != 0 &&
741 axis_ref != nullptr && distance != last_distance_) {
742 last_distance_ = distance;
743 const rt::ErrorCode updated = axis_ref->update_superimposed_target(
744 tracked_command_id_, distance, velocity, acceleration,
746 if(updated != rt::ErrorCode::ok) {
747 axis_ref->abort_superimposed();
748 outputs.error = true;
749 outputs.error_id = updated;
750 outputs.busy = false;
751 outputs.active = false;
752 return;
753 }
754 }
755 observe();
756 if(axis_ref != nullptr && tracked_command_id_ != 0) {
757 covered_distance = axis_ref->superimposed_distance();
758 }
759 }
760
761private:
762 void submit()
763 {
764 clear(outputs);
765 if(axis_ref == nullptr) {
766 outputs.error = true;
768 tracked_command_id_ = 0;
769 return;
770 }
771 const rt::Result<std::uint32_t> accepted =
773 if(!accepted) {
774 outputs.error = true;
775 outputs.error_id = accepted.error();
776 tracked_command_id_ = 0;
777 return;
778 }
779 tracked_command_id_ = accepted.value();
780 outputs.command_id = tracked_command_id_;
782 outputs.busy = true;
783 outputs.active = true;
784 }
785
786 void observe()
787 {
788 if(tracked_command_id_ == 0 || axis_ref == nullptr || outputs.done) {
789 return;
790 }
791 if(axis_ref->superimposed_command_id() == tracked_command_id_) {
792 outputs.busy = true;
793 outputs.active = true;
794 return;
795 }
796 if(axis_ref->superimposed_completed_id() == tracked_command_id_) {
797 outputs.done = true;
798 outputs.busy = false;
799 outputs.active = false;
800 terminal_low_cycle_ = !execute;
801 return;
802 }
803 outputs.command_aborted = true;
804 outputs.busy = false;
805 outputs.active = false;
806 terminal_low_cycle_ = !execute;
807 }
808
809 std::uint32_t tracked_command_id_ = 0;
810 bool last_execute_ = false;
811 bool terminal_low_cycle_ = false;
812 bool continuous_update_enabled_ = false;
813 double last_distance_ = 0.0;
814};
815
816// MC_HaltSuperimposed: stops only the superimposed offset with the requested
817// dynamics; the accumulated contribution persists while base motion continues.
819{
820public:
822 double deceleration = 1.0;
823 double jerk = 1.0;
824 bool execute = false;
826
827 void call()
828 {
829 const bool rising = execute && !last_execute_;
830 last_execute_ = execute;
831 if(!execute) {
832 clear(outputs);
833 tracked_command_id_ = 0;
834 return;
835 }
836 if(!rising) {
837 observe();
838 return;
839 }
840 clear(outputs);
841 if(axis_ref == nullptr) {
842 outputs.error = true;
844 return;
845 }
846 tracked_command_id_ = axis_ref->superimposed_command_id();
847 const rt::ErrorCode halted =
848 axis_ref->halt_superimposed(deceleration, jerk);
849 if(halted != rt::ErrorCode::ok) {
850 outputs.error = true;
851 outputs.error_id = halted;
852 tracked_command_id_ = 0;
853 return;
854 }
855 observe();
856 }
857
858private:
859 void observe()
860 {
861 if(axis_ref == nullptr || tracked_command_id_ == 0 ||
862 axis_ref->superimposed_command_id() != tracked_command_id_) {
863 outputs.done = true;
864 outputs.busy = false;
865 outputs.active = false;
866 tracked_command_id_ = 0;
867 return;
868 }
869 outputs.done = false;
870 outputs.busy = true;
871 outputs.active = true;
872 }
873
874 bool last_execute_ = false;
875 std::uint32_t tracked_command_id_ = 0;
876};
877
879{
880public:
881 bool continuous_update = false;
882 double torque = 0.0;
883 double torque_ramp = 0.0;
884 double velocity = 0.0;
885 double acceleration = 0.0;
886 double deceleration = 0.0;
887 double jerk = 0.0;
890 bool in_torque = false;
891
892 bool set_cycle_time(std::int64_t task_period_ns)
893 {
894 if(task_period_ns <= 0) return false;
895 task_period_ns_ = task_period_ns;
896 return true;
897 }
898
899 void call()
900 {
901 if(rising_edge()) {
902 continuous_update_enabled_ = continuous_update;
903 axis::AxisCommand command{};
904 const rt::ErrorCode built = build_command(command);
905 if(axis_ref == nullptr || built != rt::ErrorCode::ok) {
908 : built));
909 } else {
910 const rt::Result<std::uint32_t> accepted =
911 axis_ref->submit(command);
912 if(accepted) remember(command);
913 accept(accepted);
914 }
915 } else if(execute && continuous_update_enabled_ &&
916 tracked_command_id_ != 0 && axis_ref != nullptr &&
917 inputs_changed()) {
918 axis::AxisCommand command{};
919 const rt::ErrorCode built = build_command(command);
920 const rt::ErrorCode updated =
921 built == rt::ErrorCode::ok
922 ? axis_ref->update_active_torque(tracked_command_id_, command)
923 : built;
924 if(updated != rt::ErrorCode::ok) {
925 fail_runtime(updated);
926 } else {
927 remember(command);
928 }
929 }
930 observe_axis();
931 in_torque = axis_ref != nullptr && tracked_command_id_ != 0 &&
932 axis_ref->torque_command_id() == tracked_command_id_ &&
933 std::fabs(axis_ref->command_torque() - commanded_torque_) <= 1e-12;
934 if(in_torque) {
935 outputs.done = false;
936 outputs.busy = true;
937 outputs.active = true;
938 }
939 }
940
941private:
942 rt::ErrorCode build_command(axis::AxisCommand &command) const
943 {
944 if(!std::isfinite(torque) ||
945 !std::isfinite(torque_ramp) || torque_ramp < 0.0 ||
946 !std::isfinite(velocity) || velocity < 0.0 ||
947 !std::isfinite(acceleration) || acceleration < 0.0 ||
948 !std::isfinite(deceleration) || deceleration < 0.0 ||
949 !std::isfinite(jerk) || jerk < 0.0) {
951 }
954 }
957 }
958 double target = torque;
960 target = std::fabs(torque);
962 target = -std::fabs(torque);
963 }
964 const double ramp =
965 torque_ramp * static_cast<double>(task_period_ns_) / 1.0e9;
966 if(!std::isfinite(ramp) || (torque_ramp > 0.0 && ramp <= 0.0)) {
968 }
970 command.value = target;
971 command.torque_ramp = ramp;
972 command.velocity = velocity;
973 command.acceleration = acceleration;
974 command.deceleration = deceleration;
975 command.jerk = jerk;
976 command.direction = direction;
977 command.buffer_mode = buffer_mode;
978 return rt::ErrorCode::ok;
979 }
980
981 bool inputs_changed() const
982 {
983 return torque != last_torque_input_ ||
984 torque_ramp != last_torque_ramp_ ||
985 velocity != last_velocity_ ||
986 acceleration != last_acceleration_ ||
987 deceleration != last_deceleration_ || jerk != last_jerk_ ||
988 direction != last_direction_ || buffer_mode != last_buffer_mode_;
989 }
990
991 void remember(const axis::AxisCommand &command)
992 {
993 commanded_torque_ = command.value;
994 last_torque_input_ = torque;
995 last_torque_ramp_ = torque_ramp;
996 last_velocity_ = velocity;
997 last_acceleration_ = acceleration;
998 last_deceleration_ = deceleration;
999 last_jerk_ = jerk;
1000 last_direction_ = direction;
1001 last_buffer_mode_ = buffer_mode;
1002 }
1003
1004 double commanded_torque_ = 0.0;
1005 double last_torque_input_ = 0.0;
1006 double last_torque_ramp_ = 0.0;
1007 double last_velocity_ = 0.0;
1008 double last_acceleration_ = 0.0;
1009 double last_deceleration_ = 0.0;
1010 double last_jerk_ = 0.0;
1011 axis::Direction last_direction_ = axis::Direction::current;
1012 axis::BufferMode last_buffer_mode_ = axis::BufferMode::aborting;
1013 bool continuous_update_enabled_ = false;
1014 std::int64_t task_period_ns_ = 1000000;
1015};
1016
1018{
1019public:
1021 bool execute = false;
1023
1024protected:
1026 {
1027 const bool rising = execute && !last_execute_;
1028 last_execute_ = execute;
1029 if(!execute) {
1030 clear(outputs);
1032 }
1033 return rising;
1034 }
1035
1037 {
1038 outputs.command_accepted = false;
1039 outputs.error = false;
1040 outputs.error_id = rt::ErrorCode::ok;
1041 if(!accepted) {
1042 outputs.error = true;
1043 outputs.error_id = accepted.error();
1045 return;
1046 }
1047 tracked_command_id_ = accepted.value();
1048 outputs.command_id = tracked_command_id_;
1049 outputs.command_accepted = true;
1050 outputs.busy = true;
1051 outputs.active = true;
1052 outputs.done = false;
1053 }
1054
1056 {
1057 if(!execute || tracked_command_id_ == 0 || group_ref == nullptr) {
1058 return;
1059 }
1060 const axis::GroupStatus gs = group_ref->status();
1062 outputs.busy = true;
1063 outputs.active = true;
1064 outputs.done = false;
1065 return;
1066 }
1068 outputs.command_aborted = true;
1069 outputs.busy = false;
1070 outputs.active = false;
1071 outputs.done = false;
1072 return;
1073 }
1075 outputs.busy = false;
1076 outputs.active = false;
1077 }
1078
1079 std::uint32_t tracked_command_id_ = 0;
1080
1081private:
1082 bool last_execute_ = false;
1083};
1084
1086{
1087public:
1088 void call()
1089 {
1090 if(!rising_edge()) {
1091 return;
1092 }
1093 if(group_ref == nullptr) {
1095 return;
1096 }
1097 const rt::ErrorCode enabled = group_ref->enable();
1098 if(enabled != rt::ErrorCode::ok) {
1100 return;
1101 }
1103 outputs.done = true;
1104 outputs.busy = false;
1105 outputs.active = false;
1106 }
1107};
1108
1110{
1111public:
1112 void call()
1113 {
1114 if(!rising_edge()) {
1115 return;
1116 }
1117 if(group_ref == nullptr) {
1119 return;
1120 }
1121 group_ref->disable();
1123 outputs.done = true;
1124 outputs.busy = false;
1125 outputs.active = false;
1126 }
1127};
1128
1130{
1131public:
1132 double deceleration = 1.0;
1133 double jerk = 1.0;
1134
1135 void call()
1136 {
1137 if(rising_edge()) {
1138 if(group_ref == nullptr) {
1140 } else {
1141 const rt::ErrorCode stopped = group_ref->stop(deceleration, jerk);
1142 accept(stopped == rt::ErrorCode::ok
1145 }
1146 }
1147 observe_group();
1148 }
1149};
1150
1152{
1153public:
1155 double velocity = 1.0;
1156 double acceleration = 1.0;
1157 double deceleration = 1.0;
1158 double jerk = 1.0;
1160 // Approved coordinate matrix (B1 v1): ACS/MCS/PCS; WCS/FCS/TCS report
1161 // explicit unsupported.
1163 // A4 geometric blending inputs (approved blending matrix): TransitionMode
1164 // MaxCornerDeviation with a positive tolerance and a blending buffer mode
1165 // requests a quintic corner blend; unlisted combinations are explicit
1166 // errors.
1171
1172 void call()
1173 {
1174 if(rising_edge()) {
1175 submit(false);
1176 }
1177 observe_group();
1178 }
1179
1180protected:
1181 void submit(bool relative)
1182 {
1183 if(group_ref == nullptr) {
1185 return;
1186 }
1187 axis::GroupCommand command{};
1188 command.target = position;
1189 command.relative = relative;
1190 command.velocity = velocity;
1191 command.acceleration = acceleration;
1192 command.deceleration = deceleration;
1193 command.jerk = jerk;
1194 command.buffer_mode = buffer_mode;
1195 command.transition_mode = transition_mode;
1196 command.transition_velocity = transition_velocity;
1197 command.transition_parameter = transition_parameter;
1198 command.orientation_mode = orientation_mode;
1199 command.coord_system = coord_system;
1200 accept(group_ref->submit_linear(command));
1201 }
1202};
1203
1205{
1206public:
1207 void call()
1208 {
1209 if(rising_edge()) {
1210 submit(true);
1211 }
1212 observe_group();
1213 }
1214};
1215
1216// MC_MoveCircularAbsolute (approved circular matrix, A3 v1): three-point
1217// BORDER arcs in ACS, 2-8 axes, Aborting/Buffered. CENTER/RADIUS modes and
1218// blending buffer modes report explicit errors instead of approximations.
1220{
1221public:
1226 double velocity = 1.0;
1227 double acceleration = 1.0;
1228 double deceleration = 1.0;
1229 double jerk = 1.0;
1231 // Approved coordinate matrix (B1 v1): ACS/MCS/PCS; WCS/FCS/TCS report
1232 // explicit unsupported.
1234 double tolerance = 0.0;
1239
1240 void call()
1241 {
1242 if(rising_edge()) {
1243 submit(false);
1244 }
1245 observe_group();
1246 }
1247
1248protected:
1249 void submit(bool relative)
1250 {
1251 if(group_ref == nullptr) {
1253 return;
1254 }
1255 axis::GroupCommand command{};
1256 command.path_kind = axis::GroupPathKind::circular;
1257 command.circ_mode = circ_mode;
1258 command.aux = aux_point;
1259 command.target = end_point;
1260 command.path_choice = path_choice;
1261 command.relative = relative;
1262 command.velocity = velocity;
1263 command.acceleration = acceleration;
1264 command.deceleration = deceleration;
1265 command.jerk = jerk;
1266 command.buffer_mode = buffer_mode;
1267 command.coord_system = coord_system;
1268 command.tolerance = tolerance;
1269 command.transition_mode = transition_mode;
1270 command.transition_velocity = transition_velocity;
1271 command.transition_parameter = transition_parameter;
1272 command.orientation_mode = orientation_mode;
1273 accept(group_ref->submit_circular(command));
1274 }
1275};
1276
1278{
1279public:
1280 void call()
1281 {
1282 if(rising_edge()) {
1283 submit(true);
1284 }
1285 observe_group();
1286 }
1287};
1288
1289} // namespace plcopen::core::fb
rt::Result< std::uint32_t > submit_superimposed(double distance, double velocity, double acceleration, double deceleration, double jerk)
std::uint32_t superimposed_command_id() const
bool rising_edge(bool retain_active_on_falling=false)
void accept(rt::Result< std::uint32_t > accepted)
void fail_runtime(rt::ErrorCode code)
void accept_management(rt::Result< std::uint32_t > accepted)
void submit(axis::CommandKind kind, double value)
void update_target(double input, double absolute_target)
void begin_continuous_update(double input)
void submit_continuous(axis::CommandKind kind, double value)
void update_target(double input_value, double absolute_value)
axis::AxisModel * axis_ref
bool set_cycle_time(std::int64_t task_period_ns)
void accept(rt::Result< std::uint32_t > accepted)
static constexpr Result success(const T &value)
定义 error.h:24
static constexpr Result failure(ErrorCode error)
定义 error.h:29
void clear(MotionOutputs &outputs)