plcopen 0.22.0
载入中...
搜索中...
未找到
group.h
浏览该文件的文档.
1#pragma once
2
3#include <array>
4#include <cmath>
5#include <cstdint>
6
11#include "axis/group_window.h"
12#include "axis/state.h"
13#include "geom/frame.h"
14#include "geom/geometry.h"
15#include "kin/kinematics.h"
16#include "kin/pose.h"
17#include "otg/profile1d.h"
18#include "plan/path.h"
19#include "otg/time_optimal.h"
20#include "rt/cycle.h"
21#include "rt/error.h"
22#include "rt/static_vector.h"
23
24namespace plcopen::core::axis
25{
26
28{
29 static constexpr std::size_t MaxAxes = 8;
30 std::array<double, MaxAxes> value{};
31 std::size_t size = 0;
32};
33
35{
36 std::size_t index = 0;
37};
38
40{
41 double theta = 0.0;
42 double d = 0.0;
43 double a = 0.0;
44 double alpha = 0.0;
45};
46
48{
49 double zero_position = 0.0;
50 bool direction_clockwise = false;
51};
52
53template <typename T> struct GroupArray
54{
55 std::array<T, GroupPosition::MaxAxes> value{};
56 std::size_t count = 0;
57};
58
62
64{
65 bool serial = false;
66 std::size_t count = 0;
67 std::array<DHParameter, GroupPosition::MaxAxes> dh{};
68 std::array<JointInfo, GroupPosition::MaxAxes> joint{};
69};
70
77
83
89
95
97{
98 double velocity = 1.0;
99 double acceleration = 1.0;
100 double deceleration = 1.0;
101 double jerk = 1.0;
102};
103
105{
107 std::size_t size = 0;
108 std::array<double, GroupPosition::MaxAxes> axis_velocity{};
109 std::array<double, GroupPosition::MaxAxes> axis_acceleration{};
110 std::array<double, GroupPosition::MaxAxes> axis_deceleration{};
111 std::array<double, GroupPosition::MaxAxes> axis_jerk{};
112};
113
115{
116 double velocity_override = 1.0;
120};
121
123{
124 std::array<double, 6> value{};
125};
126
133
140
142{
144 double mass = 0.0;
145 double ix = 0.0;
146 double iy = 0.0;
147 double iz = 0.0;
148};
149
151{
153 double mass = 0.0;
154 double ix = 0.0;
155 double iy = 0.0;
156 double iz = 0.0;
157};
158
160{
161 std::array<RigidBodyDynamic, GroupPosition::MaxAxes + 1> value{};
162 std::size_t count = 0;
163};
164
170
172{
173 double minimum = 0.0;
174 double maximum = 0.0;
175 bool minimum_enabled = false;
176 bool maximum_enabled = false;
177};
178
180
182{
184 std::array<AxisSiConfig, GroupPosition::MaxAxes> value{};
185 std::size_t count = 0;
186};
187
193
203
205{
206 bool tracking = false;
207 bool in_sync = true;
208 bool in_position = true;
209 bool standstill = true;
210 bool constant_velocity = false;
211 bool accelerating = false;
212 bool decelerating = false;
213 std::uint32_t active_command_id = 0;
214};
215
217{
219 std::int64_t elapsed_cycles = 0;
220 std::int64_t remaining_cycles = 0;
221 double remaining_distance = 0.0;
222 double progress = 0.0;
223 std::uint16_t info_id = 0;
224 std::uint16_t warning_id = 0;
225};
226
227// MC_CIRC_MODE: BORDER (three-point), CENTER (center + endpoint / full circle),
228// and RADIUS (signed radius minor/major arc).
229enum class CircMode
230{
234};
235
236// Y5 circular plane convention: xy_helical (default, KB-030/KB-047 XY circle +
237// linear Z/higher axes) or spatial_3d (true 3D arbitrary-plane Cartesian arc).
243
244// KB-054 linear path-length metric policy: group_default resolves at submit to
245// the group setting (default max_axis, preserving all 18 golden replays);
246// euclidean normalizes ACS/joint linear moves by the scale-stable L2 norm.
253
254// Y5 TCP origin linear velocity (units/cycle) and rigid-body spatial angular
255// velocity (rad/cycle) expressed in the requested coordinate system axes.
256// In ACS, holds raw member rates ([0..2], [3..5]).
262
263// MC_CIRC_PATHCHOICE. In BORDER mode the three points already determine the
264// arc direction; a conflicting input is an explicit error, never a silent
265// reinterpretation (approved circular matrix).
271
278
279enum class PathMode
280{
283};
284
292
293// MC_TRANSITION_MODE (approved blending matrix): v1 implements None and
294// MaxCornerDeviation; StartVelocity/ConstantVelocity/CornerDistance are
295// explicit unsupported.
304
305// MC_COORD_SYSTEM (approved coordinate matrix, B1 v1): ACS is the raw axis
306// domain (frames never applied); MCS/PCS carry Cartesian semantics on the
307// first three coordinates with the v1 identity ACS<->MCS mapping declared;
308// WCS/FCS/TCS report explicit unsupported.
318
324
325// Readback source (approved readback matrix, decision #1/#8): the command
326// setpoint domain or the servo feedback domain, through one conversion
327// chain.
329{
332};
333
334// Cartesian-interpolation batch (approved matrix): opt-in in-segment
335// per-cycle inverse kinematics. joint keeps the declared KB-037/KB-042
336// joint-space interpolation byte-identical.
342
343// Native coordinated-motion orientation contract. joint_space preserves the
344// member-domain interpolation, shortest_path interpolates the TCP rotation on
345// the shortest geodesic, and constant holds the TCP orientation captured at
346// the deterministic segment start.
353
366
367struct GroupCommand // NOLINT(clang-analyzer-optin.performance.Padding)
368{
371 bool relative = false;
372 bool direct_semantics = false;
373 // Shared-path dynamics. Linear: the scalar path parameter is planned as
374 // one jerk-limited 1D profile referenced to the member with the longest
375 // travel (the fastest-moving member). Circular: the path parameter is the
376 // arc length in the plane of the first two axes, so velocity/limits apply
377 // to the in-plane path speed (approved circular matrix).
378 double velocity = 1.0;
379 double acceleration = 1.0;
380 double deceleration = 1.0;
381 double jerk = 1.0;
383 std::uint32_t command_id = 0;
384
385 // Approved coordinate matrix (B1 v1): target/aux are interpreted in this
386 // frame and converted to ACS at submit time; the cycle path never sees a
387 // frame.
389
390 // Cartesian-interpolation batch: joint (default, byte-identical) or
391 // cartesian (per-cycle inverse kinematics on the precomputed
392 // line/geodesic).
394
395 // A4 transition inputs (linear-to-linear geometric blending v1, KB-031).
397 // Zero selects the planner-derived junction speed. A positive value is an
398 // explicit upper bound on the transition node velocity.
402
403 // Circular-only inputs (ignored by submit_linear).
409 // Y5 free-vector oriented plane normal for spatial_3d arcs (rotated by PCS,
410 // never translated) and invariant signed radius for CircMode::radius.
412 double circ_radius = 0.0;
413 // KB-054 path-length normalization for linear segments.
415 // Independent circular geometry acceptance. Zero disables the additional
416 // higher-dimensional via-point residual check.
417 double tolerance = 0.0;
418 // Internal: the validated arc geometry, resolved by submit_circular from
419 // the command's deterministic start point. Not a user input.
423 std::size_t tool_number = 0;
424 std::size_t payload_number = 0;
426 bool dynamic_pcs = false;
429 double max_joint_step = 0.01;
431 double parameter_value = 0.0;
434};
435
441
443{
444public:
445 static constexpr std::size_t MaxAxes = GroupPosition::MaxAxes;
446 static constexpr std::size_t QueueCapacity = 8;
447 static constexpr std::size_t ToolCapacity = 16;
448 static constexpr std::size_t PayloadCapacity = 16;
449 static constexpr std::size_t RigidBodyCapacity = MaxAxes + 1;
450 static constexpr std::size_t SyncPathCapacity = 32;
451
452 explicit AxisGroup(int domain_id = 0)
453 : domain_id_(domain_id)
454 {
455 }
456
457 // Members are non-owning and must remain alive while registered. Detach
458 // them on group destruction so an outliving axis never retains owner state.
460 {
461 if(path_sync_slave_ != nullptr &&
462 path_sync_slave_->sync_kind_ == SyncKind::group_path) {
463 path_sync_slave_->clear_synchronized();
464 }
465 for(std::size_t i = 0; i < axes_.size(); ++i) {
466 if(axes_[i]->group_owner() == this) {
467 axes_[i]->set_group_owner(nullptr);
468 }
469 }
470 }
471
472 AxisGroup(const AxisGroup &) = delete;
473 AxisGroup &operator=(const AxisGroup &) = delete;
474 AxisGroup(AxisGroup &&) = delete;
476
478 {
479 return status_;
480 }
481
482 std::size_t member_count() const
483 {
484 return axes_.size();
485 }
486
488 {
489 if(status_ == GroupStatus::moving || status_ == GroupStatus::stopping ||
490 status_ == GroupStatus::interrupted) {
492 }
493 abort_motion();
494 cancel_tracking();
495 for(std::size_t i = 0; i < axes_.size(); ++i) {
496 axes_[i]->set_group_owner(nullptr);
497 }
498 axes_.clear();
499 member_idents_.clear();
500 pose_frames_.translation_path_differential_ = nullptr;
501 status_ = GroupStatus::disabled;
502 group_error_id_ = rt::ErrorCode::ok;
503 return rt::ErrorCode::ok;
504 }
505
507 {
508 if(axes_.empty()) return rt::ErrorCode::precondition_failed;
509 if(enabled) {
510 for(std::size_t i = 0; i < axes_.size(); ++i) {
511 if(axes_[i]->status() == AxisStatus::errorstop) {
512 set_group_error(rt::ErrorCode::precondition_failed);
514 }
515 }
516 }
517 for(std::size_t i = 0; i < axes_.size(); ++i) {
518 const rt::ErrorCode result = axes_[i]->set_power(enabled);
519 if(result != rt::ErrorCode::ok) {
520 set_group_error(result);
521 return result;
522 }
523 }
524 if(!enabled && status_ != GroupStatus::disabled) {
525 abort_motion();
526 set_group_error(rt::ErrorCode::precondition_failed);
527 }
528 return rt::ErrorCode::ok;
529 }
530
531 bool group_powered() const
532 {
533 if(axes_.empty()) return false;
534 for(std::size_t i = 0; i < axes_.size(); ++i) {
535 if(!axes_[i]->powered()) return false;
536 }
537 return true;
538 }
539
540 bool connector_active() const
541 {
542 return connector_.active();
543 }
544
546 {
547 return connector_.tube_radius();
548 }
549
550 // Math-Max Step 5 (Y7b2b, D04): independent Cartesian takeover connector
551 // state and verified absolute TCP deviation readback (plugin Cartesian
552 // length units; 0.0 when inactive). Never shares units with joint-space
553 // connector_tube_radius().
555 {
556 return cartesian_.takeover_active_;
557 }
558
560 {
561 return cartesian_.takeover_active_ ? cartesian_.takeover_tcp_tube_ : 0.0;
562 }
563
564 double path_odometer() const
565 {
566 return path_odometer_;
567 }
568
570 double ratio_numerator,
571 double ratio_denominator,
572 double acceleration,
573 double deceleration,
574 double jerk,
575 BufferMode buffer_mode)
576 {
577 if(status_ == GroupStatus::disabled || status_ == GroupStatus::errorstop ||
578 slave.group_owner() != nullptr || !slave.powered() ||
579 !std::isfinite(ratio_numerator) || !std::isfinite(ratio_denominator) ||
580 ratio_denominator == 0.0 || !std::isfinite(acceleration) ||
581 !std::isfinite(deceleration) || !std::isfinite(jerk) || acceleration < 0.0 ||
582 deceleration < 0.0 || jerk < 0.0) {
584 }
585 if(path_sync_slave_ != nullptr && path_sync_slave_ != &slave &&
586 path_sync_slave_->sync_kind_ == SyncKind::group_path) {
587 path_sync_slave_->clear_synchronized();
588 }
589 const rt::Result<std::uint32_t> begun =
590 slave.begin_sync(SyncKind::group_path, buffer_mode);
591 if(!begun) return begun;
592 const bool position_locked = acceleration == 0.0 && deceleration == 0.0 && jerk == 0.0;
593 slave.sync_phase_ = position_locked ? SyncPhase::engaged : SyncPhase::approaching;
594 path_sync_slave_ = &slave;
595 path_sync_id_ = begun.value();
596 path_sync_origin_ = path_odometer_;
597 path_sync_slave_origin_ = slave.snapshot().command_position;
598 path_sync_ratio_ = ratio_numerator / ratio_denominator;
599 path_sync_acceleration_ = acceleration;
600 path_sync_deceleration_ = deceleration;
601 path_sync_jerk_ = jerk;
602 path_sync_velocity_ = slave.snapshot().command_velocity;
603 path_sync_acceleration_state_ = slave.snapshot().command_acceleration;
604 path_sync_in_sync_ = position_locked;
605 return begun;
606 }
607
609 AxisModel &master,
610 const GroupPosition *waypoints,
611 std::size_t count,
612 PathMode mode,
613 const std::array<int, MaxAxes> &tuc_numerator,
614 const std::array<int, MaxAxes> &tuc_denominator,
615 CoordSystem coord_system,
616 BufferMode buffer_mode)
617 {
618 if(status_ == GroupStatus::disabled || status_ == GroupStatus::errorstop ||
619 waypoints == nullptr || count < 2 || count > SyncPathCapacity ||
620 !master.powered() || master.group_owner() == this ||
621 coord_system != CoordSystem::acs || buffer_mode != BufferMode::aborting) {
623 }
624 for(std::size_t axis_index = 0; axis_index < axes_.size(); ++axis_index) {
625 if(tuc_numerator[axis_index] == 0 || tuc_denominator[axis_index] == 0) {
627 }
628 }
629 group_sync_cumulative_[0] = 0.0;
630 for(std::size_t point = 0; point < count; ++point) {
631 if(waypoints[point].size != axes_.size() || !finite(waypoints[point])) {
633 }
634 group_sync_waypoints_[point] = waypoints[point];
635 if(point == 0) continue;
636 double squared_length = 0.0;
637 for(std::size_t axis_index = 0; axis_index < axes_.size(); ++axis_index) {
638 const double conversion = static_cast<double>(tuc_numerator[axis_index]) /
639 static_cast<double>(tuc_denominator[axis_index]);
640 const double delta = (waypoints[point].value[axis_index] -
641 waypoints[point - 1].value[axis_index]) *
642 conversion;
643 squared_length += delta * delta;
644 }
645 const double length = std::sqrt(squared_length);
646 if(length <= 0.0 || !std::isfinite(length)) {
648 }
649 group_sync_cumulative_[point] = group_sync_cumulative_[point - 1] + length;
650 }
651 abort_motion();
652 group_sync_master_ = &master;
653 group_sync_master_origin_ = master.snapshot().command_position;
654 group_sync_count_ = count;
655 group_sync_mode_ = mode;
656 group_sync_id_ = next_command_id_++;
657 group_sync_active_ = true;
658 group_sync_previous_ = group_sync_waypoints_[0];
659 status_ = GroupStatus::moving;
660 return rt::Result<std::uint32_t>::success(group_sync_id_);
661 }
662
663 bool group_to_axis_sync_active(std::uint32_t command_id) const
664 {
665 return group_sync_active_ && command_id != 0 && command_id == group_sync_id_;
666 }
667
668 bool group_to_axis_sync_aborted(std::uint32_t command_id) const
669 {
670 return command_id != 0 && command_id == last_aborted_group_sync_id_;
671 }
672
674 AxisGroup &master,
675 const ToolData &transform,
676 CoordSystem coord_system,
677 BufferMode buffer_mode)
678 {
679 if(&master == this || !valid_tracking_pose(transform)) {
681 }
682 const rt::Result<std::uint32_t> begun =
683 begin_tracking(TrackingKind::dynamic_group, coord_system, buffer_mode);
684 if(!begun) return begun;
685 tracking_master_group_ = &master;
686 tracking_transform_ = transform;
687 return begun;
688 }
689
691 const ToolData &origin,
692 const ToolData &initial_object,
693 CoordSystem coord_system,
694 BufferMode buffer_mode)
695 {
696 if(!conveyor.powered() || !valid_tracking_pose(origin) ||
697 !valid_tracking_pose(initial_object)) {
699 }
700 const rt::Result<std::uint32_t> begun =
701 begin_tracking(TrackingKind::conveyor, coord_system, buffer_mode);
702 if(!begun) return begun;
703 tracking_master_axis_ = &conveyor;
704 tracking_master_origin_ = conveyor.snapshot().actual_position;
705 tracking_origin_ = origin;
706 tracking_transform_ = initial_object;
707 return begun;
708 }
709
711 const ToolData &origin,
712 const ToolData &initial_object,
713 CoordSystem coord_system,
714 BufferMode buffer_mode)
715 {
716 if(!rotary.powered() || !valid_tracking_pose(origin) ||
717 !valid_tracking_pose(initial_object)) {
719 }
720 const rt::Result<std::uint32_t> begun =
721 begin_tracking(TrackingKind::rotary, coord_system, buffer_mode);
722 if(!begun) return begun;
723 tracking_master_axis_ = &rotary;
724 tracking_master_origin_ = rotary.snapshot().actual_position;
725 tracking_origin_ = origin;
726 tracking_transform_ = initial_object;
727 return begun;
728 }
729
730 bool tracking_command_busy(std::uint32_t command_id) const
731 {
732 return tracking_kind_ != TrackingKind::none && command_id != 0 &&
733 command_id == tracking_command_id_;
734 }
735
736 bool tracking_command_active(std::uint32_t command_id) const
737 {
738 return tracking_command_busy(command_id) && tracking_motion_seen_;
739 }
740
741 bool tracking_command_aborted(std::uint32_t command_id) const
742 {
743 return command_id != 0 && command_id == last_aborted_tracking_id_;
744 }
745
746 rt::ErrorCode tracking_command_error(std::uint32_t command_id) const
747 {
748 return tracking_command_busy(command_id) ? tracking_error_
750 }
751
752 const AxisModel *member(std::size_t index) const
753 {
754 return index < axes_.size() ? axes_[index] : nullptr;
755 }
756
757 std::size_t member_index(const AxisModel &axis) const
758 {
759 return find(axis);
760 }
761
763 {
764 if(status_ != GroupStatus::disabled || kinematics_info_frozen_ ||
765 !info.serial || info.count == 0 || info.count != axes_.size()) {
767 }
768 for(std::size_t i = 0; i < info.count; ++i) {
769 const DHParameter &dh = info.dh[i];
770 if(!std::isfinite(dh.theta) || !std::isfinite(dh.d) ||
771 !std::isfinite(dh.a) || !std::isfinite(dh.alpha) ||
772 !std::isfinite(info.joint[i].zero_position)) {
774 }
775 }
776 kinematics_info_ = info;
777 kinematics_info_bound_ = true;
778 return rt::ErrorCode::ok;
779 }
780
782 {
783 if(!kinematics_info_bound_ || !kinematics_info_.serial ||
784 kinematics_info_.count != axes_.size()) {
787 }
788 return rt::Result<GroupKinematicsInfo>::success(kinematics_info_);
789 }
790
792 {
793 if(parameter == GroupParameter::dynamics_mode) {
794 return rt::Result<double>::success(static_cast<double>(dynamics_mode_));
795 }
798 static_cast<double>(transition_reference_point_));
799 }
801 }
802
804 {
805 if(!std::isfinite(value)) return rt::ErrorCode::invalid_argument;
806 if(!configuration_writable()) return rt::ErrorCode::precondition_failed;
807 if(parameter == GroupParameter::dynamics_mode) {
808 if(value == static_cast<double>(DynamicsMode::absolute)) {
809 dynamics_mode_ = DynamicsMode::absolute;
810 return rt::ErrorCode::ok;
811 }
812 if(value == static_cast<double>(DynamicsMode::percentage)) {
813 dynamics_mode_ = DynamicsMode::percentage;
814 return rt::ErrorCode::ok;
815 }
817 }
819 if(value == static_cast<double>(TransitionReferencePoint::end_point)) {
820 transition_reference_point_ = TransitionReferencePoint::end_point;
821 return rt::ErrorCode::ok;
822 }
823 if(value == static_cast<double>(TransitionReferencePoint::start_point)) {
825 }
827 }
829 }
830
832 double value,
833 ExecutionMode mode)
834 {
835 if(mode == ExecutionMode::immediately) {
836 return complete_immediate(write_group_parameter(parameter, value));
837 }
838 const rt::ErrorCode valid = validate_group_parameter(parameter, value);
839 if(valid != rt::ErrorCode::ok) {
841 }
844 command.parameter = parameter;
845 command.parameter_value = value;
846 return enqueue_management(command, mode);
847 }
848
849 const PathDynamics &reference_dynamics() const { return reference_dynamics_; }
850 const PathDynamics &default_dynamics() const { return default_dynamics_; }
851 const JoggingDynamics &jogging_dynamics() const { return jogging_dynamics_; }
852
853 rt::ErrorCode write_tool_data(std::size_t number, const ToolData &data)
854 {
855 if(number == 0) return rt::ErrorCode::precondition_failed;
856 if(number >= ToolCapacity) return rt::ErrorCode::out_of_range;
857 if(!configuration_writable()) return rt::ErrorCode::precondition_failed;
858 for(double value : data.value) {
859 if(!std::isfinite(value)) return rt::ErrorCode::invalid_argument;
860 }
861 tools_[number] = data;
862 tool_defined_[number] = true;
863 return rt::ErrorCode::ok;
864 }
865
867 const ToolData &data,
868 ExecutionMode mode)
869 {
870 if(mode == ExecutionMode::immediately) {
871 return complete_immediate(write_tool_data(number, data));
872 }
873 const rt::ErrorCode valid = validate_tool_data(number, data);
874 if(valid != rt::ErrorCode::ok) {
876 }
879 command.tool_number = number;
880 command.tool_data = data;
881 return enqueue_management(command, mode);
882 }
883
884 rt::Result<ToolData> read_tool_data(std::size_t number) const
885 {
886 if(number >= ToolCapacity || !tool_defined_[number]) {
888 }
889 return rt::Result<ToolData>::success(tools_[number]);
890 }
891
892 rt::ErrorCode select_tool(std::size_t number)
893 {
894 if(status_ != GroupStatus::disabled && status_ != GroupStatus::standby &&
895 status_ != GroupStatus::moving) {
897 }
898 if(number >= ToolCapacity || !tool_defined_[number]) {
900 }
901 selected_tool_ = number;
902 numbered_tool_mode_ = true;
903 apply_selected_tool();
904 return rt::ErrorCode::ok;
905 }
906
907 std::size_t read_tool(SelectionSource source) const
908 {
909 return source == SelectionSource::active &&
910 (status_ == GroupStatus::moving || status_ == GroupStatus::stopping ||
911 status_ == GroupStatus::interrupted)
912 ? active_tool_
913 : selected_tool_;
914 }
915
916 rt::ErrorCode write_payload_data(std::size_t number, const PayloadData &data)
917 {
918 if(number == 0) return rt::ErrorCode::precondition_failed;
919 if(number >= PayloadCapacity) return rt::ErrorCode::out_of_range;
920 if(!configuration_writable()) return rt::ErrorCode::precondition_failed;
921 for(double value : data.center.value) {
922 if(!std::isfinite(value)) return rt::ErrorCode::invalid_argument;
923 }
924 if(!std::isfinite(data.mass) || !std::isfinite(data.ix) ||
925 !std::isfinite(data.iy) || !std::isfinite(data.iz) || data.mass < 0.0 ||
926 data.ix < 0.0 || data.iy < 0.0 || data.iz < 0.0) {
928 }
929 payloads_[number] = data;
930 payload_defined_[number] = true;
931 return rt::ErrorCode::ok;
932 }
933
935 {
936 if(number >= PayloadCapacity || !payload_defined_[number]) {
938 }
939 return rt::Result<PayloadData>::success(payloads_[number]);
940 }
941
943 {
944 if(data.count == 0) return rt::ErrorCode::invalid_argument;
946 if(!configuration_writable()) return rt::ErrorCode::precondition_failed;
947 for(std::size_t index = 0; index < data.count; ++index) {
948 const RigidBodyDynamic &body = data.value[index];
949 for(double value : body.center_of_gravity.value) {
950 if(!std::isfinite(value)) return rt::ErrorCode::invalid_argument;
951 }
952 if(!std::isfinite(body.mass) || !std::isfinite(body.ix) ||
953 !std::isfinite(body.iy) || !std::isfinite(body.iz) ||
954 body.mass < 0.0 || body.ix < 0.0 || body.iy < 0.0 || body.iz < 0.0) {
956 }
957 }
958 rigid_body_dynamics_ = data;
959 rigid_body_dynamics_defined_ = true;
960 return rt::ErrorCode::ok;
961 }
962
964 {
965 if(!rigid_body_dynamics_defined_) {
968 }
969 return rt::Result<RigidBodyDynamics>::success(rigid_body_dynamics_);
970 }
971
972 rt::ErrorCode select_payload(std::size_t number)
973 {
974 if(status_ != GroupStatus::disabled && status_ != GroupStatus::standby &&
975 status_ != GroupStatus::moving) {
977 }
978 if(number >= PayloadCapacity || !payload_defined_[number]) {
980 }
981 selected_payload_ = number;
982 return rt::ErrorCode::ok;
983 }
984
985 std::size_t read_payload(SelectionSource source) const
986 {
987 return source == SelectionSource::active &&
988 (status_ == GroupStatus::moving || status_ == GroupStatus::stopping ||
989 status_ == GroupStatus::interrupted)
990 ? active_payload_
991 : selected_payload_;
992 }
993
995 const GroupPosition &direction,
996 const JogCommandOptions &options = {})
997 {
998 const rt::ErrorCode valid = validate_jog(coord_system, direction, options);
999 if(valid != rt::ErrorCode::ok) {
1001 }
1002 if(status_ != GroupStatus::standby && status_ != GroupStatus::moving &&
1003 status_ != GroupStatus::stopping) {
1005 }
1006 if(jog_active_) {
1007 last_aborted_jog_id_ = jog_command_id_;
1008 }
1009 abort_motion();
1010 jog_command_id_ = next_command_id_++;
1011 jog_coord_system_ = coord_system;
1012 jog_direction_ = direction;
1013 jog_options_ = options;
1014 jog_releasing_ = false;
1015 jog_error_ = rt::ErrorCode::ok;
1016 jog_stop_deceleration_ = 0.0;
1017 jog_stop_jerk_ = 0.0;
1018 jog_active_ = true;
1019 snapshot_selections();
1020 snapshot_active_tool_transform();
1021 for(std::size_t i = 0; i < axes_.size(); ++i) {
1022 jog_position_[i] = axes_[i]->snapshot().command_position;
1023 jog_velocity_[i] = axes_[i]->snapshot().command_velocity;
1024 jog_acceleration_[i] = axes_[i]->snapshot().command_acceleration;
1025 }
1026 if(coord_system != CoordSystem::acs) {
1027 GroupPosition current{};
1028 const rt::ErrorCode read =
1030 if(read != rt::ErrorCode::ok) {
1031 jog_active_ = false;
1033 }
1034 jog_cartesian_position_ = current;
1035 for(std::size_t i = 0; i < 6; ++i) {
1036 jog_cartesian_start_[i] = current.value[i];
1037 }
1038 pose_frames_.jog_tool_offset_ = pose_frames_.tool_offset_;
1039 pose_frames_.jog_pose_tool_inverse_ = pose_frames_.pose_tool_inverse_;
1040 jog_cart_velocity_.fill(0.0);
1041 jog_cart_acceleration_.fill(0.0);
1042 }
1043 status_ = any_direction(direction) ? GroupStatus::moving
1045 return rt::Result<std::uint32_t>::success(jog_command_id_);
1046 }
1047
1048 rt::ErrorCode update_jog(std::uint32_t command_id, const GroupPosition &direction,
1049 const JogCommandOptions &options = {})
1050 {
1051 if(!jog_active_ || command_id == 0 || command_id != jog_command_id_) {
1053 }
1054 if(jog_error_ != rt::ErrorCode::ok) return jog_error_;
1055 const rt::ErrorCode valid = validate_jog(jog_coord_system_, direction, options);
1056 if(valid != rt::ErrorCode::ok) return valid;
1057 jog_direction_ = direction;
1058 jog_options_ = options;
1059 jog_releasing_ = false;
1060 if(any_direction(direction)) status_ = GroupStatus::moving;
1061 return rt::ErrorCode::ok;
1062 }
1063
1064 rt::ErrorCode release_jog(std::uint32_t command_id)
1065 {
1066 if(!jog_active_ || command_id == 0 || command_id != jog_command_id_) {
1068 }
1069 jog_direction_ = {};
1070 jog_direction_.size = jog_coord_system_ == CoordSystem::acs ? axes_.size() : 6;
1071 jog_releasing_ = true;
1072 status_ = GroupStatus::stopping;
1073 return rt::ErrorCode::ok;
1074 }
1075
1076 bool jog_command_active(std::uint32_t command_id) const
1077 {
1078 return jog_active_ && command_id != 0 && command_id == jog_command_id_;
1079 }
1080
1081 bool jog_command_aborted(std::uint32_t command_id) const
1082 {
1083 return command_id != 0 && command_id == last_aborted_jog_id_;
1084 }
1085
1086 rt::ErrorCode jog_error() const { return jog_error_; }
1087
1089 {
1090 return update_path_dynamics(reference_dynamics_, update);
1091 }
1092
1094 {
1095 return update_path_dynamics(default_dynamics_, update);
1096 }
1097
1099 {
1100 if(update.size != axes_.size()) return rt::ErrorCode::invalid_argument;
1101 if(!configuration_writable()) return rt::ErrorCode::precondition_failed;
1102 JoggingDynamics next = jogging_dynamics_;
1103 const rt::ErrorCode path = apply_path_update(next.path, update.path);
1104 if(path != rt::ErrorCode::ok) return path;
1105 next.size = update.size;
1106 for(std::size_t i = 0; i < update.size; ++i) {
1107 const double values[4] = {update.axis_velocity[i],
1108 update.axis_acceleration[i],
1109 update.axis_deceleration[i],
1110 update.axis_jerk[i]};
1111 for(double value : values) {
1112 if(!std::isfinite(value)) return rt::ErrorCode::invalid_argument;
1113 }
1114 if(update.axis_velocity[i] > 0.0) next.axis_velocity[i] = update.axis_velocity[i];
1115 if(update.axis_acceleration[i] > 0.0)
1116 next.axis_acceleration[i] = update.axis_acceleration[i];
1117 if(update.axis_deceleration[i] > 0.0)
1118 next.axis_deceleration[i] = update.axis_deceleration[i];
1119 if(update.axis_jerk[i] > 0.0) next.axis_jerk[i] = update.axis_jerk[i];
1120 }
1121 jogging_dynamics_ = next;
1122 return rt::ErrorCode::ok;
1123 }
1124
1126 {
1127 GroupSWLimits result{};
1128 result.count = axes_.size();
1129 for(std::size_t i = 0; i < axes_.size(); ++i) {
1130 const MotionLimits &limits = axes_[i]->limits_;
1131 result.value[i] = {limits.min_position, limits.max_position,
1132 limits.min_position_enabled,
1133 limits.max_position_enabled};
1134 }
1136 }
1137
1139 {
1140 if(cycle.period_ns() <= 0) {
1142 }
1143 GroupSiConfig result{};
1144 result.cycle = cycle;
1145 result.count = axes_.size();
1146 for(std::size_t i = 0; i < axes_.size(); ++i) {
1147 const rt::Result<AxisSiConfig> axis_config = axes_[i]->si_config(cycle);
1148 if(!axis_config) {
1149 return rt::Result<GroupSiConfig>::failure(axis_config.error());
1150 }
1151 result.value[i] = axis_config.value();
1152 }
1154 }
1155
1157 {
1158 if(limits.count != axes_.size()) return rt::ErrorCode::invalid_argument;
1159 if(!configuration_writable()) return rt::ErrorCode::precondition_failed;
1160 for(std::size_t i = 0; i < limits.count; ++i) {
1161 const GroupSWLimit &entry = limits.value[i];
1162 if(!std::isfinite(entry.minimum) || !std::isfinite(entry.maximum) ||
1163 entry.minimum > entry.maximum) {
1165 }
1166 }
1167 for(std::size_t i = 0; i < limits.count; ++i) {
1168 MotionLimits next = axes_[i]->limits_;
1169 next.min_position = limits.value[i].minimum;
1170 next.max_position = limits.value[i].maximum;
1171 next.min_position_enabled = limits.value[i].minimum_enabled;
1172 next.max_position_enabled = limits.value[i].maximum_enabled;
1173 axes_[i]->limits_ = next;
1174 }
1175 return rt::ErrorCode::ok;
1176 }
1177
1179 {
1180 if(!configuration_writable()) return rt::ErrorCode::precondition_failed;
1181 std::array<MotionLimits, MaxAxes> next_limits{};
1182 const rt::ErrorCode valid = validate_group_si_config(config, next_limits);
1183 if(valid != rt::ErrorCode::ok) return valid;
1184 for(std::size_t i = 0; i < config.count; ++i) {
1185 axes_[i]->limits_ = next_limits[i];
1186 }
1187 return rt::ErrorCode::ok;
1188 }
1189
1191 ExecutionMode mode)
1192 {
1193 if(mode == ExecutionMode::immediately) {
1194 return complete_immediate(write_group_sw_limits(limits));
1195 }
1196 const rt::ErrorCode valid = validate_group_sw_limits(limits);
1197 if(valid != rt::ErrorCode::ok) {
1199 }
1202 command.sw_limits = limits;
1203 return enqueue_management(command, mode);
1204 }
1205
1206 bool contains(const AxisModel &axis) const
1207 {
1208 return find(axis) < axes_.size();
1209 }
1210
1212 {
1213 if(status_ != GroupStatus::disabled || axis.domain_id() != domain_id_) {
1215 }
1216 if(axis.group_owner() == this) {
1218 }
1219 if(axis.group_owner() != nullptr) {
1221 }
1222 if(find(ident) < member_idents_.size()) {
1224 }
1225
1226 const rt::ErrorCode pushed = axes_.push_back(&axis);
1227 if(pushed != rt::ErrorCode::ok) {
1228 return pushed;
1229 }
1230 pose_frames_.translation_path_differential_ = nullptr;
1231 const rt::ErrorCode ident_pushed = member_idents_.push_back(ident);
1232 if(ident_pushed != rt::ErrorCode::ok) {
1233 axes_.pop_back();
1234 return ident_pushed;
1235 }
1236 axis.set_group_owner(this, &status_);
1237 return rt::ErrorCode::ok;
1238 }
1239
1241 {
1242 IdentInGroup ident{};
1243 while(find(ident) < member_idents_.size()) {
1244 ++ident.index;
1245 }
1246 return add_axis(axis, ident);
1247 }
1248
1250 {
1251 if(status_ != GroupStatus::disabled) {
1253 }
1254 const std::size_t index = find(ident);
1255 if(index == member_idents_.size()) {
1256 return rt::ErrorCode::ok;
1257 }
1258 AxisModel *axis = axes_[index];
1259 for(std::size_t i = index + 1; i < axes_.size(); ++i) {
1260 axes_[i - 1] = axes_[i];
1261 member_idents_[i - 1] = member_idents_[i];
1262 }
1263 axes_.pop_back();
1264 member_idents_.pop_back();
1265 pose_frames_.translation_path_differential_ = nullptr;
1266 axis->set_group_owner(nullptr);
1267 return rt::ErrorCode::ok;
1268 }
1269
1271 {
1272 if(status_ != GroupStatus::disabled) {
1274 }
1275 const std::size_t index = find(axis);
1276 if(index == axes_.size()) {
1278 }
1279 for(std::size_t i = index + 1; i < axes_.size(); ++i) {
1280 axes_[i - 1] = axes_[i];
1281 member_idents_[i - 1] = member_idents_[i];
1282 }
1283 axes_.pop_back();
1284 member_idents_.pop_back();
1285 pose_frames_.translation_path_differential_ = nullptr;
1286 axis.set_group_owner(nullptr);
1287 return rt::ErrorCode::ok;
1288 }
1289
1291 {
1292 const std::size_t index = find(ident);
1293 return index < axes_.size() ? axes_[index] : nullptr;
1294 }
1295
1296 const AxisModel *member(IdentInGroup ident) const
1297 {
1298 const std::size_t index = find(ident);
1299 return index < axes_.size() ? axes_[index] : nullptr;
1300 }
1301
1303 {
1304 const std::size_t index = find(axis);
1305 return index < member_idents_.size() ? member_idents_[index]
1306 : IdentInGroup{static_cast<std::size_t>(-1)};
1307 }
1308
1310 {
1311 if(status_ != GroupStatus::disabled || axes_.empty()) {
1313 }
1314 for(std::size_t i = 0; i < axes_.size(); ++i) {
1315 if(!axes_[i]->powered()) {
1317 }
1318 }
1319 status_ = GroupStatus::standby;
1320 kinematics_info_frozen_ = true;
1321 return rt::ErrorCode::ok;
1322 }
1323
1325 {
1326 if(direct_path_.direct_active_) {
1327 direct_path_.last_aborted_direct_id_ = direct_path_.direct_command_id_;
1328 abort_direct_members();
1329 }
1330 abort_motion();
1331 if(path_sync_slave_ != nullptr &&
1332 path_sync_slave_->sync_kind_ == SyncKind::group_path) {
1333 path_sync_slave_->clear_synchronized();
1334 }
1335 path_sync_slave_ = nullptr;
1336 path_sync_id_ = 0;
1337 cancel_tracking();
1338 status_ = GroupStatus::disabled;
1339 for(std::size_t i = 0; i < axes_.size(); ++i) {
1340 axes_[i]->clear_synchronized();
1341 }
1342 return rt::ErrorCode::ok;
1343 }
1344
1345 // MC_GroupStop: controlled deceleration along the original path. The halt
1346 // profile re-plans the path parameter from its current sampled state to
1347 // the minimal braking point (KB-027); a live circular takeover also
1348 // re-plans its member residuals instead of dropping the tolerance tube.
1349 rt::ErrorCode stop(double deceleration = 1.0, double jerk = 1.0)
1350 {
1351 if(cartesian_.window_active_ && !cartesian_.window_stopping_) {
1352 return cart_window_stop(deceleration, jerk);
1353 }
1354 if(status_ == GroupStatus::disabled || status_ == GroupStatus::errorstop ||
1355 !std::isfinite(deceleration) || deceleration <= 0.0 || !std::isfinite(jerk) ||
1356 jerk <= 0.0) {
1358 }
1359 if(group_sync_active_) {
1360 abort_motion();
1361 status_ = GroupStatus::standby;
1362 return rt::ErrorCode::ok;
1363 }
1364 if(status_ != GroupStatus::moving) {
1365 return rt::ErrorCode::ok;
1366 }
1367 if(jog_active_) {
1368 jog_stop_deceleration_ = deceleration;
1369 jog_stop_jerk_ = jerk;
1370 last_aborted_jog_id_ = jog_command_id_;
1371 return release_jog(jog_command_id_);
1372 }
1373 if(direct_path_.direct_active_) {
1374 return stop_direct_members(deceleration, jerk);
1375 }
1376 queue_.clear();
1377 if(joint_window_.active_) {
1378 // Controlled stop along the committed window geometry (KB-032):
1379 // one halt profile over the composite arc length; not-yet-started
1380 // commands are cleared (they never execute), the geometry is kept
1381 // for braking. Mirrors the KB-027 clamp trick: the halt target may
1382 // lie past the path end, sampling clamps at the terminal point.
1383 if(joint_window_.stopping_) {
1384 return rt::ErrorCode::ok;
1385 }
1386 double s_live = 0.0;
1387 double v_live = 0.0;
1388 double a_live = 0.0;
1389 window_live_state(s_live, v_live, a_live);
1390 if(v_live <= 0.0) {
1391 window_reset();
1392 clear_axes_synchronized();
1393 status_ = GroupStatus::standby;
1394 return rt::ErrorCode::ok;
1395 }
1396 const WindowSegment &seg = joint_window_.segments_[joint_window_.index_];
1397 const otg::Limits1D halt_limits{seg.limits.max_velocity,
1398 seg.limits.max_acceleration, deceleration, jerk};
1399 double brake_velocity = v_live;
1400 double brake_shift = 0.0;
1401 if(a_live != 0.0) {
1402 const double zero_cycles = std::ceil(std::fabs(a_live) / jerk);
1403 brake_velocity += 0.5 * a_live * zero_cycles;
1404 brake_shift += v_live * zero_cycles + a_live * zero_cycles * zero_cycles / 3.0;
1405 }
1406 if(brake_velocity < 0.0) {
1407 brake_velocity = 0.0;
1408 }
1409 const double stop_position =
1410 brake_shift +
1411 otg::detail::ramp_between(brake_velocity, 0.0, halt_limits).distance;
1413 {0.0, v_live, a_live}, {stop_position, 0.0, 0.0}, halt_limits);
1414 if(!halt) {
1415 window_reset();
1416 clear_axes_synchronized();
1417 status_ = GroupStatus::standby;
1418 return rt::ErrorCode::ok;
1419 }
1420 joint_window_.stopping_ = true;
1421 joint_window_.stop_profile_ = halt.value();
1422 joint_window_.stop_origin_ = s_live;
1423 joint_window_.tick_ = 0;
1424 status_ = GroupStatus::stopping;
1425 return rt::ErrorCode::ok;
1426 }
1427 if(!active_ || active_path_length_ <= 0.0) {
1428 abort_motion();
1429 status_ = GroupStatus::standby;
1430 return rt::ErrorCode::ok;
1431 }
1432
1433 const otg::State1D state =
1434 otg::sample(active_profile_, rt::CycleTick::from_cycles(active_tick_));
1435 if(cartesian_.takeover_active_) {
1436 const rt::ErrorCode planned =
1437 plan_cartesian_connector_stop(deceleration, jerk);
1438 if(planned == rt::ErrorCode::ok) {
1439 return rt::ErrorCode::ok;
1440 }
1441 // D11: freeze at the last commanded point and report the planning
1442 // error rather than snapping active residuals back to zero.
1443 abort_motion();
1444 status_ = GroupStatus::standby;
1445 return planned;
1446 }
1447 if(connector_.vector_mode()) {
1448 const otg::Limits1D stop_limits{
1449 active_command_.velocity, active_command_.acceleration,
1450 deceleration, jerk};
1451 std::array<double, MaxAxes> output_velocity{};
1452 std::array<double, MaxAxes> output_acceleration{};
1453 current_member_output_state(output_velocity, output_acceleration);
1454 otg::Profile1D halt_profile{};
1455 std::int64_t halt_duration = 0;
1456 const rt::ErrorCode planned =
1457 active_kind_ == GroupPathKind::circular
1458 ? connector_.plan_circular_stop(
1459 stop_limits, active_path_length_, axes_.size(),
1460 active_start_, active_finish_, active_arc_,
1461 active_profile_, active_tick_, output_velocity,
1462 output_acceleration, halt_profile, halt_duration)
1463 : connector_.plan_linear_vector_stop(
1464 stop_limits, active_path_length_, axes_.size(),
1465 active_start_, active_finish_, active_profile_,
1466 active_tick_, output_velocity, output_acceleration,
1467 halt_profile, halt_duration,
1468 active_command_.linear_metric ==
1470 if(planned == rt::ErrorCode::ok) {
1471 active_profile_ = halt_profile;
1472 active_tick_ = 0;
1473 active_duration_ = halt_duration;
1474 override_paused_ = false;
1475 status_ = GroupStatus::stopping;
1476 return rt::ErrorCode::ok;
1477 }
1478 // A finite path, continuity and the requested stop envelope cannot
1479 // all be preserved when the remaining segment is too short. Freeze at
1480 // the last commanded point and report the planning error instead
1481 // of snapping the residual back to the base arc.
1482 abort_motion();
1483 status_ = GroupStatus::standby;
1484 return planned;
1485 }
1486 if(cartesian_.active_replay_only_takeover_) {
1487 abort_motion();
1488 status_ = GroupStatus::standby;
1490 }
1491 if(state.velocity <= 0.0) {
1492 abort_motion();
1493 status_ = GroupStatus::standby;
1494 return rt::ErrorCode::ok;
1495 }
1496
1497 // Minimal braking distance: fold the acceleration-zeroing ramp, then
1498 // the jerk-limited ramp to rest (same primitives as the planner). The
1499 // acceleration bound stays the original command's so the current
1500 // profile state is always inside the halt envelope.
1501 if(cartesian_.active_safe_envelope_) {
1502 const otg::Limits1D &safe = cartesian_.active_safe_limits_;
1503 const double eff_decel = std::min(deceleration, safe.max_deceleration);
1504 const double eff_jerk = std::min(jerk, safe.max_jerk);
1505 const otg::Limits1D halt_limits{safe.max_velocity, safe.max_acceleration,
1506 eff_decel, eff_jerk};
1507 double brake_velocity = state.velocity;
1508 double brake_shift = 0.0;
1509 if(state.acceleration != 0.0) {
1510 const double zero_cycles = std::ceil(std::fabs(state.acceleration) / eff_jerk);
1511 brake_velocity += 0.5 * state.acceleration * zero_cycles;
1512 brake_shift += state.velocity * zero_cycles +
1513 state.acceleration * zero_cycles * zero_cycles / 3.0;
1514 }
1515 if(brake_velocity < 0.0) {
1516 brake_velocity = 0.0;
1517 }
1518 double stop_position = state.position + brake_shift +
1519 otg::detail::ramp_between(brake_velocity, 0.0, halt_limits)
1520 .distance;
1521 if(stop_position > active_path_length_) {
1522 stop_position = active_path_length_;
1523 }
1526 state, stop_position, active_path_length_, halt_limits, &safe);
1527 if(!halt) {
1529 state, active_path_length_, active_path_length_, safe, &safe);
1530 }
1531 if(!halt) {
1532 abort_motion();
1533 status_ = GroupStatus::standby;
1535 }
1536 active_profile_ = halt.value();
1537 active_tick_ = 0;
1538 active_duration_ = active_profile_.duration_cycles();
1539 override_paused_ = false;
1540 connector_.deactivate();
1541 status_ = GroupStatus::stopping;
1542 return rt::ErrorCode::ok;
1543 }
1544 const otg::Limits1D halt_limits{active_command_.velocity,
1545 active_command_.acceleration, deceleration, jerk};
1546 double brake_velocity = state.velocity;
1547 double brake_shift = 0.0;
1548 if(state.acceleration != 0.0) {
1549 const double zero_cycles = std::ceil(std::fabs(state.acceleration) / jerk);
1550 brake_velocity += 0.5 * state.acceleration * zero_cycles;
1551 brake_shift += state.velocity * zero_cycles +
1552 state.acceleration * zero_cycles * zero_cycles / 3.0;
1553 }
1554 if(brake_velocity < 0.0) {
1555 brake_velocity = 0.0;
1556 }
1557 const double stop_position = state.position + brake_shift +
1558 otg::detail::ramp_between(brake_velocity, 0.0, halt_limits)
1559 .distance;
1560
1562 state, {stop_position, 0.0, 0.0}, halt_limits);
1563 if(!halt) {
1564 // Fall back to the immediate stop rather than continuing motion.
1565 abort_motion();
1566 status_ = GroupStatus::standby;
1567 return rt::ErrorCode::ok;
1568 }
1569 active_profile_ = halt.value();
1570 active_tick_ = 0;
1571 active_duration_ = active_profile_.duration_cycles();
1572 override_paused_ = false;
1573 connector_.deactivate();
1574 status_ = GroupStatus::stopping;
1575 return rt::ErrorCode::ok;
1576 }
1577
1578 rt::Result<std::uint32_t> halt(double deceleration = 1.0,
1579 double jerk = 1.0,
1580 BufferMode buffer_mode = BufferMode::aborting)
1581 {
1582 if(buffer_mode != BufferMode::aborting && buffer_mode != BufferMode::buffered) {
1584 }
1585 if(!std::isfinite(deceleration) || deceleration <= 0.0 ||
1586 !std::isfinite(jerk) || jerk <= 0.0 ||
1587 status_ == GroupStatus::disabled || status_ == GroupStatus::errorstop) {
1589 }
1590 if(buffer_mode == BufferMode::buffered) {
1593 command.deceleration = deceleration;
1594 command.jerk = jerk;
1595 command.buffer_mode = buffer_mode;
1596 command.command_id = next_command_id_++;
1597 const rt::ErrorCode queued = queue_.push_back(command);
1598 if(queued != rt::ErrorCode::ok) {
1600 }
1601 halt_command_id_ = command.command_id;
1602 halt_command_live_ = true;
1604 }
1605 abort_wait();
1606 abort_queued_management();
1607 if(halt_command_live_) {
1608 if(halt_command_done(halt_command_id_)) {
1609 last_completed_halt_id_ = halt_command_id_;
1610 } else {
1611 last_aborted_halt_id_ = halt_command_id_;
1612 }
1613 }
1614 const rt::ErrorCode result = stop(deceleration, jerk);
1615 if(result != rt::ErrorCode::ok) {
1617 }
1618 halt_command_id_ = next_command_id_++;
1619 halt_command_live_ = true;
1620 return rt::Result<std::uint32_t>::success(halt_command_id_);
1621 }
1622
1623 bool halt_command_done(std::uint32_t command_id) const
1624 {
1625 return command_id != 0 &&
1626 (command_id == last_completed_halt_id_ ||
1627 (halt_command_live_ && command_id == halt_command_id_ &&
1628 status_ == GroupStatus::standby));
1629 }
1630
1631 bool halt_command_active(std::uint32_t command_id) const
1632 {
1633 return halt_command_live_ && command_id == halt_command_id_ &&
1634 status_ != GroupStatus::standby && !command_queued(command_id);
1635 }
1636
1637 bool halt_command_aborted(std::uint32_t command_id) const
1638 {
1639 return command_id != 0 && command_id == last_aborted_halt_id_;
1640 }
1641
1643 {
1644 if(period_ns <= 0) return rt::ErrorCode::invalid_argument;
1645 if(!configuration_writable()) return rt::ErrorCode::precondition_failed;
1646 task_cycle_period_ns_ = period_ns;
1647 return rt::ErrorCode::ok;
1648 }
1649
1650 std::int64_t task_cycle_period_ns() const { return task_cycle_period_ns_; }
1651
1652 rt::Result<std::uint32_t> submit_wait(std::int64_t duration_ns,
1653 BufferMode buffer_mode)
1654 {
1655 if(duration_ns <= 0 || status_ == GroupStatus::disabled ||
1656 status_ == GroupStatus::errorstop) {
1658 }
1659 if(buffer_mode != BufferMode::aborting && buffer_mode != BufferMode::buffered) {
1661 }
1662 if(wait_state_ == GroupWaitState::queued || wait_state_ == GroupWaitState::stopping ||
1663 wait_state_ == GroupWaitState::active) {
1665 }
1666 if(buffer_mode == BufferMode::buffered && !queue_.empty()) {
1668 }
1669
1670 wait_command_id_ = next_command_id_++;
1671 wait_duration_cycles_ = duration_ns / task_cycle_period_ns_;
1672 if(duration_ns % task_cycle_period_ns_ != 0) ++wait_duration_cycles_;
1673 wait_elapsed_cycles_ = 0;
1674 if(buffer_mode == BufferMode::aborting) {
1675 const rt::ErrorCode stopped = stop();
1676 if(stopped != rt::ErrorCode::ok) {
1677 wait_command_id_ = 0;
1678 return rt::Result<std::uint32_t>::failure(stopped);
1679 }
1680 wait_state_ = status_ == GroupStatus::stopping ? GroupWaitState::stopping
1682 } else {
1683 wait_state_ = status_ == GroupStatus::standby ? GroupWaitState::active
1685 }
1686 return rt::Result<std::uint32_t>::success(wait_command_id_);
1687 }
1688
1689 bool wait_command_done(std::uint32_t command_id) const
1690 {
1691 return command_id != 0 && command_id == wait_command_id_ &&
1692 wait_state_ == GroupWaitState::completed;
1693 }
1694
1695 bool wait_command_active(std::uint32_t command_id) const
1696 {
1697 return command_id != 0 && command_id == wait_command_id_ &&
1698 wait_state_ == GroupWaitState::active;
1699 }
1700
1701 bool wait_command_busy(std::uint32_t command_id) const
1702 {
1703 return command_id != 0 && command_id == wait_command_id_ &&
1704 (wait_state_ == GroupWaitState::queued ||
1705 wait_state_ == GroupWaitState::stopping ||
1706 wait_state_ == GroupWaitState::active);
1707 }
1708
1709 bool wait_command_aborted(std::uint32_t command_id) const
1710 {
1711 return command_id != 0 && command_id == last_aborted_wait_id_;
1712 }
1713
1714 // MC_GroupInterrupt: controlled deceleration preserving active/queue/window
1715 // state and the pause point. Transitions moving→stopping→interrupted.
1716 rt::ErrorCode interrupt(double deceleration = 1.0, double jerk = 1.0)
1717 {
1718 if(status_ != GroupStatus::moving || !std::isfinite(deceleration) ||
1719 deceleration <= 0.0 || !std::isfinite(jerk) || jerk <= 0.0) {
1721 }
1722 if(direct_path_.direct_active_) {
1724 }
1725 if(cartesian_.window_active_ || cartesian_.window_stopping_) {
1727 }
1728 if(connector_.active() || cartesian_.takeover_active_ ||
1729 cartesian_.active_replay_only_takeover_) {
1731 }
1732 if(joint_window_.active_) {
1733 if(joint_window_.stopping_) {
1734 return rt::ErrorCode::ok;
1735 }
1736 double s_live = 0.0;
1737 double v_live = 0.0;
1738 double a_live = 0.0;
1739 window_live_state(s_live, v_live, a_live);
1740 if(v_live <= 0.0) {
1741 interrupted_window_ = true;
1742 interrupted_plain_ = false;
1743 status_ = GroupStatus::interrupted;
1744 return rt::ErrorCode::ok;
1745 }
1746 const WindowSegment &seg = joint_window_.segments_[joint_window_.index_];
1747 const otg::Limits1D halt_limits{seg.limits.max_velocity,
1748 seg.limits.max_acceleration, deceleration, jerk};
1749 double brake_velocity = v_live;
1750 double brake_shift = 0.0;
1751 if(a_live != 0.0) {
1752 const double zero_cycles = std::ceil(std::fabs(a_live) / jerk);
1753 brake_velocity += 0.5 * a_live * zero_cycles;
1754 brake_shift += v_live * zero_cycles + a_live * zero_cycles * zero_cycles / 3.0;
1755 }
1756 if(brake_velocity < 0.0) {
1757 brake_velocity = 0.0;
1758 }
1759 const double stop_position =
1760 brake_shift +
1761 otg::detail::ramp_between(brake_velocity, 0.0, halt_limits).distance;
1763 {0.0, v_live, a_live}, {stop_position, 0.0, 0.0}, halt_limits);
1764 if(!halt) {
1765 interrupted_window_ = true;
1766 interrupted_plain_ = false;
1767 status_ = GroupStatus::interrupted;
1768 return rt::ErrorCode::ok;
1769 }
1770 joint_window_.stopping_ = true;
1771 joint_window_.stop_profile_ = halt.value();
1772 joint_window_.stop_origin_ = s_live;
1773 joint_window_.tick_ = 0;
1774 interrupting_ = true;
1775 interrupted_window_ = true;
1776 interrupted_plain_ = false;
1777 status_ = GroupStatus::stopping;
1778 return rt::ErrorCode::ok;
1779 }
1780 if(!active_ || active_path_length_ <= 0.0) {
1781 override_paused_ = false;
1782 interrupted_plain_ = false;
1783 interrupted_window_ = false;
1784 status_ = GroupStatus::interrupted;
1785 return rt::ErrorCode::ok;
1786 }
1787 const otg::State1D state =
1788 otg::sample(active_profile_, rt::CycleTick::from_cycles(active_tick_));
1789 if(state.velocity <= 0.0) {
1790 override_paused_ = false;
1791 interrupted_plain_ = true;
1792 interrupted_window_ = false;
1793 interrupt_ratio_ = state.position / active_path_length_;
1794 if(interrupt_ratio_ > 1.0) { interrupt_ratio_ = 1.0; }
1795 active_ = false;
1796 status_ = GroupStatus::interrupted;
1797 return rt::ErrorCode::ok;
1798 }
1799 if(cartesian_.active_safe_envelope_) {
1800 const otg::Limits1D &safe = cartesian_.active_safe_limits_;
1801 const double eff_decel = std::min(deceleration, safe.max_deceleration);
1802 const double eff_jerk = std::min(jerk, safe.max_jerk);
1803 const otg::Limits1D halt_limits{safe.max_velocity, safe.max_acceleration,
1804 eff_decel, eff_jerk};
1805 double brake_velocity = state.velocity;
1806 double brake_shift = 0.0;
1807 if(state.acceleration != 0.0) {
1808 const double zero_cycles = std::ceil(std::fabs(state.acceleration) / eff_jerk);
1809 brake_velocity += 0.5 * state.acceleration * zero_cycles;
1810 brake_shift += state.velocity * zero_cycles +
1811 state.acceleration * zero_cycles * zero_cycles / 3.0;
1812 }
1813 if(brake_velocity < 0.0) {
1814 brake_velocity = 0.0;
1815 }
1816 double stop_position = state.position + brake_shift +
1817 otg::detail::ramp_between(brake_velocity, 0.0, halt_limits)
1818 .distance;
1819 if(stop_position > active_path_length_) {
1820 stop_position = active_path_length_;
1821 }
1824 state, stop_position, active_path_length_, halt_limits, &safe);
1825 if(!halt) {
1827 state, active_path_length_, active_path_length_, safe, &safe);
1828 }
1829 if(!halt) {
1831 }
1832 active_profile_ = halt.value();
1833 active_tick_ = 0;
1834 active_duration_ = active_profile_.duration_cycles();
1835 override_paused_ = false;
1836 connector_.deactivate();
1837 interrupting_ = true;
1838 interrupted_plain_ = true;
1839 interrupted_window_ = false;
1840 status_ = GroupStatus::stopping;
1841 return rt::ErrorCode::ok;
1842 }
1843 const otg::Limits1D halt_limits{active_command_.velocity,
1844 active_command_.acceleration, deceleration, jerk};
1845 double brake_velocity = state.velocity;
1846 double brake_shift = 0.0;
1847 if(state.acceleration != 0.0) {
1848 const double zero_cycles = std::ceil(std::fabs(state.acceleration) / jerk);
1849 brake_velocity += 0.5 * state.acceleration * zero_cycles;
1850 brake_shift += state.velocity * zero_cycles +
1851 state.acceleration * zero_cycles * zero_cycles / 3.0;
1852 }
1853 if(brake_velocity < 0.0) {
1854 brake_velocity = 0.0;
1855 }
1856 const double stop_position = state.position + brake_shift +
1857 otg::detail::ramp_between(brake_velocity, 0.0, halt_limits)
1858 .distance;
1860 state, {stop_position, 0.0, 0.0}, halt_limits);
1861 if(!halt) {
1862 override_paused_ = false;
1863 interrupted_plain_ = true;
1864 interrupted_window_ = false;
1865 interrupt_ratio_ = state.position / active_path_length_;
1866 if(interrupt_ratio_ > 1.0) { interrupt_ratio_ = 1.0; }
1867 active_ = false;
1868 status_ = GroupStatus::interrupted;
1869 return rt::ErrorCode::ok;
1870 }
1871 active_profile_ = halt.value();
1872 active_tick_ = 0;
1873 active_duration_ = active_profile_.duration_cycles();
1874 override_paused_ = false;
1875 connector_.deactivate();
1876 interrupting_ = true;
1877 interrupted_plain_ = true;
1878 interrupted_window_ = false;
1879 status_ = GroupStatus::stopping;
1880 return rt::ErrorCode::ok;
1881 }
1882
1883 // MC_GroupContinue: resume from interrupted state, replanning remaining
1884 // path geometry from rest at the pause position.
1886 {
1887 if(status_ != GroupStatus::interrupted) {
1889 }
1890 if(interrupted_plain_) {
1891 for(std::size_t i = 0; i < axes_.size(); ++i) {
1892 active_start_[i] = axes_[i]->snapshot().command_position;
1893 }
1894 const double remaining = active_path_length_ * (1.0 - interrupt_ratio_);
1895 if(remaining <= 0.0) {
1896 override_paused_ = false;
1897 interrupted_plain_ = false;
1898 interrupted_window_ = false;
1899 status_ = GroupStatus::standby;
1900 clear_axes_synchronized();
1901 start_next_queued();
1902 return rt::ErrorCode::ok;
1903 }
1904 if(active_kind_ == GroupPathKind::cartesian_linear &&
1905 cartesian_.active_safe_envelope_) {
1906 const otg::Limits1D &safe = cartesian_.active_safe_limits_;
1907 const otg::Limits1D limits{
1908 std::min(active_command_.velocity * group_override_, safe.max_velocity),
1909 std::min(active_command_.acceleration * group_acc_override_, safe.max_acceleration),
1910 std::min(active_command_.deceleration * group_acc_override_, safe.max_deceleration),
1911 std::min(active_command_.jerk * group_jerk_override_, safe.max_jerk)};
1912 const rt::Result<otg::Profile1D> profile =
1914 if(!profile) {
1915 return profile.error();
1916 }
1917 const geom::Vec3 new_start =
1918 cartesian_point_at(cartesian_.active_segment_, interrupt_ratio_);
1919 cartesian_.active_segment_.start = new_start;
1920 cartesian_.active_segment_.delta =
1921 cartesian_.active_segment_.delta * (1.0 - interrupt_ratio_);
1922 cartesian_.active_segment_.length = remaining;
1923 active_path_length_ = remaining;
1924 active_profile_ = profile.value();
1925 active_tick_ = 0;
1926 active_duration_ = active_profile_.duration_cycles();
1927 active_ = true;
1928 override_paused_ = false;
1929 interrupted_plain_ = false;
1930 interrupted_window_ = false;
1931 interrupting_ = false;
1932 status_ = GroupStatus::moving;
1933 return rt::ErrorCode::ok;
1934 }
1935 active_path_length_ = remaining;
1936 const otg::Limits1D limits{
1937 active_command_.velocity * group_override_,
1938 active_command_.acceleration * group_acc_override_,
1939 active_command_.deceleration * group_acc_override_,
1940 active_command_.jerk * group_jerk_override_};
1942 {0.0, 0.0, 0.0}, {remaining, 0.0, 0.0}, limits);
1943 if(!profile) {
1944 return profile.error();
1945 }
1946 active_profile_ = profile.value();
1947 active_tick_ = 0;
1948 active_duration_ = active_profile_.duration_cycles();
1949 active_ = true;
1950 override_paused_ = false;
1951 interrupted_plain_ = false;
1952 interrupted_window_ = false;
1953 interrupting_ = false;
1954 status_ = GroupStatus::moving;
1955 return rt::ErrorCode::ok;
1956 }
1957 if(interrupted_window_) {
1958 if(!joint_window_.active_ || joint_window_.segments_.empty()) {
1959 interrupted_window_ = false;
1960 interrupted_plain_ = false;
1961 status_ = GroupStatus::standby;
1962 clear_axes_synchronized();
1963 start_next_queued();
1964 return rt::ErrorCode::ok;
1965 }
1966 joint_window_.stopping_ = false;
1967 joint_window_.in_curve_ = false;
1968 joint_window_.tick_ = 0;
1969 for(std::size_t i = 0; i < axes_.size(); ++i) {
1970 joint_window_.segments_[joint_window_.index_].entry[i] = axes_[i]->snapshot().command_position;
1971 }
1972 for(std::size_t s = joint_window_.index_; s < joint_window_.segments_.size(); ++s) {
1973 joint_window_.segments_[s].limits.max_velocity *= group_override_;
1974 joint_window_.segments_[s].limits.max_acceleration *= group_acc_override_;
1975 joint_window_.segments_[s].limits.max_deceleration *= group_acc_override_;
1976 joint_window_.segments_[s].limits.max_jerk *= group_jerk_override_;
1977 }
1978 bool late = false;
1979 if(!window_rebuild(late)) {
1980 window_reset();
1981 clear_axes_synchronized();
1982 interrupted_window_ = false;
1983 interrupted_plain_ = false;
1984 status_ = GroupStatus::standby;
1985 start_next_queued();
1986 return rt::ErrorCode::ok;
1987 }
1988 interrupted_window_ = false;
1989 interrupted_plain_ = false;
1990 interrupting_ = false;
1991 status_ = GroupStatus::moving;
1992 return rt::ErrorCode::ok;
1993 }
1994 interrupted_plain_ = false;
1995 interrupted_window_ = false;
1996 status_ = GroupStatus::standby;
1997 clear_axes_synchronized();
1998 start_next_queued();
1999 return rt::ErrorCode::ok;
2000 }
2001
2002 // MC_GroupSetOverride: independent group velocity, acceleration and jerk
2003 // factors. A zero velocity factor performs the existing controlled freeze.
2004 rt::ErrorCode set_group_override(double factor, double acc_factor = 1.0,
2005 double jerk_factor = 1.0)
2006 {
2007 if(!std::isfinite(factor) || factor < 0.0 || factor > 1.0 ||
2008 !std::isfinite(acc_factor) || acc_factor < 0.0 ||
2009 acc_factor > 1.0 || !std::isfinite(jerk_factor) ||
2010 jerk_factor < 0.0 || jerk_factor > 1.0) {
2012 }
2013 if(status_ == GroupStatus::disabled || status_ == GroupStatus::errorstop) {
2015 }
2016 if(direct_path_.direct_active_) {
2018 }
2019 if(connector_.active() || cartesian_.takeover_active_ ||
2020 cartesian_.active_replay_only_takeover_) {
2022 }
2023 const double previous = group_override_;
2024 const double previous_acc = group_acc_override_;
2025 const double previous_jerk = group_jerk_override_;
2026 group_override_ = factor;
2027 group_acc_override_ = acc_factor;
2028 group_jerk_override_ = jerk_factor;
2029 if(previous == factor && previous_acc == acc_factor &&
2030 previous_jerk == jerk_factor) {
2031 return rt::ErrorCode::ok;
2032 }
2033 if(status_ != GroupStatus::moving) {
2034 return rt::ErrorCode::ok;
2035 }
2036 if(cartesian_.window_active_) {
2037 return rt::ErrorCode::ok;
2038 }
2039 if(joint_window_.active_ && !joint_window_.stopping_) {
2040 if(factor == 0.0) {
2041 const rt::ErrorCode paused = interrupt(active_command_.deceleration,
2042 active_command_.jerk);
2043 if(paused != rt::ErrorCode::ok) {
2044 group_override_ = previous;
2045 group_acc_override_ = previous_acc;
2046 group_jerk_override_ = previous_jerk;
2047 return paused;
2048 }
2049 joint_window_.override_paused_ = true;
2050 status_ = GroupStatus::moving;
2051 return rt::ErrorCode::ok;
2052 }
2053 if(joint_window_.override_paused_) {
2054 joint_window_.override_paused_ = false;
2055 status_ = GroupStatus::interrupted;
2056 group_override_ = 1.0;
2057 const rt::ErrorCode resumed = continue_motion();
2058 if(resumed != rt::ErrorCode::ok || status_ != GroupStatus::moving) {
2059 group_override_ = factor;
2060 group_acc_override_ = acc_factor;
2061 group_jerk_override_ = jerk_factor;
2062 return resumed;
2063 }
2064 return set_group_override(factor, acc_factor, jerk_factor);
2065 }
2066 for(std::size_t s = joint_window_.index_ + 1; s < joint_window_.segments_.size(); ++s) {
2067 if(previous > 0.0) {
2068 joint_window_.segments_[s].limits.max_velocity =
2069 joint_window_.segments_[s].limits.max_velocity * (factor / previous);
2070 } else {
2071 double v = active_command_.velocity * factor;
2072 if(joint_window_.segments_[s].kind == WindowKind::arc) {
2073 const double junction = std::fmin(
2074 joint_window_.segments_[s].limits.max_acceleration,
2075 joint_window_.segments_[s].limits.max_deceleration);
2076 const double centripetal =
2077 std::sqrt(junction * joint_window_.segments_[s].arc_geom.radius);
2078 if(centripetal < v) {
2079 v = centripetal;
2080 }
2081 }
2082 joint_window_.segments_[s].limits.max_velocity = v;
2083 }
2084 joint_window_.segments_[s].limits.max_acceleration =
2085 previous_acc > 0.0
2086 ? joint_window_.segments_[s].limits.max_acceleration *
2087 (acc_factor / previous_acc)
2088 : active_command_.acceleration * acc_factor;
2089 joint_window_.segments_[s].limits.max_deceleration =
2090 previous_acc > 0.0
2091 ? joint_window_.segments_[s].limits.max_deceleration *
2092 (acc_factor / previous_acc)
2093 : active_command_.deceleration * acc_factor;
2094 joint_window_.segments_[s].limits.max_jerk =
2095 previous_jerk > 0.0
2096 ? joint_window_.segments_[s].limits.max_jerk *
2097 (jerk_factor / previous_jerk)
2098 : active_command_.jerk * jerk_factor;
2099 }
2100 if(joint_window_.index_ + 1 < joint_window_.segments_.size()) {
2101 bool late = false;
2102 window_rebuild(late);
2103 }
2104 return rt::ErrorCode::ok;
2105 }
2106 if(!active_ || active_path_length_ <= 0.0) {
2107 return rt::ErrorCode::ok;
2108 }
2109 const otg::State1D state =
2110 otg::sample(active_profile_, rt::CycleTick::from_cycles(active_tick_));
2111 const double remaining = active_path_length_ - state.position;
2112 if(remaining <= 0.0) {
2113 return rt::ErrorCode::ok;
2114 }
2115 if(factor == 0.0) {
2116 const double deceleration =
2117 cartesian_.active_safe_envelope_
2118 ? std::min(active_command_.deceleration,
2119 cartesian_.active_safe_limits_.max_deceleration)
2120 : active_command_.deceleration;
2121 const double jerk =
2122 cartesian_.active_safe_envelope_
2123 ? std::min(active_command_.jerk,
2124 cartesian_.active_safe_limits_.max_jerk)
2125 : active_command_.jerk;
2126 const otg::Limits1D halt_limits{
2127 cartesian_.active_safe_envelope_
2128 ? cartesian_.active_safe_limits_.max_velocity
2129 : active_command_.velocity,
2130 cartesian_.active_safe_envelope_
2131 ? cartesian_.active_safe_limits_.max_acceleration
2132 : active_command_.acceleration,
2133 deceleration, jerk};
2134 double brake_velocity = state.velocity;
2135 double brake_shift = 0.0;
2136 if(state.acceleration != 0.0) {
2137 const double zero_cycles =
2138 std::ceil(std::fabs(state.acceleration) / jerk);
2139 brake_velocity += 0.5 * state.acceleration * zero_cycles;
2140 brake_shift += state.velocity * zero_cycles +
2141 state.acceleration * zero_cycles * zero_cycles / 3.0;
2142 }
2143 if(brake_velocity < 0.0) { brake_velocity = 0.0; }
2144 double stop_position = state.position + brake_shift +
2145 otg::detail::ramp_between(brake_velocity, 0.0, halt_limits).distance;
2148 if(cartesian_.active_safe_envelope_) {
2149 if(stop_position > active_path_length_) {
2150 stop_position = active_path_length_;
2151 }
2153 state, stop_position, active_path_length_, halt_limits,
2154 &cartesian_.active_safe_limits_);
2155 if(!profile) {
2157 state, active_path_length_, active_path_length_,
2158 cartesian_.active_safe_limits_, &cartesian_.active_safe_limits_);
2159 }
2160 } else {
2161 profile = otg::plan_time_optimal(
2162 state, {stop_position, 0.0, 0.0}, halt_limits);
2163 }
2164 if(!profile) {
2165 group_override_ = previous;
2166 group_acc_override_ = previous_acc;
2167 group_jerk_override_ = previous_jerk;
2168 return profile.error();
2169 }
2170 active_profile_ = profile.value();
2171 active_tick_ = 0;
2172 active_duration_ = active_profile_.duration_cycles();
2173 override_paused_ = true;
2174 return rt::ErrorCode::ok;
2175 }
2176 otg::Limits1D limits{
2177 active_command_.velocity * factor,
2178 active_command_.acceleration * acc_factor,
2179 active_command_.deceleration * acc_factor,
2180 active_command_.jerk * jerk_factor};
2183 if(cartesian_.active_safe_envelope_) {
2184 const otg::Limits1D &safe = cartesian_.active_safe_limits_;
2185 limits.max_velocity = std::min(limits.max_velocity, safe.max_velocity);
2186 limits.max_acceleration = std::min(limits.max_acceleration, safe.max_acceleration);
2187 limits.max_deceleration = std::min(limits.max_deceleration, safe.max_deceleration);
2188 limits.max_jerk = std::min(limits.max_jerk, safe.max_jerk);
2190 state, active_path_length_, active_path_length_, limits, &safe);
2191 } else {
2192 profile = otg::plan_time_optimal(
2193 state, {active_path_length_, 0.0, 0.0}, limits);
2194 }
2195 if(!profile) {
2196 group_override_ = previous;
2197 group_acc_override_ = previous_acc;
2198 group_jerk_override_ = previous_jerk;
2199 return profile.error();
2200 }
2201 active_profile_ = profile.value();
2202 active_tick_ = 0;
2203 active_duration_ = active_profile_.duration_cycles();
2204 override_paused_ = false;
2205 return rt::ErrorCode::ok;
2206 }
2207
2208 double group_override() const
2209 {
2210 return group_override_;
2211 }
2212
2213 double group_acc_override() const { return group_acc_override_; }
2214
2215 double group_jerk_override() const { return group_jerk_override_; }
2216
2217 // MoveDirect remains independent-member PTP for Aborting/Buffered. An
2218 // explicit blending transition is a coordinated line and therefore enters
2219 // the existing A4/A5 look-ahead planner instead of being silently ignored.
2221
2222 // Legacy direct entry retained for internal callers; the public FB uses
2223 // submit_group_home so Position/CoordSystem/BufferMode enter the group
2224 // command queue and have an observable lifecycle.
2226 {
2227 if(status_ != GroupStatus::standby || !queue_.empty()) {
2229 }
2230 if(!members_ready_for_group_motion()) {
2232 }
2233 for(std::size_t i = 0; i < axes_.size(); ++i) {
2234 const rt::ErrorCode homed = axes_[i]->home_direct(0.0);
2235 if(homed != rt::ErrorCode::ok) {
2236 abort_motion();
2237 set_group_error(homed);
2238 return homed;
2239 }
2240 }
2241 return rt::ErrorCode::ok;
2242 }
2243
2245 CoordSystem coordinate_system,
2246 BufferMode buffer_mode)
2247 {
2248 if(buffer_mode != BufferMode::aborting && buffer_mode != BufferMode::buffered) {
2250 }
2251 if(status_ == GroupStatus::disabled || status_ == GroupStatus::errorstop ||
2252 status_ == GroupStatus::interrupted || axes_.empty()) {
2254 }
2255 GroupPosition requested = position;
2256 if(requested.size == 0) requested.size = axes_.size();
2257 GroupPosition resolved{};
2258 bool singular = false;
2259 const rt::ErrorCode transformed = transform_position(
2260 requested, coordinate_system, CoordSystem::acs, resolved, singular);
2261 if(transformed != rt::ErrorCode::ok) {
2262 return rt::Result<std::uint32_t>::failure(transformed);
2263 }
2264 if(singular) {
2266 }
2267 const rt::ErrorCode limited = preflight_member_targets(resolved);
2268 if(limited != rt::ErrorCode::ok) {
2269 return rt::Result<std::uint32_t>::failure(limited);
2270 }
2271
2274 command.target = resolved;
2275 command.buffer_mode = buffer_mode;
2276 command.command_id = next_command_id_++;
2277 if(buffer_mode == BufferMode::aborting) {
2278 abort_wait();
2279 abort_halt();
2280 abort_motion();
2281 status_ = GroupStatus::standby;
2282 }
2283 const rt::ErrorCode queued = queue_.push_back(command);
2284 if(queued != rt::ErrorCode::ok) {
2286 }
2288 }
2289
2290 bool group_homing() const
2291 {
2292 if(active_management_kind_ == GroupCommandKind::home) return true;
2293 for(std::size_t i = 0; i < queue_.size(); ++i) {
2294 if(queue_[i].kind == GroupCommandKind::home) return true;
2295 }
2296 return false;
2297 }
2298
2299 bool management_command_done(std::uint32_t command_id) const
2300 {
2301 for(std::size_t i = 0; i < management_results_.size(); ++i) {
2302 if(management_results_[i].command_id == command_id) {
2303 return management_results_[i].error == rt::ErrorCode::ok;
2304 }
2305 }
2306 return false;
2307 }
2308
2309 rt::ErrorCode management_command_error(std::uint32_t command_id) const
2310 {
2311 for(std::size_t i = 0; i < management_results_.size(); ++i) {
2312 if(management_results_[i].command_id == command_id) {
2313 return management_results_[i].error;
2314 }
2315 }
2316 return rt::ErrorCode::ok;
2317 }
2318
2319 bool management_command_aborted(std::uint32_t command_id) const
2320 {
2321 for(std::size_t i = 0; i < aborted_management_ids_.size(); ++i) {
2322 if(aborted_management_ids_[i] == command_id) return true;
2323 }
2324 return false;
2325 }
2326
2327 bool management_command_active(std::uint32_t command_id) const
2328 {
2329 return active_management_id_ == command_id;
2330 }
2331
2332 bool direct_motion_active() const;
2333 bool direct_command_done(std::uint32_t command_id) const;
2334 bool direct_command_aborted(std::uint32_t command_id) const;
2335 bool direct_command_active(std::uint32_t command_id) const;
2336 bool direct_command_busy(std::uint32_t command_id) const;
2337 std::uint32_t last_completed_direct_command() const;
2338 std::uint32_t last_aborted_direct_command() const;
2339
2340 // Approved coordinate matrix (B1 v1): the workpiece frame (PCS over MCS)
2341 // and the tool offset are group configuration; they may only change at
2342 // standby with an empty queue — changing frames mid-motion has no
2343 // defined semantics.
2344 rt::ErrorCode set_workpiece_frame(double x, double y, double z, double rot_z);
2345
2346 // Orientation batch (approved matrix, decision #4): the full rigid
2347 // workpiece frame; the Z-only setter above stays as its special case.
2349 double y,
2350 double z,
2351 double roll,
2352 double pitch,
2353 double yaw);
2354
2355 // Orientation batch (approved matrix, decision #5): the flange-to-TCP
2356 // rigid transform for the pose pipeline (the translational pipeline
2357 // keeps its own set_tool_offset; the two never read each other).
2359 double y,
2360 double z,
2361 double roll,
2362 double pitch,
2363 double yaw);
2364
2365 // Orientation batch (approved matrix, decisions #2/#3): the 6-DOF pose
2366 // plugin, mutually exclusive with the translational plugin.
2368 double min_singularity_margin,
2369 double max_joint_step);
2370
2371 // Readback batch (approved matrix decision #7): configuration getters
2372 // echo the original set values — never a matrix-to-RPY inversion of a
2373 // configured frame.
2374 void workpiece_frame_rpy(double out[6]) const;
2375 void tool_transform_rpy(double out[6]) const;
2376 geom::Vec3 tool_offset() const;
2377
2378 // Readback batch (approved matrix decisions #1-#3): per-frame Cartesian
2379 // and pose readback, a pure const query mirroring the submit-side
2380 // conversion slot for slot — a read-back value is a resubmittable
2381 // target. Any motion state may read (readback is not configuration);
2382 // only WCS/FCS/TCS and a memberless/disabled group reject. Pose groups
2383 // report the TCP pose ([0..2] position, [3..5] RPY via extract_rpy with
2384 // the declared gimbal convention); translational groups report the TCP
2385 // point plus higher-axis ACS pass-through.
2387 PositionSource source,
2388 GroupPosition &out,
2389 bool *gimbal_lock = nullptr) const;
2390
2391 // Y5 TCP origin velocity & spatial angular velocity readback (const, RT-safe).
2392 // Preserves AxisSnapshot::command_velocity replay baselines while delivering
2393 // analytical command twist and genuine actual feedback twist.
2395 PositionSource source,
2396 CartesianTwist &out) const;
2397
2398 // Maps an explicit (joints, joint_velocities) pair to TCP twist in cs.
2400 CoordSystem cs,
2401 const GroupPosition &joints,
2402 const GroupPosition &joint_velocities,
2403 CartesianTwist &out) const;
2404
2405 // Y5 opt-in Pose Cartesian look-ahead window (default false keeps KB-049
2406 // single-chain geodesic behavior intact).
2408 {
2409 if(status_ != GroupStatus::standby || !queue_.empty()) {
2411 }
2412 pose_window_enabled_ = enabled;
2413 return rt::ErrorCode::ok;
2414 }
2415
2416 bool pose_window_enabled() const { return pose_window_enabled_; }
2417
2418 // Exact polynomial Rolle-bracketed monotonicity & position-bound verifier
2419 // over every segment of Profile1D on normalized u = x / T in [0, 1].
2420 static bool verify_profile_monotonic(const otg::Profile1D &p, double length);
2421
2422 // KB-054 group default path-length metric for linear segments (default
2423 // max_axis preserves all 18 golden replays; group_default is rejected here).
2425 {
2426 if(status_ != GroupStatus::standby || !queue_.empty() ||
2427 (metric != LinearPathMetric::max_axis &&
2428 metric != LinearPathMetric::euclidean)) {
2430 }
2431 linear_path_metric_ = metric;
2432 return rt::ErrorCode::ok;
2433 }
2434
2435 LinearPathMetric linear_path_metric() const { return linear_path_metric_; }
2436
2437 rt::ErrorCode set_tool_offset(double x, double y, double z);
2438
2439 // BS3.6 (approved kinematics matrix follow-up): conservative dual-space
2440 // velocity limiting. With a kinematics plugin the segment interpolates
2441 // in joint space, so the Cartesian speed along it varies; at submit the
2442 // joint-space chord is sampled through the forward solution and the
2443 // command velocity is scaled down so the worst sampled Cartesian speed
2444 // stays under this limit (0 disables; linear segments only in v1).
2446
2447 // Approved kinematics matrix (B2 v1): the plugin upgrades the declared
2448 // identity ACS<->MCS mapping to a real mechanism. The caller owns the
2449 // plugin lifetime; nullptr restores the identity. v1 requires the joint
2450 // count to equal both the Cartesian coordinate count (2 or 3) and the
2451 // group axis count; the 6R batch lifts this.
2453 double min_singularity_margin = 0.0);
2454
2457 double min_singularity_margin,
2458 double max_joint_step,
2459 ExecutionMode mode)
2460 {
2461 const rt::ErrorCode valid = validate_kinematics(
2462 kin_transform, min_singularity_margin, max_joint_step);
2463 if(valid != rt::ErrorCode::ok) {
2465 }
2466 if(mode == ExecutionMode::immediately) {
2467 if(status_ != GroupStatus::standby || !queue_.empty()) {
2470 }
2471 return complete_immediate(apply_kinematics(
2472 kin_transform, min_singularity_margin, max_joint_step));
2473 }
2476 command.kin_transform = kin_transform;
2477 command.min_singularity_margin = min_singularity_margin;
2478 command.max_joint_step = max_joint_step;
2479 return enqueue_management(command, mode);
2480 }
2481
2482 const kin::Kinematics *kinematics_plugin() const;
2485
2486 // Math-Max Step 5 (Y7b2b, D02/D04): optional analytical companion binding
2487 // for plain translational Cartesian LINE aborting takeover (caller owns
2488 // lifetime; auto-cleared whenever kinematics change) and absolute TCP tube
2489 // ceiling configuration.
2491 const kin::TranslationPathDifferential *differential);
2494 double cartesian_takeover_tcp_tube_limit() const;
2495
2497 const ToolData &transform,
2498 ExecutionMode execution_mode);
2500 CoordSystem coordinate_system,
2501 const ToolData &transform,
2502 ExecutionMode execution_mode)
2503 {
2504 const rt::ErrorCode valid = validate_coordinate_transform(
2505 coordinate_system, transform);
2506 if(valid != rt::ErrorCode::ok) {
2508 }
2509 if(execution_mode == ExecutionMode::immediately) {
2510 return complete_immediate(set_coordinate_transform(
2511 coordinate_system, transform, execution_mode));
2512 }
2515 command.coord_system = coordinate_system;
2516 command.tool_data = transform;
2517 return enqueue_management(command, execution_mode);
2518 }
2520 ToolData &transform) const;
2522 CoordSystem source,
2523 CoordSystem target,
2524 GroupPosition &output,
2525 bool &singular_position) const;
2526
2528 bool relative,
2529 CoordSystem coordinate_system,
2530 ExecutionMode execution_mode)
2531 {
2532 if(execution_mode != ExecutionMode::immediately ||
2533 status_ != GroupStatus::standby || !configuration_writable()) {
2535 }
2536 GroupPosition resolved{};
2537 bool singular = false;
2538 const rt::ErrorCode transformed = transform_position(
2539 position, coordinate_system, CoordSystem::acs, resolved, singular);
2540 if(transformed != rt::ErrorCode::ok) return transformed;
2541 if(singular) return rt::ErrorCode::precondition_failed;
2542 if(relative) {
2543 for(std::size_t i = 0; i < resolved.size; ++i) {
2544 resolved.value[i] += axes_[i]->snapshot().command_position;
2545 }
2546 }
2547 const rt::ErrorCode preflight = preflight_member_targets(resolved);
2548 if(preflight != rt::ErrorCode::ok) return preflight;
2549 for(std::size_t i = 0; i < resolved.size; ++i) {
2550 const rt::ErrorCode result = axes_[i]->set_position(resolved.value[i]);
2551 if(result != rt::ErrorCode::ok) return result;
2552 }
2553 return rt::ErrorCode::ok;
2554 }
2555
2556 // Look-ahead v2 addendum (approved 2026-07-06): runtime cap on the
2557 // window depth; the declared capacity_exceeded semantics fire at the
2558 // configured value. Default stays the full 64 (replay guard).
2560 {
2561 if(status_ != GroupStatus::standby || !queue_.empty() || joint_window_.active_ ||
2562 depth < 2 || depth > WindowCapacity) {
2564 }
2565 joint_window_.depth_ = depth;
2566 return rt::ErrorCode::ok;
2567 }
2568
2570 {
2571 pending_dynamic_pcs_ = false;
2572 if(command.buffer_mode != BufferMode::aborting && has_queued_management()) {
2574 }
2575 if(jog_active_ && command.buffer_mode != BufferMode::aborting) {
2577 }
2578 command.tool_number = selected_tool_;
2579 command.payload_number = selected_payload_;
2580 command.tool_inverse = pose_frames_.pose_tool_inverse_;
2581 const rt::ErrorCode dynamics = resolve_dynamics(command);
2582 if(dynamics != rt::ErrorCode::ok) {
2583 return rt::Result<std::uint32_t>::failure(dynamics);
2584 }
2585 const bool halt_takeover = halt_command_live_ &&
2586 status_ == GroupStatus::stopping &&
2587 command.buffer_mode == BufferMode::aborting;
2588 if(status_ == GroupStatus::interrupted) {
2589 if(command.buffer_mode != BufferMode::aborting) {
2591 }
2592 }
2593 // MoveDirect is driven by member base profiles. Until a coordinated
2594 // takeover can cancel every member atomically, accepting a path here
2595 // would leave AxisGroup::cycle() and AxisModel::cycle() as two writers.
2596 if(direct_path_.direct_active_ && !halt_takeover) {
2598 }
2599 if(command.linear_metric == LinearPathMetric::group_default) {
2600 command.linear_metric = linear_path_metric_;
2601 } else if(command.linear_metric != LinearPathMetric::max_axis &&
2602 command.linear_metric != LinearPathMetric::euclidean) {
2604 }
2605 const bool pose_cartesian_target =
2606 pose_frames_.pose_kinematics_ != nullptr &&
2607 (command.coord_system == CoordSystem::mcs ||
2608 command.coord_system == CoordSystem::pcs);
2609 const bool valid_target_size =
2610 command.target.size == axes_.size() ||
2611 (pose_cartesian_target && command.target.size == 6);
2612 if((status_ != GroupStatus::standby && status_ != GroupStatus::moving &&
2613 status_ != GroupStatus::interrupted && !halt_takeover) ||
2614 axes_.size() < 2 ||
2615 !valid_target_size || command.velocity <= 0.0 ||
2616 !std::isfinite(command.velocity) || command.acceleration <= 0.0 ||
2617 !std::isfinite(command.acceleration) || command.deceleration <= 0.0 ||
2618 !std::isfinite(command.deceleration) || command.jerk <= 0.0 ||
2619 !std::isfinite(command.jerk) || !finite(command.target)) {
2621 }
2622 const rt::ErrorCode orientation = select_orientation_interpolation(command);
2623 if(orientation != rt::ErrorCode::ok) {
2624 return rt::Result<std::uint32_t>::failure(orientation);
2625 }
2626 const bool blending_buffer = command.buffer_mode == BufferMode::blending_low ||
2627 command.buffer_mode == BufferMode::blending_high;
2628 if(!std::isfinite(command.transition_velocity) ||
2629 command.transition_velocity < 0.0 ||
2630 command.transition_velocity > command.velocity ||
2631 (command.transition_velocity > 0.0 && !blending_buffer)) {
2633 }
2634 if(!members_ready_for_group_motion()) {
2636 }
2637 if(tracking_kind_ != TrackingKind::none && command.coord_system == CoordSystem::pcs) {
2638 if(command.buffer_mode != BufferMode::aborting) {
2640 }
2641 command.dynamic_pcs = true;
2642 pending_dynamic_pcs_ = true;
2643 pose_frames_.pending_dynamic_reference_frame_ = pose_frames_.workpiece_frame_;
2644 }
2645 // Cartesian-interpolation batch (approved matrix): resolve the
2646 // opt-in segment before the frame collapse — pre-validation either
2647 // rejects here or leaves the ACS endpoint joints plus the cycle
2648 // geometry in command.cart.
2649 if(command.interpolation_space == InterpolationSpace::cartesian) {
2650 // Cartesian v2-C (approved addendum): a blending successor with a
2651 // corner tolerance fuses with the active Cartesian line here;
2652 // every other blending shape stays unsupported via the guards.
2653 if((command.buffer_mode == BufferMode::blending_low ||
2654 command.buffer_mode == BufferMode::blending_high) &&
2655 command.transition_mode == TransitionMode::max_corner_deviation &&
2656 std::isfinite(command.transition_parameter) &&
2657 command.transition_parameter > 0.0) {
2658 // v3/Y5 window: translational plugin groups always use the
2659 // look-ahead window; Pose groups use it when opt-in
2660 // pose_window_enabled_ is active (default false preserves KB-049).
2661 if(pose_frames_.kinematics_ != nullptr ||
2662 (pose_frames_.pose_kinematics_ != nullptr && pose_window_enabled_)) {
2663 return submit_cartesian_window(command);
2664 }
2665 return submit_cartesian_blend(command);
2666 }
2667 const rt::ErrorCode prepared = prepare_cartesian_linear(command);
2668 if(prepared != rt::ErrorCode::ok) {
2669 return rt::Result<std::uint32_t>::failure(prepared);
2670 }
2671 }
2672
2673 const rt::ErrorCode framed = apply_coordinate_frame(command);
2674 if(framed != rt::ErrorCode::ok) {
2676 }
2677
2678 // TransitionMode combination matrix (approved blending matrix):
2679 // unlisted combinations are explicit errors, never silent downgrades.
2680 if(command.transition_mode == TransitionMode::none) {
2681 if(command.transition_parameter != 0.0) {
2683 }
2684 if(blending_buffer) {
2686 }
2687 } else if(command.transition_mode == TransitionMode::max_corner_deviation) {
2688 if(!std::isfinite(command.transition_parameter) ||
2689 command.transition_parameter <= 0.0) {
2691 }
2692 if(command.buffer_mode == BufferMode::aborting) {
2693 // Aborting semantics and pre-blended queues are mutually
2694 // exclusive (approved matrix).
2696 }
2697 if(!blending_buffer) {
2699 }
2700 } else {
2702 }
2703
2704 if(command.command_id == 0) {
2705 command.command_id = next_command_id_++;
2706 }
2707
2708 // submit_linear always drives a linear path regardless of any stray
2709 // circular fields on the command struct (the cartesian marker set by
2710 // the pre-validation above is the one exception).
2711 if(command.interpolation_space != InterpolationSpace::cartesian) {
2712 command.path_kind = GroupPathKind::linear;
2713 }
2714 command.arc = geom::ArcSegment{};
2715
2716 const GroupCommand normalized = normalize(command);
2717 const rt::ErrorCode limited = preflight_member_targets(normalized.target);
2718 if(limited != rt::ErrorCode::ok) {
2719 return rt::Result<std::uint32_t>::failure(limited);
2720 }
2721
2722 if(command.buffer_mode == BufferMode::aborting) {
2723 // Y7/Y7b1/Y7b2a/Y7b2b: capture the live member state before
2724 // abort_motion() destroys an eligible joint path or a plain
2725 // Cartesian LINE source (including an active Cartesian takeover
2726 // connector for D12 re-entry).
2727 const bool cartesian_takeover_target =
2729 !command.dynamic_pcs &&
2730 !command.cart.pose &&
2731 !command.cart.arc_path &&
2732 !command.cart.chain &&
2733 pose_frames_.kinematics_ != nullptr &&
2734 pose_frames_.pose_kinematics_ == nullptr &&
2735 pose_frames_.translation_path_differential_ != nullptr &&
2736 axes_.size() >= 2 && axes_.size() <= 3 &&
2738 if(active_ && !joint_window_.active_ && !cartesian_.window_active_) {
2739 capture_takeover_velocity(
2740 (command.path_kind == GroupPathKind::linear &&
2741 !command.dynamic_pcs) ||
2742 cartesian_takeover_target);
2743 }
2744 if(cartesian_takeover_target && connector_.has_captured_velocity()) {
2745 const rt::ErrorCode staged = stage_cartesian_takeover(normalized);
2746 if(staged != rt::ErrorCode::ok) {
2747 connector_.discard_capture();
2748 cartesian_.clear_staged_takeover();
2749 cartesian_.pending_takeover_grid_valid_ = false;
2751 }
2752 }
2753 if(halt_takeover && direct_path_.direct_active_) abort_direct_members();
2754 abort_halt();
2755 abort_wait();
2756 abort_motion();
2757 }
2758 command = normalized;
2759
2760 if(blending_buffer) {
2761 return submit_blend(command);
2762 }
2763
2764 if(command.buffer_mode == BufferMode::aborting ||
2765 (!active_ && !joint_window_.active_ && !wait_blocks_motion_start())) {
2766 const rt::ErrorCode started = start(command);
2767 if(started != rt::ErrorCode::ok) {
2768 return rt::Result<std::uint32_t>::failure(started);
2769 }
2771 }
2772
2773 // A buffered command behind an active look-ahead window queues
2774 // normally: the window terminates at rest (approved A5 matrix).
2775 const rt::ErrorCode queued = queue_.push_back(command);
2776 if(queued != rt::ErrorCode::ok) {
2778 }
2780 }
2781
2782 // MC_MoveCircularAbsolute/Relative (approved circular matrix, A3 v1):
2783 // three-point BORDER arcs in the plane of the first two axes, remaining
2784 // axes follow the path parameter linearly. Degenerate geometry is an
2785 // explicit error before any motion state is touched.
2787 {
2788 pending_dynamic_pcs_ = false;
2789 if(command.buffer_mode != BufferMode::aborting && has_queued_management()) {
2791 }
2792 if(jog_active_ && command.buffer_mode != BufferMode::aborting) {
2794 }
2795 command.tool_number = selected_tool_;
2796 command.payload_number = selected_payload_;
2797 command.tool_inverse = pose_frames_.pose_tool_inverse_;
2798 const rt::ErrorCode dynamics = resolve_dynamics(command);
2799 if(dynamics != rt::ErrorCode::ok) {
2800 return rt::Result<std::uint32_t>::failure(dynamics);
2801 }
2802 const bool halt_takeover = halt_command_live_ &&
2803 status_ == GroupStatus::stopping &&
2804 command.buffer_mode == BufferMode::aborting;
2805 if(status_ == GroupStatus::interrupted) {
2806 if(command.buffer_mode != BufferMode::aborting) {
2808 }
2809 }
2810 if(direct_path_.direct_active_ && !halt_takeover) {
2812 }
2813 if(command.circ_mode != CircMode::border &&
2814 command.circ_mode != CircMode::center &&
2815 command.circ_mode != CircMode::radius) {
2817 }
2818 if(command.circ_plane_mode != CircPlaneMode::xy_helical &&
2819 command.circ_plane_mode != CircPlaneMode::spatial_3d) {
2821 }
2822 const bool pose_cartesian_target =
2823 pose_frames_.pose_kinematics_ != nullptr &&
2824 (command.coord_system == CoordSystem::mcs ||
2825 command.coord_system == CoordSystem::pcs);
2826 const bool valid_target_size =
2827 command.target.size == axes_.size() ||
2828 (pose_cartesian_target && command.target.size == 6);
2829 bool valid_aux_size = false;
2830 if(command.circ_mode == CircMode::radius) {
2831 valid_aux_size =
2832 command.aux.size == 0 || command.aux.size == axes_.size() ||
2833 (pose_cartesian_target &&
2834 (command.aux.size == 3 || command.aux.size == 6));
2835 } else {
2836 valid_aux_size =
2837 command.aux.size == axes_.size() ||
2838 (pose_cartesian_target &&
2839 (command.aux.size == 3 || command.aux.size == 6));
2840 }
2841 if((status_ != GroupStatus::standby && status_ != GroupStatus::moving &&
2842 status_ != GroupStatus::interrupted && !halt_takeover) ||
2843 axes_.size() < 2 || !valid_target_size || !valid_aux_size ||
2844 command.velocity <= 0.0 || !std::isfinite(command.velocity) ||
2845 command.acceleration <= 0.0 || !std::isfinite(command.acceleration) ||
2846 command.deceleration <= 0.0 || !std::isfinite(command.deceleration) ||
2847 command.jerk <= 0.0 || !std::isfinite(command.jerk) ||
2848 !finite(command.target) || !finite(command.aux) ||
2849 !std::isfinite(command.tolerance) || command.tolerance < 0.0 ||
2850 !std::isfinite(command.circ_radius) ||
2851 !std::isfinite(command.circ_plane_normal.x) ||
2852 !std::isfinite(command.circ_plane_normal.y) ||
2853 !std::isfinite(command.circ_plane_normal.z)) {
2855 }
2856 const rt::ErrorCode orientation = select_orientation_interpolation(command);
2857 if(orientation != rt::ErrorCode::ok) {
2858 return rt::Result<std::uint32_t>::failure(orientation);
2859 }
2860 const bool arc_blending = command.buffer_mode == BufferMode::blending_low ||
2861 command.buffer_mode == BufferMode::blending_high;
2862 if(!std::isfinite(command.transition_velocity) ||
2863 command.transition_velocity < 0.0 ||
2864 command.transition_velocity > command.velocity ||
2865 (command.transition_velocity > 0.0 && !arc_blending)) {
2867 }
2868 if(command.transition_mode == TransitionMode::none) {
2869 if(command.transition_parameter != 0.0) {
2871 }
2872 } else if(command.transition_mode == TransitionMode::max_corner_deviation) {
2873 if(!std::isfinite(command.transition_parameter) ||
2874 command.transition_parameter <= 0.0) {
2876 }
2877 if(command.buffer_mode == BufferMode::aborting) {
2879 }
2880 if(!arc_blending) {
2882 }
2883 } else {
2885 }
2886 if(!members_ready_for_group_motion()) {
2888 }
2889 if(tracking_kind_ != TrackingKind::none && command.coord_system == CoordSystem::pcs) {
2890 if(command.buffer_mode != BufferMode::aborting) {
2892 }
2893 command.dynamic_pcs = true;
2894 pending_dynamic_pcs_ = true;
2895 pose_frames_.pending_dynamic_reference_frame_ = pose_frames_.workpiece_frame_;
2896 }
2897 if(command.circ_plane_mode == CircPlaneMode::spatial_3d &&
2898 command.interpolation_space != InterpolationSpace::cartesian) {
2900 }
2901 // Cartesian v2-B / Y5: opt-in Cartesian-domain arcs (xy_helical or
2902 // spatial_3d, BORDER/CENTER/RADIUS) resolve here and commit directly.
2903 if(command.interpolation_space == InterpolationSpace::cartesian) {
2904 if(arc_blending) {
2905 // Cartesian circular transition-window geometry is not
2906 // implemented; reject instead of queuing a fake blend.
2908 }
2909 const rt::ErrorCode prepared = prepare_cartesian_circular(command);
2910 if(prepared != rt::ErrorCode::ok) {
2911 return rt::Result<std::uint32_t>::failure(prepared);
2912 }
2913 if(command.command_id == 0) {
2914 command.command_id = next_command_id_++;
2915 }
2916 if(command.buffer_mode == BufferMode::aborting) {
2917 if(halt_takeover && direct_path_.direct_active_) abort_direct_members();
2918 abort_halt();
2919 abort_wait();
2920 abort_motion();
2921 }
2922 if(command.buffer_mode == BufferMode::aborting ||
2923 (!active_ && !joint_window_.active_ && !wait_blocks_motion_start())) {
2924 const rt::ErrorCode started = start(command);
2925 if(started != rt::ErrorCode::ok) {
2926 return rt::Result<std::uint32_t>::failure(started);
2927 }
2929 }
2930 const rt::ErrorCode queued = queue_.push_back(command);
2931 if(queued != rt::ErrorCode::ok) {
2933 }
2935 }
2936 // Orientation batch (approved matrix, decision #6): the pose pipeline
2937 // carries no joint-domain circular semantics; ACS arcs stay available
2938 // (decision #8 passthrough). Likewise, Cartesian-unit RADIUS arcs on a
2939 // kinematics plugin cannot be mixed with joint-space interpolation
2940 // (use InterpolationSpace::cartesian instead).
2941 if(pose_frames_.pose_kinematics_ != nullptr && command.coord_system != CoordSystem::acs) {
2943 }
2944 if(pose_frames_.kinematics_ != nullptr &&
2945 command.coord_system != CoordSystem::acs &&
2946 command.circ_mode == CircMode::radius) {
2948 }
2949 const rt::ErrorCode framed = apply_coordinate_frame(command);
2950 if(framed != rt::ErrorCode::ok) {
2952 }
2953 // Deterministic start point: the live commanded position for an
2954 // aborting takeover, otherwise the committed finish of the queue tail.
2955 // Geometry is validated before any abort so a rejected command never
2956 // destroys the active motion.
2957 const bool aborting = command.buffer_mode == BufferMode::aborting;
2958 std::array<double, MaxAxes> start_point{};
2959 for(std::size_t i = 0; i < axes_.size(); ++i) {
2960 start_point[i] = aborting ? axes_[i]->snapshot().command_position
2961 : queued_finish(i);
2962 }
2963 if(command.relative) {
2964 for(std::size_t i = 0; i < axes_.size(); ++i) {
2965 command.target.value[i] += start_point[i];
2966 if(command.circ_mode != CircMode::radius) {
2967 command.aux.value[i] += start_point[i];
2968 }
2969 }
2970 command.relative = false;
2971 }
2972
2973 const rt::ErrorCode limited = preflight_member_targets(command.target);
2974 if(limited != rt::ErrorCode::ok) {
2975 return rt::Result<std::uint32_t>::failure(limited);
2976 }
2977
2978 const geom::Vec3 plane_start{start_point[0], start_point[1], 0.0};
2979 const geom::Vec3 plane_finish{command.target.value[0], command.target.value[1], 0.0};
2980 const bool ccw = command.path_choice == CircPathChoice::counter_clockwise;
2983
2984 if(command.circ_mode == CircMode::border) {
2985 const geom::Vec3 plane_aux{command.aux.value[0], command.aux.value[1], 0.0};
2986 // Coincident points (zero arc length / zero radius) and the closed
2987 // start==finish circle are rejected in BORDER mode.
2988 constexpr double PointTolerance = 1e-12;
2989 if(geom::norm(plane_aux - plane_start) <= PointTolerance ||
2990 geom::norm(plane_finish - plane_aux) <= PointTolerance ||
2991 geom::norm(plane_finish - plane_start) <= PointTolerance) {
2993 }
2994 arc = geom::make_arc(plane_start, plane_aux, plane_finish);
2995 if(!arc) {
2997 }
2998 if(arc.value().radius > geom::norm(plane_finish - plane_start) * 1e6) {
3000 }
3001 const CircPathChoice derived = arc.value().sweep >= 0.0
3004 if(derived != command.path_choice) {
3006 }
3007 if(command.tolerance > 0.0) {
3008 const double via_sweep = geom::normalize_sweep(
3009 geom::angle_of(plane_aux, arc.value().center) -
3010 arc.value().start_angle,
3011 arc.value().sweep);
3012 const double fraction = via_sweep / arc.value().sweep;
3013 for(std::size_t i = 2; i < axes_.size(); ++i) {
3014 const double expected = start_point[i] +
3015 (command.target.value[i] - start_point[i]) *
3016 fraction;
3017 if(std::fabs(command.aux.value[i] - expected) > command.tolerance) {
3020 }
3021 }
3022 }
3023 } else if(command.circ_mode == CircMode::center) {
3024 const geom::Vec3 plane_center{command.aux.value[0], command.aux.value[1], 0.0};
3025 arc = geom::make_arc_center_xy(plane_start, plane_center, plane_finish, ccw);
3026 if(!arc) {
3027 return rt::Result<std::uint32_t>::failure(arc.error());
3028 }
3029 } else {
3030 arc = geom::make_arc_radius_xy(plane_start, plane_finish,
3031 command.circ_radius, ccw);
3032 if(!arc) {
3033 return rt::Result<std::uint32_t>::failure(arc.error());
3034 }
3035 }
3036 command.path_kind = GroupPathKind::circular;
3037 command.arc = arc.value();
3038
3039 if(command.command_id == 0) {
3040 command.command_id = next_command_id_++;
3041 }
3042 if(arc_blending) {
3043 // A5 v2 (KB-033): the arc joins the look-ahead window when the
3044 // junction is tangent-continuous, otherwise the request degrades
3045 // to a BUFFERED full-stop join (reported).
3046 return submit_blend_arc(command, start_point);
3047 }
3048 if(aborting) {
3049 // Y7b1/Y7b2a-2: geometry is fully validated before the live plain
3050 // path is captured, so an invalid arc never disturbs the active
3051 // command. Dynamic PCS targets do not open the Cartesian source gate.
3052 if(active_ && !joint_window_.active_ &&
3053 !cartesian_.window_active_) {
3054 capture_takeover_velocity(!command.dynamic_pcs);
3055 }
3056 if(halt_takeover && direct_path_.direct_active_) abort_direct_members();
3057 abort_halt();
3058 abort_wait();
3059 abort_motion();
3060 }
3061 if(aborting || (!active_ && !joint_window_.active_ && !wait_blocks_motion_start())) {
3062 const rt::ErrorCode started = start(command);
3063 if(started != rt::ErrorCode::ok) {
3064 return rt::Result<std::uint32_t>::failure(started);
3065 }
3067 }
3068 const rt::ErrorCode queued = queue_.push_back(command);
3069 if(queued != rt::ErrorCode::ok) {
3071 }
3073 }
3074
3075 // Degradation of a blending request to a plain BUFFERED join is reported
3076 // through this query, never silently (approved blending matrix).
3077 // Cartesian-interpolation batch (approved matrix decision #7): the
3078 // error that tripped the cycle-path errorstop, ok when none did.
3080 {
3081 return cartesian_.last_error_;
3082 }
3083
3085 {
3086 return status_ == GroupStatus::errorstop ? group_error_id_ : rt::ErrorCode::ok;
3087 }
3088
3089 std::uint32_t last_blend_degraded_command() const
3090 {
3091 return last_blend_degraded_id_;
3092 }
3093
3095 {
3096 GroupMotionState result{};
3097 result.tracking = tracking_kind_ != TrackingKind::none;
3098 if(status_ == GroupStatus::disabled || status_ == GroupStatus::errorstop) {
3099 result.in_position = false;
3100 result.standstill = false;
3101 return result;
3102 }
3103 double velocity = 0.0;
3104 double acceleration = 0.0;
3105 if(direct_path_.direct_active_) {
3106 result.active_command_id = direct_path_.direct_command_id_;
3107 result.in_position = false;
3108 result.standstill = false;
3109 for(std::size_t i = 0; i < axes_.size(); ++i) {
3110 const AxisSnapshot &snapshot = axes_[i]->snapshot();
3111 if(std::fabs(snapshot.command_velocity) > std::fabs(velocity)) {
3112 velocity = snapshot.command_velocity;
3113 }
3114 if(std::fabs(snapshot.command_acceleration) >
3115 std::fabs(acceleration)) {
3116 acceleration = snapshot.command_acceleration;
3117 }
3118 }
3119 } else if(joint_window_.active_ && !joint_window_.segments_.empty()) {
3120 result.active_command_id = joint_window_.segments_[joint_window_.index_].command_id;
3121 result.in_position = false;
3122 result.standstill = false;
3123 double position = 0.0;
3124 window_live_state(position, velocity, acceleration);
3125 } else if(active_) {
3126 result.active_command_id = active_command_.command_id;
3127 result.in_position = false;
3128 result.standstill = false;
3129 const otg::State1D state = otg::sample(
3130 active_profile_, rt::CycleTick::from_cycles(active_tick_));
3131 velocity = state.velocity;
3132 acceleration = state.acceleration;
3133 }
3134 constexpr double MotionTolerance = 1e-12;
3135 if(result.active_command_id != 0) {
3136 result.accelerating = acceleration > MotionTolerance;
3137 result.decelerating = acceleration < -MotionTolerance;
3138 result.constant_velocity = !result.accelerating &&
3139 !result.decelerating &&
3140 std::fabs(velocity) > MotionTolerance;
3141 }
3142 return result;
3143 }
3144
3145 double path_derivative(bool acceleration) const
3146 {
3147 if(joint_window_.active_ && !joint_window_.segments_.empty()) {
3148 double position = 0.0;
3149 double velocity = 0.0;
3150 double accel = 0.0;
3151 window_live_state(position, velocity, accel);
3152 return acceleration ? accel : velocity;
3153 }
3154 if(active_) {
3155 const otg::State1D state = otg::sample(
3156 active_profile_, rt::CycleTick::from_cycles(active_tick_));
3157 return acceleration ? state.acceleration : state.velocity;
3158 }
3159 return 0.0;
3160 }
3161
3162 rt::Result<GroupCommandInfo> command_info(std::uint32_t command_id) const
3163 {
3164 if(command_id == 0) {
3166 }
3167 if(command_id == wait_command_id_ &&
3168 wait_state_ != GroupWaitState::idle && wait_state_ != GroupWaitState::aborted) {
3169 GroupCommandInfo result{};
3170 result.state = wait_state_ == GroupWaitState::queued ||
3171 wait_state_ == GroupWaitState::stopping
3174 result.elapsed_cycles = wait_elapsed_cycles_;
3175 result.remaining_cycles = wait_duration_cycles_ > wait_elapsed_cycles_
3176 ? wait_duration_cycles_ - wait_elapsed_cycles_
3177 : 0;
3178 result.progress = wait_duration_cycles_ > 0
3179 ? static_cast<double>(wait_elapsed_cycles_) /
3180 static_cast<double>(wait_duration_cycles_)
3181 : 1.0;
3182 if(result.progress > 1.0) result.progress = 1.0;
3184 }
3185 if(command_id == halt_command_id_ && halt_command_live_) {
3186 GroupCommandInfo result{};
3190 }
3191 if(cartesian_.window_active_) {
3194 }
3195 if(direct_path_.direct_active_ && command_id == direct_path_.direct_command_id_) {
3196 GroupCommandInfo result{};
3199 }
3200 if(joint_window_.active_) {
3201 for(std::size_t i = joint_window_.index_; i < joint_window_.segments_.size(); ++i) {
3202 if(joint_window_.segments_[i].command_id != command_id) continue;
3203 GroupCommandInfo result{};
3204 result.state = i == joint_window_.index_ ? GroupCommandState::active
3206 if(i == joint_window_.index_) {
3207 result.elapsed_cycles = joint_window_.tick_;
3208 result.remaining_cycles =
3209 joint_window_.segments_[i].profile.duration_cycles() - joint_window_.tick_;
3210 double position = 0.0;
3211 double velocity = 0.0;
3212 double acceleration = 0.0;
3213 window_live_state(position, velocity, acceleration);
3214 const double length = joint_window_.segments_[i].line_length();
3215 result.remaining_distance = length > position
3216 ? length - position
3217 : 0.0;
3218 result.progress = length > 0.0 ? position / length : 1.0;
3219 }
3221 }
3222 }
3223 if(active_ && active_command_.command_id == command_id) {
3224 GroupCommandInfo result{};
3226 result.elapsed_cycles = active_tick_;
3227 result.remaining_cycles = active_duration_ - active_tick_;
3228 const otg::State1D state = otg::sample(
3229 active_profile_, rt::CycleTick::from_cycles(active_tick_));
3230 result.remaining_distance = active_path_length_ > state.position
3231 ? active_path_length_ - state.position
3232 : 0.0;
3233 result.progress = active_path_length_ > 0.0
3234 ? state.position / active_path_length_
3235 : 1.0;
3237 }
3238 for(std::size_t i = 0; i < queue_.size(); ++i) {
3239 if(queue_[i].command_id == command_id) {
3240 GroupCommandInfo result{};
3243 }
3244 }
3246 }
3247
3248 void cycle()
3249 {
3250 if(cycle_wait()) return;
3251 update_tracking_transform();
3252 apply_tracking_hold();
3253 update_path_odometer();
3254 cycle_axis_to_group_sync();
3255 if(group_sync_active_) {
3256 cycle_group_to_axis_sync();
3257 return;
3258 }
3259 if(status_ == GroupStatus::errorstop || status_ == GroupStatus::disabled ||
3260 status_ == GroupStatus::interrupted) {
3261 return;
3262 }
3263 for(std::size_t i = 0; i < axes_.size(); ++i) {
3264 if(!axes_[i]->powered() || axes_[i]->status() == AxisStatus::errorstop) {
3265 if(direct_path_.direct_active_) {
3266 direct_path_.last_aborted_direct_id_ = direct_path_.direct_command_id_;
3267 abort_direct_members();
3268 }
3269 abort_motion();
3270 interrupting_ = false;
3271 set_group_error(rt::ErrorCode::precondition_failed);
3272 return;
3273 }
3274 }
3275
3276 if(jog_active_) {
3277 jog_cycle();
3278 return;
3279 }
3280
3281 if(direct_path_.direct_active_) {
3282 bool all_done = true;
3283 for(std::size_t i = 0; i < axes_.size(); ++i) {
3284 if(axes_[i]->status() != AxisStatus::standstill) {
3285 all_done = false;
3286 break;
3287 }
3288 }
3289 if(all_done) {
3290 if(direct_path_.direct_stopping_) {
3291 abort_direct(direct_path_.direct_command_id_);
3292 } else {
3293 complete_direct(direct_path_.direct_command_id_);
3294 }
3295 direct_path_.direct_active_ = false;
3296 direct_path_.direct_stopping_ = false;
3297 status_ = GroupStatus::standby;
3298 start_next_queued();
3299 }
3300 return;
3301 }
3302
3303 if(cartesian_.window_active_) {
3304 cart_window_cycle();
3305 return;
3306 }
3307 if(joint_window_.active_) {
3308 window_cycle();
3309 return;
3310 }
3311
3312 if(!active_) {
3313 if(status_ == GroupStatus::stopping) {
3314 if(interrupting_) {
3315 interrupting_ = false;
3316 status_ = GroupStatus::interrupted;
3317 } else {
3318 status_ = GroupStatus::standby;
3319 }
3320 }
3321 if(status_ == GroupStatus::standby && !queue_.empty()) {
3322 start_next_queued();
3323 }
3324 return;
3325 }
3326
3327 ++active_tick_;
3328 double ratio = 1.0;
3329 if(active_path_length_ > 0.0) {
3330 const otg::State1D state =
3331 otg::sample(active_profile_, rt::CycleTick::from_cycles(active_tick_));
3332 ratio = state.position / active_path_length_;
3333 if(active_kind_ != GroupPathKind::linear) {
3334 ratio = ratio < 0.0 ? 0.0 : ratio;
3335 }
3336 ratio = ratio > 1.0 ? 1.0 : ratio;
3337 }
3338 if(active_kind_ == GroupPathKind::circular) {
3339 // Arc-length parameterized sampling: the first two axes trace the
3340 // arc, remaining axes follow the path parameter linearly.
3341 std::array<double, MaxAxes> connector_offsets{};
3342 connector_.sample_lateral_offsets(active_tick_, connector_offsets,
3343 axes_.size());
3344 const geom::Vec3 point = geom::sample(active_arc_, ratio * active_path_length_);
3345 axes_[0]->set_synchronized_position(point.x + connector_offsets[0]);
3346 axes_[1]->set_synchronized_position(point.y + connector_offsets[1]);
3347 for(std::size_t i = 2; i < axes_.size(); ++i) {
3348 const double position =
3349 active_start_[i] +
3350 (active_finish_[i] - active_start_[i]) * ratio +
3351 connector_offsets[i];
3352 axes_[i]->set_synchronized_position(position);
3353 }
3354 } else if(active_kind_ == GroupPathKind::cartesian_linear) {
3355 if(!cartesian_cycle(ratio)) {
3356 return;
3357 }
3358 } else {
3359 // Y7 (KB-051): during the connector, the output is the
3360 // along-path position plus the lateral decay offset. After
3361 // the lateral profile completes, its position is zero and
3362 // the motion continues as pure along-path interpolation.
3363 const bool vector_connector = connector_.vector_mode();
3364 std::array<double, MaxAxes> connector_offsets{};
3365 double lat_offset = 0.0;
3366 if(vector_connector) {
3367 connector_.sample_lateral_offsets(active_tick_,
3368 connector_offsets,
3369 axes_.size());
3370 } else {
3371 lat_offset = connector_.sample_lateral_offset(active_tick_);
3372 }
3373 for(std::size_t i = 0; i < axes_.size(); ++i) {
3374 double position =
3375 active_start_[i] + (active_finish_[i] - active_start_[i]) * ratio;
3376 if(vector_connector) {
3377 position += connector_offsets[i];
3378 } else if(lat_offset != 0.0) {
3379 position += connector_.lateral_dir(i) * lat_offset;
3380 }
3381 axes_[i]->set_synchronized_position(position);
3382 }
3383 }
3384
3385 if(!apply_dynamic_tracking_to_active()) {
3386 tracking_error_ = rt::ErrorCode::precondition_failed;
3387 abort_motion();
3388 set_group_error(tracking_error_);
3389 return;
3390 }
3391
3392 if(active_tick_ >= active_duration_) {
3393 finish_active();
3394 }
3395 }
3396
3398 {
3399 if(status_ != GroupStatus::errorstop) {
3401 }
3402 for(std::size_t i = 0; i < axes_.size(); ++i) {
3403 if(axes_[i]->status() == AxisStatus::errorstop) {
3404 const rt::ErrorCode reset = axes_[i]->reset_error();
3405 if(reset != rt::ErrorCode::ok) {
3406 return reset;
3407 }
3408 }
3409 }
3410 status_ = GroupStatus::standby;
3411 group_error_id_ = rt::ErrorCode::ok;
3412 return rt::ErrorCode::ok;
3413 }
3414
3415private:
3416 void set_group_error(rt::ErrorCode error)
3417 {
3418 group_error_id_ = error;
3419 status_ = GroupStatus::errorstop;
3420 }
3421
3422 rt::ErrorCode validate_group_parameter(GroupParameter parameter, double value) const
3423 {
3424 if(!std::isfinite(value)) return rt::ErrorCode::invalid_argument;
3425 if(parameter == GroupParameter::dynamics_mode) {
3426 return value == static_cast<double>(DynamicsMode::absolute) ||
3427 value == static_cast<double>(DynamicsMode::percentage)
3430 }
3432 if(value == static_cast<double>(TransitionReferencePoint::start_point)) {
3434 }
3435 return value == static_cast<double>(TransitionReferencePoint::end_point)
3437 : rt::ErrorCode::invalid_argument;
3438 }
3440 }
3441
3442 rt::ErrorCode validate_tool_data(std::size_t number, const ToolData &data) const
3443 {
3444 if(number == 0) return rt::ErrorCode::precondition_failed;
3445 if(number >= ToolCapacity) return rt::ErrorCode::out_of_range;
3446 for(double value : data.value) {
3447 if(!std::isfinite(value)) return rt::ErrorCode::invalid_argument;
3448 }
3449 return rt::ErrorCode::ok;
3450 }
3451
3452 rt::ErrorCode validate_group_sw_limits(const GroupSWLimits &limits) const
3453 {
3454 if(limits.count != axes_.size()) return rt::ErrorCode::invalid_argument;
3455 for(std::size_t i = 0; i < limits.count; ++i) {
3456 const GroupSWLimit &entry = limits.value[i];
3457 if(!std::isfinite(entry.minimum) || !std::isfinite(entry.maximum) ||
3458 entry.minimum > entry.maximum) {
3460 }
3461 }
3462 return rt::ErrorCode::ok;
3463 }
3464
3465 rt::ErrorCode validate_group_si_config(const GroupSiConfig &config,
3466 std::array<MotionLimits, MaxAxes> &next_limits) const
3467 {
3468 if(config.count != axes_.size() || config.cycle.period_ns() <= 0) {
3470 }
3471 for(std::size_t i = 0; i < config.count; ++i) {
3472 const rt::Result<MotionLimits> next =
3473 AxisModel::si_to_limits(config.cycle, config.value[i], axes_[i]->limits_);
3474 if(!next) return next.error();
3475 next_limits[i] = next.value();
3476 }
3477 return rt::ErrorCode::ok;
3478 }
3479
3480 rt::ErrorCode validate_kinematics(const KinTransformRef &transform,
3481 double min_singularity_margin,
3482 double max_joint_step) const;
3483 rt::ErrorCode apply_kinematics(const KinTransformRef &transform,
3484 double min_singularity_margin,
3485 double max_joint_step);
3486 rt::ErrorCode validate_coordinate_transform(CoordSystem coordinate_system,
3487 const ToolData &transform) const;
3488 rt::ErrorCode apply_coordinate_transform(CoordSystem coordinate_system,
3489 const ToolData &transform);
3490
3491 rt::Result<std::uint32_t> complete_immediate(rt::ErrorCode result)
3492 {
3493 if(result != rt::ErrorCode::ok) {
3495 }
3496 const std::uint32_t command_id = next_command_id_++;
3497 remember_management_result(command_id, rt::ErrorCode::ok);
3498 return rt::Result<std::uint32_t>::success(command_id);
3499 }
3500
3501 rt::Result<std::uint32_t> enqueue_management(GroupCommand command,
3502 ExecutionMode mode)
3503 {
3504 if(mode != ExecutionMode::queued) {
3506 }
3507 if(status_ != GroupStatus::standby && status_ != GroupStatus::moving &&
3508 status_ != GroupStatus::stopping) {
3510 }
3511 command.command_id = next_command_id_++;
3512 const rt::ErrorCode queued = queue_.push_back(command);
3513 return queued == rt::ErrorCode::ok
3515 : rt::Result<std::uint32_t>::failure(queued);
3516 }
3517
3518 void remember_management_result(std::uint32_t command_id, rt::ErrorCode error)
3519 {
3520 if(management_results_.size() == QueueCapacity) {
3521 for(std::size_t i = 1; i < management_results_.size(); ++i) {
3522 management_results_[i - 1] = management_results_[i];
3523 }
3524 management_results_.pop_back();
3525 }
3526 management_results_.push_back({command_id, error});
3527 }
3528
3529 void remember_management_aborted(std::uint32_t command_id)
3530 {
3531 if(command_id == 0) return;
3532 if(aborted_management_ids_.size() == QueueCapacity) {
3533 for(std::size_t i = 1; i < aborted_management_ids_.size(); ++i) {
3534 aborted_management_ids_[i - 1] = aborted_management_ids_[i];
3535 }
3536 aborted_management_ids_.pop_back();
3537 }
3538 aborted_management_ids_.push_back(command_id);
3539 }
3540
3541 bool command_queued(std::uint32_t command_id) const
3542 {
3543 for(std::size_t i = 0; i < queue_.size(); ++i) {
3544 if(queue_[i].command_id == command_id) return true;
3545 }
3546 return false;
3547 }
3548
3549 bool has_queued_management() const
3550 {
3551 for(std::size_t i = 0; i < queue_.size(); ++i) {
3552 if(queue_[i].kind != GroupCommandKind::motion &&
3553 queue_[i].kind != GroupCommandKind::direct) return true;
3554 }
3555 return false;
3556 }
3557
3558 void abort_queued_management()
3559 {
3560 for(std::size_t i = 0; i < queue_.size(); ++i) {
3561 if(queue_[i].kind != GroupCommandKind::motion) {
3562 remember_management_aborted(queue_[i].command_id);
3563 if(queue_[i].kind == GroupCommandKind::halt &&
3564 halt_command_id_ == queue_[i].command_id) {
3565 last_aborted_halt_id_ = queue_[i].command_id;
3566 halt_command_live_ = false;
3567 }
3568 }
3569 }
3570 }
3571
3572 rt::ErrorCode execute_management(const GroupCommand &command)
3573 {
3574 active_management_id_ = command.command_id;
3575 active_management_kind_ = command.kind;
3577 switch(command.kind) {
3579 if(status_ != GroupStatus::standby || !members_ready_for_group_motion()) {
3581 break;
3582 }
3583 for(std::size_t i = 0; i < axes_.size(); ++i) {
3584 result = axes_[i]->home_direct(command.target.value[i]);
3585 if(result != rt::ErrorCode::ok) break;
3586 }
3587 if(result != rt::ErrorCode::ok) set_group_error(result);
3588 break;
3590 abort_queued_management();
3591 queue_.clear();
3592 last_completed_halt_id_ = command.command_id;
3593 halt_command_id_ = command.command_id;
3594 halt_command_live_ = true;
3595 break;
3597 result = apply_kinematics(command.kin_transform,
3598 command.min_singularity_margin,
3599 command.max_joint_step);
3600 break;
3602 result = apply_coordinate_transform(command.coord_system, command.tool_data);
3603 break;
3605 result = validate_group_parameter(command.parameter, command.parameter_value);
3606 if(result == rt::ErrorCode::ok) {
3607 if(command.parameter == GroupParameter::dynamics_mode) {
3608 dynamics_mode_ = static_cast<DynamicsMode>(
3609 static_cast<int>(command.parameter_value));
3610 } else {
3611 transition_reference_point_ = TransitionReferencePoint::end_point;
3612 }
3613 }
3614 break;
3616 result = validate_group_sw_limits(command.sw_limits);
3617 if(result == rt::ErrorCode::ok) {
3618 for(std::size_t i = 0; i < command.sw_limits.count; ++i) {
3619 MotionLimits next = axes_[i]->limits_;
3620 next.min_position = command.sw_limits.value[i].minimum;
3621 next.max_position = command.sw_limits.value[i].maximum;
3622 next.min_position_enabled = command.sw_limits.value[i].minimum_enabled;
3623 next.max_position_enabled = command.sw_limits.value[i].maximum_enabled;
3624 axes_[i]->limits_ = next;
3625 }
3626 }
3627 break;
3629 result = validate_tool_data(command.tool_number, command.tool_data);
3630 if(result == rt::ErrorCode::ok) {
3631 tools_[command.tool_number] = command.tool_data;
3632 tool_defined_[command.tool_number] = true;
3633 }
3634 break;
3638 break;
3639 }
3640 remember_management_result(command.command_id, result);
3641 active_management_id_ = 0;
3642 active_management_kind_ = GroupCommandKind::motion;
3643 return result;
3644 }
3645
3646 bool cycle_wait()
3647 {
3648 if((wait_state_ == GroupWaitState::queued ||
3649 wait_state_ == GroupWaitState::stopping) &&
3650 status_ == GroupStatus::standby) {
3651 wait_state_ = GroupWaitState::active;
3652 }
3653 if(wait_state_ != GroupWaitState::active) return false;
3654 ++wait_elapsed_cycles_;
3655 if(wait_elapsed_cycles_ >= wait_duration_cycles_) {
3656 wait_elapsed_cycles_ = wait_duration_cycles_;
3657 wait_state_ = GroupWaitState::completed;
3658 start_next_queued();
3659 }
3660 return true;
3661 }
3662
3663 void abort_wait()
3664 {
3665 if(wait_state_ == GroupWaitState::queued ||
3666 wait_state_ == GroupWaitState::stopping ||
3667 wait_state_ == GroupWaitState::active) {
3668 last_aborted_wait_id_ = wait_command_id_;
3669 wait_state_ = GroupWaitState::aborted;
3670 }
3671 }
3672
3673 bool wait_blocks_motion_start() const
3674 {
3675 return wait_state_ == GroupWaitState::queued ||
3676 wait_state_ == GroupWaitState::stopping ||
3677 wait_state_ == GroupWaitState::active;
3678 }
3679
3680 void abort_halt()
3681 {
3682 if(halt_command_live_) {
3683 if(halt_command_done(halt_command_id_)) {
3684 last_completed_halt_id_ = halt_command_id_;
3685 } else {
3686 last_aborted_halt_id_ = halt_command_id_;
3687 }
3688 halt_command_live_ = false;
3689 }
3690 }
3691 bool solve_tracking_tcp(const geom::RigidTransform &tcp)
3692 {
3693 double seed[MaxAxes] = {};
3694 double solved[MaxAxes] = {};
3695 for(std::size_t i = 0; i < axes_.size(); ++i) {
3696 seed[i] = axes_[i]->snapshot().command_position;
3697 solved[i] = seed[i];
3698 }
3700 if(pose_frames_.pose_kinematics_ != nullptr) {
3701 const geom::RigidTransform flange =
3702 geom::compose(tcp, pose_frames_.active_pose_tool_inverse_);
3703 kin::Pose6 pose{};
3704 pose.position[0] = flange.translation.x;
3705 pose.position[1] = flange.translation.y;
3706 pose.position[2] = flange.translation.z;
3707 for(int row = 0; row < 3; ++row) {
3708 for(int column = 0; column < 3; ++column) {
3709 pose.rotation[row][column] = flange.rotation[row][column];
3710 }
3711 }
3712 result = pose_frames_.pose_kinematics_->inverse(
3713 pose, seed, pose_frames_.pose_max_joint_step_, solved);
3714 } else {
3715 const geom::Vec3 flange = tcp.translation - pose_frames_.active_tool_offset_;
3716 if(pose_frames_.kinematics_ != nullptr) {
3717 result = pose_frames_.kinematics_->inverse(flange, seed, axes_.size(), solved);
3718 } else {
3719 if(axes_.size() > 0) solved[0] = flange.x;
3720 if(axes_.size() > 1) solved[1] = flange.y;
3721 if(axes_.size() > 2) solved[2] = flange.z;
3722 }
3723 }
3724 if(result != rt::ErrorCode::ok) return false;
3725 for(std::size_t i = 0; i < axes_.size(); ++i) {
3726 const double previous_velocity = axes_[i]->snapshot().command_velocity;
3727 const double velocity = solved[i] - seed[i];
3728 axes_[i]->set_synchronized_state(
3729 solved[i], velocity, velocity - previous_velocity);
3730 }
3731 return true;
3732 }
3733
3734 bool current_tracking_tcp(geom::RigidTransform &tcp) const
3735 {
3736 double joints[MaxAxes] = {};
3737 for(std::size_t i = 0; i < axes_.size(); ++i) {
3738 joints[i] = axes_[i]->snapshot().command_position;
3739 }
3740 if(pose_frames_.pose_kinematics_ != nullptr) {
3741 kin::Pose6 flange{};
3742 pose_frames_.pose_kinematics_->forward(joints, flange);
3743 geom::RigidTransform flange_transform{};
3744 flange_transform.translation =
3745 {flange.position[0], flange.position[1], flange.position[2]};
3746 for(int row = 0; row < 3; ++row) {
3747 for(int column = 0; column < 3; ++column) {
3748 flange_transform.rotation[row][column] = flange.rotation[row][column];
3749 }
3750 }
3751 tcp = geom::compose(flange_transform, pose_frames_.active_pose_tool_);
3752 return true;
3753 }
3754 geom::Vec3 point{};
3755 if(pose_frames_.kinematics_ != nullptr) {
3756 if(pose_frames_.kinematics_->forward(joints, axes_.size(), point) != rt::ErrorCode::ok) {
3757 return false;
3758 }
3759 } else {
3760 if(axes_.size() > 0) point.x = joints[0];
3761 if(axes_.size() > 1) point.y = joints[1];
3762 if(axes_.size() > 2) point.z = joints[2];
3763 }
3764 tcp.translation = point + pose_frames_.active_tool_offset_;
3765 return true;
3766 }
3767
3768 bool apply_dynamic_tracking_to_active()
3769 {
3770 if(!active_command_.dynamic_pcs) return true;
3771 geom::RigidTransform base_tcp{};
3772 if(!current_tracking_tcp(base_tcp)) return false;
3773 const geom::RigidTransform delta = geom::compose(
3774 pose_frames_.workpiece_frame_, geom::invert(pose_frames_.active_dynamic_reference_frame_));
3775 const geom::RigidTransform tracked_tcp = geom::compose(delta, base_tcp);
3776 if(!solve_tracking_tcp(tracked_tcp)) return false;
3777 pose_frames_.tracking_hold_pose_ =
3778 geom::compose(geom::invert(pose_frames_.workpiece_frame_), tracked_tcp);
3779 tracking_following_ = true;
3780 tracking_motion_seen_ = true;
3781 return true;
3782 }
3783
3784 void apply_tracking_hold()
3785 {
3786 if(!tracking_following_ || tracking_kind_ == TrackingKind::none || active_ ||
3787 joint_window_.active_ || cartesian_.window_active_ || direct_path_.direct_active_ || jog_active_ ||
3788 group_sync_active_) {
3789 return;
3790 }
3791 const geom::RigidTransform target =
3792 geom::compose(pose_frames_.workpiece_frame_, pose_frames_.tracking_hold_pose_);
3793 if(!solve_tracking_tcp(target)) {
3794 tracking_error_ = rt::ErrorCode::precondition_failed;
3795 set_group_error(tracking_error_);
3796 }
3797 }
3798
3799 void update_path_odometer()
3800 {
3801 if(!path_odometer_initialized_) {
3802 for(std::size_t i = 0; i < axes_.size(); ++i) {
3803 path_odometer_position_[i] = axes_[i]->snapshot().command_position;
3804 path_odometer_member_velocity_[i] = 0.0;
3805 }
3806 path_odometer_initialized_ = true;
3807 return;
3808 }
3809 double squared_distance = 0.0;
3810 for(std::size_t i = 0; i < axes_.size(); ++i) {
3811 const double position = axes_[i]->snapshot().command_position;
3812 const double delta = position - path_odometer_position_[i];
3813 squared_distance += delta * delta;
3814 path_odometer_member_velocity_[i] = delta;
3815 path_odometer_position_[i] = position;
3816 }
3817 const double distance = std::sqrt(squared_distance);
3818 path_odometer_acceleration_ = distance - path_odometer_velocity_;
3819 path_odometer_velocity_ = distance;
3820 path_odometer_ += distance;
3821 }
3822
3823 static bool valid_tracking_pose(const ToolData &pose)
3824 {
3825 for(double value : pose.value) {
3826 if(!std::isfinite(value)) return false;
3827 }
3828 return true;
3829 }
3830
3831 static geom::RigidTransform tracking_pose(const ToolData &pose)
3832 {
3833 return geom::make_rpy_transform(pose.value[0], pose.value[1], pose.value[2],
3834 pose.value[3], pose.value[4], pose.value[5]);
3835 }
3836
3837 rt::Result<std::uint32_t> begin_tracking(TrackingKind kind,
3838 CoordSystem coord_system,
3839 BufferMode buffer_mode)
3840 {
3841 if(status_ == GroupStatus::disabled || status_ == GroupStatus::errorstop ||
3842 coord_system != CoordSystem::pcs || buffer_mode != BufferMode::aborting) {
3844 }
3845 if(tracking_kind_ != TrackingKind::none) {
3846 last_aborted_tracking_id_ = tracking_command_id_;
3847 }
3848 tracking_kind_ = kind;
3849 tracking_command_id_ = next_command_id_++;
3850 tracking_master_group_ = nullptr;
3851 tracking_master_axis_ = nullptr;
3852 tracking_motion_seen_ = status_ == GroupStatus::moving;
3853 tracking_following_ = false;
3854 tracking_error_ = rt::ErrorCode::ok;
3855 return rt::Result<std::uint32_t>::success(tracking_command_id_);
3856 }
3857
3858 void cancel_tracking()
3859 {
3860 if(tracking_kind_ == TrackingKind::none) return;
3861 last_aborted_tracking_id_ = tracking_command_id_;
3862 tracking_kind_ = TrackingKind::none;
3863 tracking_command_id_ = 0;
3864 tracking_master_group_ = nullptr;
3865 tracking_master_axis_ = nullptr;
3866 tracking_motion_seen_ = false;
3867 tracking_following_ = false;
3868 tracking_error_ = rt::ErrorCode::ok;
3869 }
3870 void set_tracking_frame(const geom::RigidTransform &frame)
3871 {
3872 pose_frames_.workpiece_frame_ = frame;
3873 pose_frames_.workpiece_frame_rpy_[0] = frame.translation.x;
3874 pose_frames_.workpiece_frame_rpy_[1] = frame.translation.y;
3875 pose_frames_.workpiece_frame_rpy_[2] = frame.translation.z;
3876 geom::extract_rpy(frame.rotation, pose_frames_.workpiece_frame_rpy_[3],
3877 pose_frames_.workpiece_frame_rpy_[4], pose_frames_.workpiece_frame_rpy_[5]);
3878 }
3879 void update_tracking_transform()
3880 {
3881 if(tracking_kind_ == TrackingKind::none) return;
3882 if(status_ == GroupStatus::moving) tracking_motion_seen_ = true;
3883
3884 if(tracking_kind_ == TrackingKind::dynamic_group) {
3885 GroupPosition master_position{};
3886 if(tracking_master_group_ == nullptr ||
3887 tracking_master_group_->read_cartesian(
3888 CoordSystem::mcs, PositionSource::actual, master_position) !=
3890 master_position.size < 3) {
3891 tracking_error_ = rt::ErrorCode::precondition_failed;
3892 return;
3893 }
3894 ToolData master_pose{};
3895 for(std::size_t i = 0; i < 6 && i < master_position.size; ++i) {
3896 master_pose.value[i] = master_position.value[i];
3897 }
3898 set_tracking_frame(
3899 geom::compose(tracking_pose(master_pose), tracking_pose(tracking_transform_)));
3900 return;
3901 }
3902
3903 if(tracking_master_axis_ == nullptr || !tracking_master_axis_->powered() ||
3904 tracking_master_axis_->status() == AxisStatus::errorstop) {
3905 tracking_error_ = rt::ErrorCode::precondition_failed;
3906 return;
3907 }
3908 const double delta = tracking_master_axis_->snapshot().actual_position -
3909 tracking_master_origin_;
3910 const geom::RigidTransform origin = tracking_pose(tracking_origin_);
3911 const geom::RigidTransform object = tracking_pose(tracking_transform_);
3912 const geom::RigidTransform motion =
3913 tracking_kind_ == TrackingKind::conveyor
3914 ? geom::make_rpy_transform(delta, 0.0, 0.0, 0.0, 0.0, 0.0)
3915 : geom::make_rpy_transform(0.0, 0.0, 0.0, 0.0, 0.0, delta);
3916 set_tracking_frame(geom::compose(geom::compose(origin, motion), object));
3917 }
3918
3919 static double move_towards(double current, double target, double maximum_step)
3920 {
3921 if(maximum_step <= 0.0) return target;
3922 if(target > current + maximum_step) return current + maximum_step;
3923 if(target < current - maximum_step) return current - maximum_step;
3924 return target;
3925 }
3926
3927 void cycle_axis_to_group_sync()
3928 {
3929 if(path_sync_slave_ == nullptr) return;
3930 if(path_sync_slave_->sync_kind_ != SyncKind::group_path ||
3931 path_sync_slave_->sync_id_ != path_sync_id_) {
3932 path_sync_slave_ = nullptr;
3933 path_sync_id_ = 0;
3934 path_sync_in_sync_ = false;
3935 return;
3936 }
3937
3938 const double desired_position =
3939 path_sync_slave_origin_ + (path_odometer_ - path_sync_origin_) * path_sync_ratio_;
3940 const double desired_velocity = path_odometer_velocity_ * path_sync_ratio_;
3941 if(path_sync_acceleration_ == 0.0 && path_sync_deceleration_ == 0.0 &&
3942 path_sync_jerk_ == 0.0) {
3943 path_sync_velocity_ = desired_velocity;
3944 path_sync_acceleration_state_ = path_odometer_acceleration_ * path_sync_ratio_;
3945 path_sync_in_sync_ = true;
3946 } else if(!path_sync_in_sync_) {
3947 const double position_error =
3948 desired_position - path_sync_slave_->snapshot().command_position;
3949 const double entry_velocity = desired_velocity + position_error;
3950 const double acceleration_limit =
3951 std::fabs(entry_velocity) >= std::fabs(path_sync_velocity_)
3952 ? path_sync_acceleration_
3953 : path_sync_deceleration_;
3954 const double requested_acceleration = entry_velocity - path_sync_velocity_;
3955 const double jerk_limited = move_towards(
3956 path_sync_acceleration_state_, requested_acceleration, path_sync_jerk_);
3957 path_sync_acceleration_state_ =
3958 move_towards(0.0, jerk_limited, acceleration_limit);
3959 path_sync_velocity_ += path_sync_acceleration_state_;
3960 const bool velocity_reached =
3961 std::fabs(path_sync_velocity_ - desired_velocity) <= 1e-12;
3962 const bool position_reached =
3963 std::fabs(position_error) <= std::fabs(path_sync_velocity_) + 1e-12;
3964 path_sync_in_sync_ = velocity_reached && position_reached;
3965 if(path_sync_in_sync_) {
3966 path_sync_slave_->sync_phase_ = SyncPhase::engaged;
3967 }
3968 }
3969
3970 double position = desired_position;
3971 if(!path_sync_in_sync_) {
3972 position = path_sync_slave_->snapshot().command_position + path_sync_velocity_;
3973 }
3974 path_sync_slave_->snapshot_.active_command_id = path_sync_id_;
3975 path_sync_slave_->set_synchronized_state(
3976 position, path_sync_velocity_, path_sync_acceleration_state_);
3977 }
3978
3979 void cycle_group_to_axis_sync()
3980 {
3981 if(group_sync_master_ == nullptr || !group_sync_master_->powered() ||
3982 group_sync_master_->status() == AxisStatus::errorstop) {
3983 last_aborted_group_sync_id_ = group_sync_id_;
3984 group_sync_active_ = false;
3985 set_group_error(rt::ErrorCode::precondition_failed);
3986 return;
3987 }
3988 for(std::size_t axis_index = 0; axis_index < axes_.size(); ++axis_index) {
3989 if(!axes_[axis_index]->powered() ||
3990 axes_[axis_index]->status() == AxisStatus::errorstop) {
3991 last_aborted_group_sync_id_ = group_sync_id_;
3992 group_sync_active_ = false;
3993 set_group_error(rt::ErrorCode::precondition_failed);
3994 return;
3995 }
3996 }
3997
3998 const double total = group_sync_cumulative_[group_sync_count_ - 1];
3999 double path_position =
4000 group_sync_master_->snapshot().command_position - group_sync_master_origin_;
4001 if(group_sync_mode_ == PathMode::periodic) {
4002 path_position = std::fmod(path_position, total);
4003 if(path_position < 0.0) path_position += total;
4004 } else {
4005 if(path_position < 0.0) path_position = 0.0;
4006 if(path_position > total) path_position = total;
4007 }
4008
4009 std::size_t segment = 1;
4010 while(segment + 1 < group_sync_count_ &&
4011 path_position > group_sync_cumulative_[segment]) {
4012 ++segment;
4013 }
4014 const double begin = group_sync_cumulative_[segment - 1];
4015 const double length = group_sync_cumulative_[segment] - begin;
4016 const double ratio = length > 0.0 ? (path_position - begin) / length : 1.0;
4017 for(std::size_t axis_index = 0; axis_index < axes_.size(); ++axis_index) {
4018 const double position =
4019 group_sync_waypoints_[segment - 1].value[axis_index] +
4020 (group_sync_waypoints_[segment].value[axis_index] -
4021 group_sync_waypoints_[segment - 1].value[axis_index]) *
4022 ratio;
4023 const double previous_velocity = axes_[axis_index]->snapshot().command_velocity;
4024 const double velocity = position - group_sync_previous_.value[axis_index];
4025 axes_[axis_index]->set_synchronized_state(
4026 position, velocity, velocity - previous_velocity);
4027 group_sync_previous_.value[axis_index] = position;
4028 }
4029 }
4030
4031 static bool any_direction(const GroupPosition &direction)
4032 {
4033 for(std::size_t i = 0; i < direction.size; ++i) {
4034 if(direction.value[i] != 0.0) return true;
4035 }
4036 return false;
4037 }
4038
4039 rt::ErrorCode validate_jog(CoordSystem coord_system,
4040 const GroupPosition &direction,
4041 const JogCommandOptions &options) const
4042 {
4043 if(!std::isfinite(options.velocity_override) ||
4044 options.velocity_override < 0.0 || options.velocity_override > 1.0 ||
4045 !std::isfinite(options.acceleration_override) ||
4046 options.acceleration_override < 0.0 ||
4047 options.acceleration_override > 1.0 ||
4048 !std::isfinite(options.max_linear_distance) ||
4049 options.max_linear_distance < 0.0 ||
4050 !std::isfinite(options.max_angular_distance) ||
4051 options.max_angular_distance < 0.0) {
4053 }
4054 if(axes_.empty() || direction.size == 0 || !finite(direction)) {
4056 }
4057 if(jogging_dynamics_.size != axes_.size()) {
4059 }
4060 const PathDynamics &path = jogging_dynamics_.path;
4061 if(!std::isfinite(path.velocity) || !std::isfinite(path.acceleration) ||
4062 !std::isfinite(path.deceleration) || !std::isfinite(path.jerk) ||
4063 path.velocity <= 0.0 || path.acceleration <= 0.0 ||
4064 path.deceleration <= 0.0 || path.jerk <= 0.0) {
4066 }
4067 for(std::size_t i = 0; i < axes_.size(); ++i) {
4068 if(!std::isfinite(jogging_dynamics_.axis_velocity[i]) ||
4069 !std::isfinite(jogging_dynamics_.axis_acceleration[i]) ||
4070 !std::isfinite(jogging_dynamics_.axis_deceleration[i]) ||
4071 !std::isfinite(jogging_dynamics_.axis_jerk[i]) ||
4072 jogging_dynamics_.axis_velocity[i] <= 0.0 ||
4073 jogging_dynamics_.axis_acceleration[i] <= 0.0 ||
4074 jogging_dynamics_.axis_deceleration[i] <= 0.0 ||
4075 jogging_dynamics_.axis_jerk[i] <= 0.0) {
4077 }
4078 }
4079 if(coord_system == CoordSystem::acs) {
4080 if(options.max_linear_distance > 0.0 ||
4081 options.max_angular_distance > 0.0) {
4083 }
4084 return direction.size == axes_.size() ? rt::ErrorCode::ok
4086 }
4087 if(coord_system != CoordSystem::mcs && coord_system != CoordSystem::pcs) {
4089 }
4090 if(pose_frames_.kinematics_ == nullptr && pose_frames_.pose_kinematics_ == nullptr) {
4092 }
4093 if(options.max_angular_distance > 0.0 && pose_frames_.pose_kinematics_ == nullptr) {
4095 }
4096 return direction.size >= 3 ? rt::ErrorCode::ok
4098 }
4099
4100 static double approach(double current, double target, double step)
4101 {
4102 if(current < target) return current + step > target ? target : current + step;
4103 if(current > target) return current - step < target ? target : current - step;
4104 return current;
4105 }
4106
4107 void advance_jog_state(std::size_t index, double target_velocity)
4108 {
4109 const double acceleration_limit =
4110 target_velocity == 0.0
4111 ? (jog_stop_deceleration_ > 0.0 ? jog_stop_deceleration_
4112 : jogging_dynamics_.axis_deceleration[index] *
4113 jog_options_.acceleration_override)
4114 : jogging_dynamics_.axis_acceleration[index] *
4115 jog_options_.acceleration_override;
4116 const double desired_acceleration =
4117 target_velocity > jog_velocity_[index]
4118 ? acceleration_limit
4119 : (target_velocity < jog_velocity_[index] ? -acceleration_limit : 0.0);
4120 jog_acceleration_[index] =
4121 approach(jog_acceleration_[index], desired_acceleration,
4122 jog_stop_jerk_ > 0.0 && target_velocity == 0.0
4123 ? jog_stop_jerk_
4124 : jogging_dynamics_.axis_jerk[index]);
4125 const double previous = jog_velocity_[index];
4126 jog_velocity_[index] += jog_acceleration_[index];
4127 if((target_velocity - previous) * (target_velocity - jog_velocity_[index]) <= 0.0) {
4128 jog_velocity_[index] = target_velocity;
4129 jog_acceleration_[index] = 0.0;
4130 }
4131 }
4132
4133 bool all_jog_stopped() const
4134 {
4135 for(std::size_t i = 0; i < axes_.size(); ++i) {
4136 if(jog_velocity_[i] != 0.0 || jog_acceleration_[i] != 0.0) return false;
4137 }
4138 return true;
4139 }
4140
4141 void advance_cart_jog_state(std::size_t index, double target_velocity)
4142 {
4143 const double acceleration_limit =
4144 target_velocity == 0.0 && jog_stop_deceleration_ > 0.0
4145 ? jog_stop_deceleration_
4146 : (target_velocity == 0.0
4147 ? jogging_dynamics_.path.deceleration *
4148 jog_options_.acceleration_override
4149 : jogging_dynamics_.path.acceleration *
4150 jog_options_.acceleration_override);
4151 const double desired = target_velocity > jog_cart_velocity_[index]
4152 ? acceleration_limit
4153 : (target_velocity < jog_cart_velocity_[index]
4154 ? -acceleration_limit
4155 : 0.0);
4156 const double jerk = target_velocity == 0.0 && jog_stop_jerk_ > 0.0
4157 ? jog_stop_jerk_
4158 : jogging_dynamics_.path.jerk;
4159 jog_cart_acceleration_[index] =
4160 approach(jog_cart_acceleration_[index], desired, jerk);
4161 const double previous = jog_cart_velocity_[index];
4162 jog_cart_velocity_[index] += jog_cart_acceleration_[index];
4163 if((target_velocity - previous) *
4164 (target_velocity - jog_cart_velocity_[index]) <=
4165 0.0) {
4166 jog_cart_velocity_[index] = target_velocity;
4167 jog_cart_acceleration_[index] = 0.0;
4168 }
4169 }
4170
4171 bool cart_jog_stopped() const
4172 {
4173 for(std::size_t i = 0; i < jog_cart_velocity_.size(); ++i) {
4174 if(jog_cart_velocity_[i] != 0.0 || jog_cart_acceleration_[i] != 0.0) {
4175 return false;
4176 }
4177 }
4178 return true;
4179 }
4180
4181 void apply_jog_distance_limits(GroupPosition &next)
4182 {
4183 if(jog_options_.max_linear_distance > 0.0 && next.size >= 3) {
4184 const double dx = next.value[0] - jog_cartesian_start_[0];
4185 const double dy = next.value[1] - jog_cartesian_start_[1];
4186 const double dz = next.value[2] - jog_cartesian_start_[2];
4187 const double distance = std::sqrt(dx * dx + dy * dy + dz * dz);
4188 if(distance >= jog_options_.max_linear_distance && distance > 0.0) {
4189 const double scale = jog_options_.max_linear_distance / distance;
4190 next.value[0] = jog_cartesian_start_[0] + dx * scale;
4191 next.value[1] = jog_cartesian_start_[1] + dy * scale;
4192 next.value[2] = jog_cartesian_start_[2] + dz * scale;
4193 for(std::size_t i = 0; i < 3; ++i) {
4194 jog_direction_.value[i] = 0.0;
4195 jog_cart_velocity_[i] = 0.0;
4196 jog_cart_acceleration_[i] = 0.0;
4197 }
4198 }
4199 }
4200 if(jog_options_.max_angular_distance > 0.0 && next.size >= 6) {
4201 const geom::RigidTransform start = geom::make_rpy_transform(
4202 0.0, 0.0, 0.0, jog_cartesian_start_[3],
4204 geom::RigidTransform candidate = geom::make_rpy_transform(
4205 0.0, 0.0, 0.0, next.value[3], next.value[4], next.value[5]);
4206 double axis[3] = {};
4207 double angle = 0.0;
4208 geom::relative_axis_angle(start.rotation, candidate.rotation, axis, angle);
4209 if(angle >= jog_options_.max_angular_distance && angle > 0.0) {
4210 double delta[3][3] = {};
4211 geom::rodrigues(axis, jog_options_.max_angular_distance, delta);
4212 geom::rotation_multiply(start.rotation, delta, candidate.rotation);
4213 geom::extract_rpy(candidate.rotation, next.value[3], next.value[4],
4214 next.value[5]);
4215 for(std::size_t i = 3; i < 6; ++i) {
4216 jog_direction_.value[i] = 0.0;
4217 jog_cart_velocity_[i] = 0.0;
4218 jog_cart_acceleration_[i] = 0.0;
4219 }
4220 }
4221 }
4222 }
4223
4224 bool solve_jog_cartesian(GroupPosition &target)
4225 {
4226 double q[MaxAxes] = {};
4227 const bool pcs = jog_coord_system_ == CoordSystem::pcs;
4228 if(pose_frames_.pose_kinematics_ != nullptr) {
4229 geom::RigidTransform tcp = geom::make_rpy_transform(
4230 target.value[0], target.value[1], target.value[2], target.value[3],
4231 target.value[4], target.value[5]);
4232 if(pcs) tcp = geom::compose(pose_frames_.workpiece_frame_, tcp);
4233 const geom::RigidTransform flange = geom::compose(tcp, pose_frames_.jog_pose_tool_inverse_);
4234 kin::Pose6 pose{};
4235 pose.position[0] = flange.translation.x;
4236 pose.position[1] = flange.translation.y;
4237 pose.position[2] = flange.translation.z;
4238 for(int row = 0; row < 3; ++row) {
4239 for(int column = 0; column < 3; ++column) {
4240 pose.rotation[row][column] = flange.rotation[row][column];
4241 }
4242 }
4243 const rt::ErrorCode solved = pose_frames_.pose_kinematics_->inverse(
4244 pose, jog_position_.data(), pose_frames_.pose_max_joint_step_, q);
4245 if(solved != rt::ErrorCode::ok ||
4246 pose_frames_.pose_kinematics_->singularity_margin(q) < pose_frames_.pose_min_margin_) {
4247 jog_error_ = solved == rt::ErrorCode::ok
4249 : solved;
4250 return false;
4251 }
4252 } else {
4253 geom::Vec3 point = cartesian_part(target);
4254 if(pcs) point = geom::transform_point(pose_frames_.workpiece_frame_, point);
4255 point = point - pose_frames_.jog_tool_offset_;
4256 const rt::ErrorCode solved =
4257 pose_frames_.kinematics_->inverse(point, jog_position_.data(), axes_.size(), q);
4258 if(solved != rt::ErrorCode::ok ||
4259 pose_frames_.kinematics_->singularity_margin(q, axes_.size()) <
4260 pose_frames_.kinematics_min_margin_) {
4261 jog_error_ = solved == rt::ErrorCode::ok
4263 : solved;
4264 return false;
4265 }
4266 }
4267 for(std::size_t i = 0; i < axes_.size(); ++i) {
4268 if(!axes_[i]->target_inside_limits(q[i])) {
4269 jog_error_ = rt::ErrorCode::out_of_range;
4270 return false;
4271 }
4272 jog_position_[i] = q[i];
4273 }
4274 return true;
4275 }
4276
4277 void jog_cycle()
4278 {
4279 if(jog_coord_system_ == CoordSystem::acs) {
4280 for(std::size_t i = 0; i < axes_.size(); ++i) {
4281 const double target = jog_direction_.value[i] *
4282 jogging_dynamics_.axis_velocity[i] *
4283 jog_options_.velocity_override;
4284 advance_jog_state(i, target);
4285 const double next = jog_position_[i] + jog_velocity_[i];
4286 if(!axes_[i]->target_inside_limits(next)) {
4287 jog_error_ = rt::ErrorCode::out_of_range;
4288 for(std::size_t slot = 0; slot < jog_direction_.size; ++slot) {
4289 jog_direction_.value[slot] = 0.0;
4290 }
4291 jog_releasing_ = true;
4292 advance_jog_state(i, 0.0);
4293 } else {
4294 jog_position_[i] = next;
4295 }
4296 axes_[i]->set_synchronized_state(jog_position_[i], jog_velocity_[i],
4297 jog_acceleration_[i]);
4298 }
4299 } else {
4300 double linear_norm = 0.0;
4301 double angular_norm = 0.0;
4302 for(std::size_t i = 0; i < 3 && i < jog_direction_.size; ++i) {
4303 linear_norm += jog_direction_.value[i] * jog_direction_.value[i];
4304 }
4305 for(std::size_t i = 3; i < 6 && i < jog_direction_.size; ++i) {
4306 angular_norm += jog_direction_.value[i] * jog_direction_.value[i];
4307 }
4308 linear_norm = std::sqrt(linear_norm);
4309 angular_norm = std::sqrt(angular_norm);
4310 const double linear_scale = linear_norm > 1.0 ? 1.0 / linear_norm : 1.0;
4311 const double angular_scale = angular_norm > 1.0 ? 1.0 / angular_norm : 1.0;
4312 for(std::size_t i = 0; i < jog_cart_velocity_.size(); ++i) {
4313 const double scale = i < 3 ? linear_scale : angular_scale;
4314 const double component = i < jog_direction_.size
4315 ? jog_direction_.value[i] * scale
4316 : 0.0;
4317 advance_cart_jog_state(
4318 i, component * jogging_dynamics_.path.velocity *
4319 jog_options_.velocity_override);
4320 }
4321 GroupPosition next = jog_cartesian_position_;
4322 for(std::size_t i = 0; i < 6 && i < next.size; ++i) {
4323 next.value[i] += jog_cart_velocity_[i];
4324 }
4325 apply_jog_distance_limits(next);
4326 if(!solve_jog_cartesian(next)) {
4327 jog_direction_ = {};
4328 jog_direction_.size = next.size;
4329 jog_releasing_ = true;
4330 } else {
4331 jog_cartesian_position_ = next;
4332 }
4333 for(std::size_t i = 0; i < axes_.size(); ++i) {
4334 const double previous_position = axes_[i]->snapshot().command_position;
4335 const double previous_velocity = axes_[i]->snapshot().command_velocity;
4336 const double velocity = jog_position_[i] - previous_position;
4337 axes_[i]->set_synchronized_state(jog_position_[i], velocity,
4338 velocity - previous_velocity);
4339 }
4340 }
4341 const bool stopped = jog_coord_system_ == CoordSystem::acs
4342 ? all_jog_stopped()
4343 : cart_jog_stopped();
4344 if(jog_releasing_ && stopped) {
4345 jog_active_ = false;
4346 jog_releasing_ = false;
4347 for(std::size_t i = 0; i < axes_.size(); ++i) axes_[i]->clear_synchronized();
4348 status_ = GroupStatus::standby;
4349 return;
4350 }
4351 status_ = any_direction(jog_direction_) || !stopped
4352 ? (jog_releasing_ ? GroupStatus::stopping : GroupStatus::moving)
4354 }
4355 void apply_selected_tool()
4356 {
4357 const ToolData &tool = tools_[selected_tool_];
4358 pose_frames_.pose_tool_ = geom::make_rpy_transform(tool.value[0], tool.value[1], tool.value[2],
4359 tool.value[3], tool.value[4], tool.value[5]);
4360 pose_frames_.pose_tool_inverse_ = geom::invert(pose_frames_.pose_tool_);
4361 pose_frames_.tool_offset_ = {tool.value[0], tool.value[1], tool.value[2]};
4362 for(std::size_t i = 0; i < tool.value.size(); ++i) {
4363 pose_frames_.tool_transform_rpy_[i] = tool.value[i];
4364 }
4365 }
4366 void snapshot_selections()
4367 {
4368 active_tool_ = selected_tool_;
4369 active_payload_ = selected_payload_;
4370 }
4371 void snapshot_active_tool_transform();
4372 bool active_tool_transform_applies() const;
4373
4374 rt::ErrorCode preflight_member_targets(const GroupPosition &target) const
4375 {
4376 if(target.size != axes_.size()) return rt::ErrorCode::invalid_argument;
4377 for(std::size_t i = 0; i < axes_.size(); ++i) {
4378 if(!axes_[i]->target_inside_limits(target.value[i])) {
4380 }
4381 }
4382 return rt::ErrorCode::ok;
4383 }
4384
4385 bool configuration_writable() const
4386 {
4387 if(status_ != GroupStatus::disabled && status_ != GroupStatus::standby) {
4388 return false;
4389 }
4390 if(active_ || direct_path_.direct_active_ || joint_window_.active_ || cartesian_.window_active_ || jog_active_ ||
4391 !queue_.empty()) {
4392 return false;
4393 }
4394 for(std::size_t i = 0; i < axes_.size(); ++i) {
4395 if(axes_[i]->status() == AxisStatus::synchronized_motion ||
4396 axes_[i]->has_standalone_motion()) {
4397 return false;
4398 }
4399 }
4400 return true;
4401 }
4402
4403 static rt::ErrorCode apply_path_update(PathDynamics &target,
4404 const PathDynamics &update)
4405 {
4406 const double values[4] = {update.velocity, update.acceleration,
4407 update.deceleration, update.jerk};
4408 for(double value : values) {
4409 if(!std::isfinite(value)) return rt::ErrorCode::invalid_argument;
4410 }
4411 if(update.velocity > 0.0) target.velocity = update.velocity;
4412 if(update.acceleration > 0.0) target.acceleration = update.acceleration;
4413 if(update.deceleration > 0.0) target.deceleration = update.deceleration;
4414 if(update.jerk > 0.0) target.jerk = update.jerk;
4415 return rt::ErrorCode::ok;
4416 }
4417
4418 rt::ErrorCode update_path_dynamics(PathDynamics &target,
4419 const PathDynamics &update)
4420 {
4421 if(!configuration_writable()) return rt::ErrorCode::precondition_failed;
4422 PathDynamics next = target;
4423 const rt::ErrorCode result = apply_path_update(next, update);
4424 if(result == rt::ErrorCode::ok) target = next;
4425 return result;
4426 }
4427
4428 rt::ErrorCode resolve_dynamics(GroupCommand &command) const
4429 {
4430 if(command.use_default_dynamics) {
4431 command.velocity = default_dynamics_.velocity;
4432 command.acceleration = default_dynamics_.acceleration;
4433 command.deceleration = default_dynamics_.deceleration;
4434 command.jerk = default_dynamics_.jerk;
4435 return rt::ErrorCode::ok;
4436 }
4437 if(dynamics_mode_ == DynamicsMode::percentage) {
4438 if(!std::isfinite(command.velocity) || !std::isfinite(command.acceleration) ||
4439 !std::isfinite(command.deceleration) || !std::isfinite(command.jerk) ||
4440 command.velocity < 0.0 || command.velocity > 100.0 ||
4441 command.acceleration < 0.0 || command.acceleration > 100.0 ||
4442 command.deceleration < 0.0 || command.deceleration > 100.0 ||
4443 command.jerk < 0.0 || command.jerk > 100.0) {
4445 }
4446 command.velocity = reference_dynamics_.velocity * command.velocity / 100.0;
4447 command.acceleration =
4448 reference_dynamics_.acceleration * command.acceleration / 100.0;
4449 command.deceleration =
4450 reference_dynamics_.deceleration * command.deceleration / 100.0;
4451 command.jerk = reference_dynamics_.jerk * command.jerk / 100.0;
4452 }
4453 return rt::ErrorCode::ok;
4454 }
4455
4456 void abort_direct_members();
4457 rt::ErrorCode start_direct(const GroupCommand &command);
4458 void complete_direct(std::uint32_t command_id);
4459 void abort_direct(std::uint32_t command_id);
4460 rt::ErrorCode stop_direct_members(double deceleration, double jerk);
4461
4462 bool members_ready_for_group_motion() const
4463 {
4464 for(std::size_t i = 0; i < axes_.size(); ++i) {
4465 const AxisStatus member_status = axes_[i]->status();
4466 if(!axes_[i]->powered() || member_status == AxisStatus::errorstop ||
4467 (status_ == GroupStatus::standby &&
4468 (member_status != AxisStatus::standstill ||
4469 axes_[i]->has_standalone_motion()))) {
4470 return false;
4471 }
4472 }
4473 return true;
4474 }
4475
4476 std::size_t find(const AxisModel &axis) const
4477 {
4478 for(std::size_t i = 0; i < axes_.size(); ++i) {
4479 if(axes_[i] == &axis) {
4480 return i;
4481 }
4482 }
4483 return axes_.size();
4484 }
4485
4486 std::size_t find(IdentInGroup ident) const
4487 {
4488 for(std::size_t i = 0; i < member_idents_.size(); ++i) {
4489 if(member_idents_[i].index == ident.index) {
4490 return i;
4491 }
4492 }
4493 return member_idents_.size();
4494 }
4495
4496 static bool finite(const GroupPosition &position)
4497 {
4498 for(std::size_t i = 0; i < position.size; ++i) {
4499 if(!std::isfinite(position.value[i])) {
4500 return false;
4501 }
4502 }
4503 return true;
4504 }
4505
4506 static geom::Vec3 cartesian_part(const GroupPosition &position);
4507
4508 rt::ErrorCode select_orientation_interpolation(GroupCommand &command) const;
4509
4510 static void store_cartesian_part(GroupPosition &position, geom::Vec3 point);
4511 // Approved coordinate matrix (B1 v1): MCS/PCS targets convert to ACS at
4512 // submit time on the first three coordinates (higher axes pass through in
4513 // ACS); ACS commands never see the frames. Absolute points go through the
4514 // workpiece frame (PCS) and then subtract the tool offset (MCS and PCS);
4515 // relative distances only rotate — translation and tool offset cancel
4516 // between two TCP positions. The v1 ACS<->MCS mapping is the declared
4517 // identity (Cartesian rig; kinematics plugins arrive with B2).
4518 rt::ErrorCode apply_coordinate_frame(GroupCommand &command) const;
4519
4520 // One Cartesian target through frame, tool offset, and inverse solution.
4521 // Relative displacements only rotate (translation and tool offset cancel
4522 // between two TCP positions) and resolve against the flange position of
4523 // the seed joints.
4524 rt::ErrorCode solve_cartesian_target(GroupPosition &position,
4525 bool relative,
4526 bool pcs,
4527 const double *seed) const;
4528
4529 // Cartesian-interpolation batch (approved matrix decisions #1-#6 and
4530 // the approved v2 addendum): submit-side resolution of opt-in segments.
4531 // Undefined combinations reject, 33 chord samples run the seed-chained
4532 // inverse (the step gate lives inside the inverse; margin checked per
4533 // sample), the command velocity scales so the worst per-cycle joint
4534 // step stays inside half the step gate (pose pipeline; translational
4535 // groups are bounded by the margin entry ban), and the ACS endpoint
4536 // joints plus the cycle geometry stay behind.
4537 // Cartesian v3 window (approved addendum, KB-050): consecutive
4538 // Cartesian blending successors on translational plugin groups form a
4539 // look-ahead window in the plugin Cartesian space — lines joined by
4540 // quintic corners, node velocities from the bidirectional jerk-exact
4541 // scan capped by corner curvature, one jerk-limited profile per line,
4542 // corners ridden at constant node velocity (terminal sub-cycle
4543 // quantization declared). The cycle path samples the window geometry
4544 // and runs one analytic inverse (KB-044 machinery); failures are the
4545 // declared group errorstop.
4546 static constexpr std::size_t CartWindowPieces =
4547 GroupCartesianState<MaxAxes>::WindowCapacity;
4548 using CartPiece = GroupCartesianState<MaxAxes>::Piece;
4549 using CartStorage = GroupCartesianState<MaxAxes>::Storage;
4550
4551 rt::Result<std::uint32_t> submit_cartesian_window(GroupCommand command);
4552 bool cart_window_rebuild_storage(CartStorage &storage,
4553 std::size_t start_index,
4554 double entry_velocity,
4555 double entry_acceleration,
4556 double acc,
4557 double dec,
4558 double jerk) const;
4559 geom::Vec3 cart_piece_point(const CartPiece &piece, double s) const;
4560 void cart_piece_pose(const CartPiece &piece, double s,
4561 geom::RigidTransform &tcp) const;
4562 bool cart_window_emit(geom::Vec3 point);
4563 bool cart_window_emit_pose(const geom::RigidTransform &tcp);
4564 void cart_window_cycle();
4565 geom::Vec3 cart_window_point_at(double composite) const;
4566 void cart_window_pose_at(double composite, geom::RigidTransform &tcp) const;
4567 rt::ErrorCode cart_window_stop(double deceleration, double jerk);
4568 void cart_window_reset();
4569 rt::ErrorCode command_member_velocities(GroupPosition &velocities) const;
4570 rt::Result<std::uint32_t> submit_cartesian_blend(GroupCommand command);
4571 rt::ErrorCode prepare_cartesian_linear(GroupCommand &command);
4572 rt::ErrorCode prepare_cartesian_circular(GroupCommand &command);
4573 rt::ErrorCode cartesian_guards(const GroupCommand &command) const;
4574 void segment_start_joints(const GroupCommand &command, double *chain) const;
4575 geom::RigidTransform pose_start_tcp(const double *chain) const;
4576 rt::ErrorCode prevalidate_cartesian(GroupCommand &command,
4577 CartesianSegment &segment,
4578 double *chain);
4579 geom::Vec3 cartesian_point_at(const CartesianSegment &segment,
4580 double fraction) const;
4581 void cartesian_pose_at(const CartesianSegment &segment,
4582 double fraction,
4583 geom::RigidTransform &tcp) const;
4584 bool cartesian_cycle(double ratio);
4585 rt::ErrorCode stage_cartesian_takeover(const GroupCommand &command);
4586 rt::ErrorCode plan_cartesian_connector_stop(double deceleration, double jerk);
4587 double queued_finish(std::size_t axis_index) const
4588 {
4589 double finish =
4590 joint_window_.active_
4591 ? joint_window_.segments_[joint_window_.segments_.size() - 1].target[axis_index]
4592 : (cartesian_.window_active_
4593 ? cart_tail_joints_[axis_index]
4594 : (direct_path_.direct_active_
4595 ? active_finish_[axis_index]
4596 : (active_ ? active_finish_[axis_index]
4597 : axes_[axis_index]->snapshot().command_position)));
4598 for(std::size_t i = 0; i < queue_.size(); ++i) {
4599 const GroupCommand &queued = queue_[i];
4600 if(queued.kind != GroupCommandKind::motion &&
4601 queued.kind != GroupCommandKind::direct) continue;
4602 finish = queued.relative ? finish + queued.target.value[axis_index]
4603 : queued.target.value[axis_index];
4604 }
4605 return finish;
4606 }
4607
4608 GroupCommand normalize(GroupCommand command) const
4609 {
4610 if(!command.relative) {
4611 return command;
4612 }
4613 for(std::size_t i = 0; i < axes_.size(); ++i) {
4614 command.target.value[i] = queued_finish(i) + command.target.value[i];
4615 }
4616 command.relative = false;
4617 return command;
4618 }
4619
4620 rt::ErrorCode start(GroupCommand command)
4621 {
4622 active_tool_ = command.tool_number;
4623 active_payload_ = command.payload_number;
4624 pose_frames_.active_pose_tool_inverse_ = command.tool_inverse;
4625 pose_frames_.active_pose_tool_ = geom::invert(command.tool_inverse);
4626 pose_frames_.active_tool_offset_ = {pose_frames_.active_pose_tool_.translation.x,
4627 pose_frames_.active_pose_tool_.translation.y,
4628 pose_frames_.active_pose_tool_.translation.z};
4629 active_command_ = command;
4630 if(command.dynamic_pcs && pending_dynamic_pcs_) {
4631 pose_frames_.active_dynamic_reference_frame_ = pose_frames_.pending_dynamic_reference_frame_;
4632 }
4633 pending_dynamic_pcs_ = false;
4634 if(!command.dynamic_pcs) tracking_following_ = false;
4635 override_paused_ = false;
4636 active_tick_ = 0;
4637 connector_.deactivate();
4638 cartesian_.clear_takeover();
4639 cartesian_.clear_envelope();
4640 double longest = 0.0;
4641 for(std::size_t i = 0; i < axes_.size(); ++i) {
4642 active_start_[i] = axes_[i]->snapshot().command_position;
4643 active_finish_[i] = command.target.value[i];
4644 const double distance = std::fabs(active_finish_[i] - active_start_[i]);
4645 if(distance > longest) {
4646 longest = distance;
4647 }
4648 }
4649
4650 // Shared scalar path: one jerk-limited 1D profile drives the path
4651 // parameter, so members stay on the commanded geometry by construction
4652 // and the group honors the full command dynamics (KB-027). Linear
4653 // paths default to max_axis (preserving all 18 golden replays) and
4654 // opt-in to scale-stable L2 Euclidean normalization (KB-054); circular
4655 // paths use the arc length.
4656 active_kind_ = command.path_kind;
4657 active_arc_ = command.arc;
4658 if(command.path_kind == GroupPathKind::linear &&
4659 command.linear_metric == LinearPathMetric::euclidean &&
4660 longest > 0.0) {
4661 double scaled_sq = 0.0;
4662 for(std::size_t i = 0; i < axes_.size(); ++i) {
4663 const double ratio = (active_finish_[i] - active_start_[i]) / longest;
4664 scaled_sq += ratio * ratio;
4665 }
4666 longest = longest * std::sqrt(scaled_sq);
4667 }
4668 if(command.path_kind == GroupPathKind::circular) {
4669 longest = command.arc.length;
4670 }
4671 cartesian_.active_segment_ = command.cart;
4672 if(command.path_kind == GroupPathKind::cartesian_linear) {
4673 longest = command.cart.length;
4674 for(std::size_t i = 0; i < axes_.size(); ++i) {
4675 cartesian_.joints_[i] = active_start_[i];
4676 }
4677 }
4678 active_path_length_ = longest;
4679
4680 if(cartesian_.staged_takeover_valid_) {
4681 const bool is_conn = cartesian_.staged_takeover_is_connector_;
4682 const bool has_safe = cartesian_.staged_takeover_has_safe_envelope_;
4683 const otg::Limits1D safe_lim = cartesian_.staged_safe_limits_;
4684 active_profile_ = cartesian_.staged_base_profile_;
4685 active_duration_ = cartesian_.staged_base_duration_;
4686 if(is_conn) {
4687 cartesian_.takeover_residuals_ = cartesian_.staged_residuals_;
4688 cartesian_.takeover_residual_duration_ = cartesian_.staged_residual_duration_;
4689 cartesian_.takeover_tcp_tube_ = cartesian_.staged_tcp_tube_;
4690 cartesian_.takeover_active_ = (cartesian_.staged_residual_duration_ > 0);
4691 cartesian_.takeover_stopping_ = false;
4692 }
4693 cartesian_.active_safe_envelope_ = has_safe;
4694 cartesian_.active_safe_limits_ = safe_lim;
4695 cartesian_.active_replay_only_takeover_ = !has_safe;
4696 if(has_safe) {
4697 active_command_.velocity = std::min(active_command_.velocity, safe_lim.max_velocity);
4698 active_command_.acceleration =
4699 std::min(active_command_.acceleration, safe_lim.max_acceleration);
4700 active_command_.deceleration =
4701 std::min(active_command_.deceleration, safe_lim.max_deceleration);
4702 active_command_.jerk = std::min(active_command_.jerk, safe_lim.max_jerk);
4703 }
4704 cartesian_.clear_staged_takeover();
4705 cartesian_.pending_takeover_grid_valid_ = false;
4706 connector_.take_captured_velocity();
4707 active_ = true;
4708 status_ = GroupStatus::moving;
4709 return rt::ErrorCode::ok;
4710 }
4711
4712 // Y7/Y7b1/Y7b2a: joint-domain linear/circular targets may accept a
4713 // captured member state from a plain Cartesian LINE source.
4714 // Y7b2b (Step 5): plain translational Cartesian LINE targets with an
4715 // explicitly bound TranslationPathDifferential companion are staged and
4716 // verified before abort_motion() above; this branch stays as a safe guard.
4717 const bool connector_target =
4718 (command.path_kind == GroupPathKind::linear ||
4719 command.path_kind == GroupPathKind::circular) &&
4720 !command.dynamic_pcs;
4721 const bool vector_capture = connector_.captured_vector_state();
4722 const bool had_capture = connector_.take_captured_velocity();
4723 const bool try_connector = had_capture && connector_target;
4724 cartesian_.pending_takeover_grid_valid_ = false;
4725
4726 if(try_connector) {
4727 const otg::Limits1D limits{
4728 command.velocity, command.acceleration, command.deceleration,
4729 command.jerk};
4731 if(command.path_kind == GroupPathKind::circular) {
4732 planned = connector_.plan_circular(
4733 limits, longest, axes_.size(), active_start_,
4734 active_finish_, active_arc_, active_profile_,
4735 active_duration_);
4736 } else if(vector_capture) {
4737 planned = connector_.plan_linear_vector(
4738 limits, longest, axes_.size(), active_start_,
4739 active_finish_, active_profile_, active_duration_,
4740 command.linear_metric == LinearPathMetric::euclidean);
4741 } else {
4742 planned = connector_.plan(
4743 limits, longest, axes_.size(), active_start_,
4744 active_finish_, active_profile_, active_duration_);
4745 }
4746 if(planned == rt::ErrorCode::ok) {
4747 active_ = true;
4748 status_ = GroupStatus::moving;
4749 return rt::ErrorCode::ok;
4750 }
4751 // Connector planning failed; fall through to the rest-start path.
4752 connector_.deactivate();
4753 }
4754
4755 if(longest > 0.0) {
4756 const rt::Result<otg::Profile1D> profile = otg::plan_time_optimal(
4757 {0.0, 0.0, 0.0},
4758 {longest, 0.0, 0.0},
4759 {command.velocity, command.acceleration, command.deceleration,
4760 command.jerk});
4761 if(!profile) {
4762 return profile.error();
4763 }
4764 active_profile_ = profile.value();
4765 active_duration_ = active_profile_.duration_cycles();
4766 } else {
4767 active_profile_ = otg::Profile1D{};
4768 active_duration_ = 1;
4769 }
4770 active_ = true;
4771 status_ = GroupStatus::moving;
4772 return rt::ErrorCode::ok;
4773 }
4774
4775 void finish_active()
4776 {
4777 if(override_paused_) {
4778 return;
4779 }
4780 if(interrupting_) {
4781 const otg::State1D state =
4782 otg::sample(active_profile_, rt::CycleTick::from_cycles(active_tick_));
4783 interrupt_ratio_ = state.position / active_path_length_;
4784 if(interrupt_ratio_ > 1.0) { interrupt_ratio_ = 1.0; }
4785 }
4786 if(!interrupting_ && active_command_.direct_semantics) {
4787 complete_direct(active_command_.command_id);
4788 }
4789 active_ = false;
4790 connector_.deactivate();
4791 cartesian_.clear_takeover();
4792 if(!interrupting_) {
4793 cartesian_.clear_envelope();
4794 for(std::size_t i = 0; i < axes_.size(); ++i) {
4795 axes_[i]->clear_synchronized();
4796 }
4797 status_ = GroupStatus::standby;
4798 start_next_queued();
4799 }
4800 }
4801
4802 void start_next_queued()
4803 {
4804 if(queue_.empty()) {
4805 return;
4806 }
4807 const GroupCommand next = queue_[0];
4808 for(std::size_t i = 1; i < queue_.size(); ++i) {
4809 queue_[i - 1] = queue_[i];
4810 }
4811 queue_.pop_back();
4812 if(next.kind == GroupCommandKind::motion) {
4813 start(next);
4814 } else if(next.kind == GroupCommandKind::direct) {
4815 const rt::ErrorCode started = start_direct(next);
4816 if(started != rt::ErrorCode::ok) abort_direct(next.command_id);
4817 } else {
4818 execute_management(next);
4819 }
4820 }
4821
4822 void abort_motion()
4823 {
4824 if(direct_path_.direct_active_) abort_direct(direct_path_.direct_command_id_);
4825 if(active_ && active_command_.direct_semantics) {
4826 abort_direct(active_command_.command_id);
4827 }
4828 if(joint_window_.active_) {
4829 for(std::size_t i = joint_window_.index_; i < joint_window_.segments_.size(); ++i) {
4830 if(joint_window_.segments_[i].kind == WindowKind::direct_line) {
4831 abort_direct(joint_window_.segments_[i].command_id);
4832 }
4833 }
4834 }
4835 for(std::size_t i = 0; i < queue_.size(); ++i) {
4836 if(queue_[i].direct_semantics) {
4837 abort_direct(queue_[i].command_id);
4838 }
4839 }
4840 if(group_sync_active_) {
4841 last_aborted_group_sync_id_ = group_sync_id_;
4842 group_sync_active_ = false;
4843 group_sync_master_ = nullptr;
4844 group_sync_id_ = 0;
4845 }
4846 if(jog_active_) {
4847 last_aborted_jog_id_ = jog_command_id_;
4848 jog_active_ = false;
4849 jog_releasing_ = false;
4850 }
4851 active_ = false;
4852 connector_.deactivate();
4853 cartesian_.clear_takeover();
4854 cartesian_.clear_envelope();
4855 direct_path_.direct_active_ = false;
4856 direct_path_.direct_stopping_ = false;
4857 override_paused_ = false;
4858 interrupting_ = false;
4859 interrupted_plain_ = false;
4860 interrupted_window_ = false;
4861 window_reset();
4862 cart_window_reset();
4863 abort_queued_management();
4864 queue_.clear();
4865 active_tick_ = 0;
4866 for(std::size_t i = 0; i < axes_.size(); ++i) {
4867 axes_[i]->clear_synchronized();
4868 }
4869 }
4870
4871 // Y7/Y7b1/Y7b2a: capture the live member state before abort_motion()
4872 // clears it. Cartesian capture is opt-in only for a plain joint
4873 // LINE/circular target and a plain Cartesian LINE source.
4874 void current_member_output_state(
4875 std::array<double, MaxAxes> &velocity,
4876 std::array<double, MaxAxes> &acceleration) const
4877 {
4878 velocity.fill(0.0);
4879 acceleration.fill(0.0);
4880 if(!path_odometer_initialized_) {
4881 return;
4882 }
4883 for(std::size_t i = 0; i < axes_.size(); ++i) {
4884 velocity[i] = axes_[i]->snapshot().command_position -
4885 path_odometer_position_[i];
4886 acceleration[i] =
4887 velocity[i] - path_odometer_member_velocity_[i];
4888 }
4889 }
4890
4891 void capture_takeover_velocity(bool allow_cartesian_source = false)
4892 {
4893 if(active_command_.dynamic_pcs) {
4894 connector_.discard_capture();
4895 return;
4896 }
4897 if(active_kind_ == GroupPathKind::cartesian_linear) {
4898 if(!allow_cartesian_source ||
4899 cartesian_.active_segment_.arc_path ||
4900 cartesian_.active_segment_.chain ||
4901 !path_odometer_initialized_) {
4902 connector_.discard_capture();
4903 return;
4904 }
4905 std::array<double, MaxAxes> output_velocity{};
4906 std::array<double, MaxAxes> output_acceleration{};
4907 current_member_output_state(output_velocity, output_acceleration);
4908 connector_.capture_output_history(
4909 active_, output_velocity, output_acceleration, axes_.size());
4910 return;
4911 }
4912 if(active_kind_ == GroupPathKind::circular) {
4913 connector_.capture_circular(
4914 active_, active_arc_, active_path_length_, active_profile_,
4915 active_tick_, active_start_, active_finish_, axes_.size());
4916 } else {
4917 connector_.capture(active_, active_kind_ == GroupPathKind::linear,
4918 active_path_length_, active_profile_, active_tick_,
4919 active_start_, active_finish_, axes_.size());
4920 }
4921 std::array<double, MaxAxes> output_velocity{};
4922 std::array<double, MaxAxes> output_acceleration{};
4923 current_member_output_state(output_velocity, output_acceleration);
4924 connector_.set_captured_output_state(
4925 output_velocity, output_acceleration, axes_.size());
4926 }
4927
4928 // A5 look-ahead window (KB-032, approved A5 matrix): consecutive blending
4929 // successors form a window of linear segments joined by quintic corner
4930 // curves. Node velocities come from a trapezoid-level bidirectional scan
4931 // capped by the corner curvature bound; every segment runs its own
4932 // jerk-limited profile between node velocities (the OTG nonzero-target
4933 // cruise domain), so straight parts are no longer dragged down to the
4934 // sharpest corner speed. All planning happens synchronously at submit;
4935 // the cycle path only samples precomputed data.
4936 static constexpr std::size_t BlendTableSize =
4937 GroupLookaheadWindow<MaxAxes>::BlendTableSize;
4938 static constexpr std::size_t WindowCapacity =
4939 GroupLookaheadWindow<MaxAxes>::Capacity;
4940 using WindowNode = GroupLookaheadWindow<MaxAxes>::Node;
4941 using WindowKind = GroupLookaheadWindow<MaxAxes>::Kind;
4942 using WindowSegment = GroupLookaheadWindow<MaxAxes>::Segment;
4943
4944 // N-dimensional unit tangent at a segment boundary: lines use dir; arcs
4945 // combine the plane tangent with the linear following of higher axes.
4946 void window_tangent(const WindowSegment &seg, bool at_exit,
4947 std::array<double, MaxAxes> &out) const;
4948 rt::Result<std::uint32_t> submit_blend(GroupCommand command);
4949 bool convert_active_linear_to_window();
4950 rt::Result<std::uint32_t> submit_blend_arc(
4951 GroupCommand command,
4952 const std::array<double, MaxAxes> &start_point);
4953 bool window_rebuild(bool &late);
4954 std::int64_t window_remaining_cycles() const;
4955 void window_cycle();
4956 void sample_window_segment(const WindowSegment &seg, double arclength);
4957 void sample_window_curve(const WindowNode &node, double arclength);
4958 void sample_window_arclength(double arclength);
4959 void window_live_state(double &s_live, double &v_live, double &a_live) const;
4960 void window_reset();
4961 rt::Result<std::uint32_t> degrade_blend(GroupCommand command);
4962 void blend_point(const std::array<std::array<double, MaxAxes>, 6> &control,
4963 double u,
4964 std::array<double, MaxAxes> &out) const;
4965 double blend_curvature(
4966 const std::array<std::array<double, MaxAxes>, 6> &control,
4967 double u) const;
4968
4969 void clear_axes_synchronized()
4970 {
4971 for(std::size_t i = 0; i < axes_.size(); ++i) {
4972 axes_[i]->clear_synchronized();
4973 }
4974 }
4975
4976 GroupPoseFramesState pose_frames_{};
4977 double active_path_length_ = 0.0;
4978 double path_odometer_ = 0.0;
4979 double path_odometer_velocity_ = 0.0;
4980 double path_odometer_acceleration_ = 0.0;
4981 double path_sync_origin_ = 0.0;
4982 double path_sync_slave_origin_ = 0.0;
4983 double path_sync_ratio_ = 1.0;
4984 double path_sync_acceleration_ = 0.0;
4985 double path_sync_deceleration_ = 0.0;
4986 double path_sync_jerk_ = 0.0;
4987 double path_sync_velocity_ = 0.0;
4988 double path_sync_acceleration_state_ = 0.0;
4989 double tracking_master_origin_ = 0.0;
4990 std::int64_t active_tick_ = 0;
4991 std::int64_t active_duration_ = 1;
4992 double group_override_ = 1.0;
4993 double group_acc_override_ = 1.0;
4994 double group_jerk_override_ = 1.0;
4995 double interrupt_ratio_ = 0.0;
4996 double jog_stop_deceleration_ = 0.0;
4997 double jog_stop_jerk_ = 0.0;
4998 std::array<double, MaxAxes> active_start_{};
4999 std::array<double, MaxAxes> active_finish_{};
5000 std::array<double, MaxAxes> path_odometer_position_{};
5001 std::array<double, MaxAxes> path_odometer_member_velocity_{};
5002 std::array<double, SyncPathCapacity> group_sync_cumulative_{};
5003 std::array<GroupPosition, SyncPathCapacity> group_sync_waypoints_{};
5004 std::array<double, MaxAxes> jog_position_{};
5005 std::array<double, MaxAxes> jog_velocity_{};
5006 std::array<double, MaxAxes> jog_acceleration_{};
5007 std::array<double, 6> jog_cart_velocity_{};
5008 std::array<double, 6> jog_cart_acceleration_{};
5009 std::array<ToolData, ToolCapacity> tools_{};
5010 std::array<PayloadData, PayloadCapacity> payloads_{};
5011 std::array<bool, ToolCapacity> tool_defined_{{true}};
5012 std::array<bool, PayloadCapacity> payload_defined_{{true}};
5013 RigidBodyDynamics rigid_body_dynamics_{};
5014 bool rigid_body_dynamics_defined_ = false;
5015 // Cartesian look-ahead and Jog are mutually exclusive AxisGroup states;
5016 // overlay their submit-domain seed storage so Jog inputs do not enlarge
5017 // the already large fixed-capacity look-ahead object.
5018 union
5019 {
5022 };
5024 GroupLookaheadWindow<MaxAxes> joint_window_{};
5025 rt::StaticVector<AxisModel *, MaxAxes> axes_{};
5026 rt::StaticVector<IdentInGroup, MaxAxes> member_idents_{};
5027 AxisModel *path_sync_slave_ = nullptr;
5028 AxisModel *group_sync_master_ = nullptr;
5029 AxisModel *tracking_master_axis_ = nullptr;
5030 AxisGroup *tracking_master_group_ = nullptr;
5031 geom::ArcSegment active_arc_{};
5032 GroupCommand active_command_{};
5033 ToolData tracking_origin_{};
5034 ToolData tracking_transform_{};
5035 GroupPosition jog_direction_{};
5036 GroupPosition jog_cartesian_position_{};
5037 otg::Profile1D active_profile_{};
5038 rt::StaticVector<GroupCommand, QueueCapacity> queue_{};
5039 rt::StaticVector<GroupManagementResult, QueueCapacity> management_results_{};
5040 rt::StaticVector<std::uint32_t, QueueCapacity> aborted_management_ids_{};
5041 GroupCartesianState<MaxAxes> cartesian_{};
5042 int domain_id_ = 0;
5044 GroupPathKind active_kind_ = GroupPathKind::linear;
5045 CoordSystem jog_coord_system_ = CoordSystem::acs;
5046 rt::ErrorCode group_error_id_ = rt::ErrorCode::ok;
5047 rt::ErrorCode jog_error_ = rt::ErrorCode::ok;
5048 rt::ErrorCode tracking_error_ = rt::ErrorCode::ok;
5049 std::uint32_t last_blend_degraded_id_ = 0;
5050 std::uint32_t next_command_id_ = 1;
5051 std::uint32_t active_management_id_ = 0;
5052 GroupCommandKind active_management_kind_ = GroupCommandKind::motion;
5053 GroupDirectPathState direct_path_{};
5054 std::uint32_t jog_command_id_ = 0;
5055 std::uint32_t last_aborted_jog_id_ = 0;
5056 std::uint32_t path_sync_id_ = 0;
5057 std::uint32_t group_sync_id_ = 0;
5058 std::uint32_t last_aborted_group_sync_id_ = 0;
5059 std::uint32_t tracking_command_id_ = 0;
5060 std::uint32_t last_aborted_tracking_id_ = 0;
5061 std::uint32_t halt_command_id_ = 0;
5062 std::uint32_t last_completed_halt_id_ = 0;
5063 std::uint32_t last_aborted_halt_id_ = 0;
5064 std::uint32_t wait_command_id_ = 0;
5065 std::uint32_t last_aborted_wait_id_ = 0;
5066 std::int64_t wait_duration_cycles_ = 0;
5067 std::int64_t wait_elapsed_cycles_ = 0;
5068 std::int64_t task_cycle_period_ns_ = 1000000;
5069 std::size_t selected_tool_ = 0;
5070 std::size_t active_tool_ = 0;
5071 std::size_t selected_payload_ = 0;
5072 std::size_t active_payload_ = 0;
5073 std::size_t group_sync_count_ = 0;
5074 bool active_ = false;
5075 bool override_paused_ = false;
5076 bool interrupting_ = false;
5077 bool interrupted_plain_ = false;
5078 bool interrupted_window_ = false;
5079 bool numbered_tool_mode_ = false;
5080 bool jog_active_ = false;
5081 bool jog_releasing_ = false;
5082 bool path_odometer_initialized_ = false;
5083 bool path_sync_in_sync_ = false;
5084 bool group_sync_active_ = false;
5085 bool tracking_motion_seen_ = false;
5086 bool tracking_following_ = false;
5087 bool pending_dynamic_pcs_ = false;
5088 bool halt_command_live_ = false;
5089 double group_sync_master_origin_ = 0.0;
5090 // Group-to-axis synchronization is aborted before Jog acquires the group;
5091 // both states therefore share their fixed command scratch storage.
5092 union
5093 {
5096 };
5097 PathMode group_sync_mode_ = PathMode::non_periodic;
5098 TrackingKind tracking_kind_ = TrackingKind::none;
5100 GroupKinematicsInfo kinematics_info_{};
5101 PathDynamics reference_dynamics_{};
5102 PathDynamics default_dynamics_{};
5103 JoggingDynamics jogging_dynamics_{};
5104 DynamicsMode dynamics_mode_ = DynamicsMode::absolute;
5105 TransitionReferencePoint transition_reference_point_ =
5107 bool kinematics_info_bound_ = false;
5108 bool kinematics_info_frozen_ = false;
5109 bool pose_window_enabled_ = false;
5110 LinearPathMetric linear_path_metric_ = LinearPathMetric::max_axis;
5111};
5112
5113} // namespace plcopen::core::axis
5114
5117#include "axis/group_window_impl.h"
double jog_cartesian_start_[MaxAxes]
rt::ErrorCode set_workpiece_frame_rpy(double x, double y, double z, double roll, double pitch, double yaw)
rt::ErrorCode update_jog(std::uint32_t command_id, const GroupPosition &direction, const JogCommandOptions &options={})
const kin::PoseKinematics * pose_kinematics_plugin() const
LinearPathMetric linear_path_metric() const
rt::ErrorCode write_default_dynamics(const PathDynamics &update)
double cartesian_connector_tcp_tube() const
rt::ErrorCode write_rigid_body_dynamics(const RigidBodyDynamics &data)
rt::ErrorCode jog_error() const
bool contains(const AxisModel &axis) const
bool wait_command_aborted(std::uint32_t command_id) const
rt::Result< std::uint32_t > halt(double deceleration=1.0, double jerk=1.0, BufferMode buffer_mode=BufferMode::aborting)
rt::ErrorCode add_axis(AxisModel &axis, IdentInGroup ident)
rt::ErrorCode read_cartesian_twist(CoordSystem cs, PositionSource source, CartesianTwist &out) const
static constexpr std::size_t SyncPathCapacity
rt::ErrorCode set_cartesian_takeover_tcp_tube_limit(double max_tcp_tube)
const kin::Kinematics * kinematics_plugin() const
static constexpr std::size_t ToolCapacity
std::size_t member_index(const AxisModel &axis) const
rt::ErrorCode release_jog(std::uint32_t command_id)
rt::ErrorCode group_error() const
bool halt_command_aborted(std::uint32_t command_id) const
bool direct_command_active(std::uint32_t command_id) const
rt::ErrorCode interrupt(double deceleration=1.0, double jerk=1.0)
std::size_t read_tool(SelectionSource source) const
rt::ErrorCode set_workpiece_frame(double x, double y, double z, double rot_z)
rt::Result< std::uint32_t > submit_coordinate_transform(CoordSystem coordinate_system, const ToolData &transform, ExecutionMode execution_mode)
bool tracking_command_busy(std::uint32_t command_id) const
const AxisModel * member(std::size_t index) const
static constexpr std::size_t MaxAxes
rt::Result< ToolData > read_tool_data(std::size_t number) const
bool management_command_active(std::uint32_t command_id) const
const kin::TranslationPathDifferential * translation_path_differential() const
rt::Result< std::uint32_t > set_dynamic_coord_transform(AxisGroup &master, const ToolData &transform, CoordSystem coord_system, BufferMode buffer_mode)
rt::Result< std::uint32_t > submit_group_parameter(GroupParameter parameter, double value, ExecutionMode mode)
rt::ErrorCode set_group_override(double factor, double acc_factor=1.0, double jerk_factor=1.0)
rt::ErrorCode write_jogging_dynamics(const JoggingDynamics &update)
rt::ErrorCode set_kinematics(const kin::Kinematics *plugin, double min_singularity_margin=0.0)
rt::Result< std::uint32_t > sync_axis_to_group(AxisModel &slave, double ratio_numerator, double ratio_denominator, double acceleration, double deceleration, double jerk, BufferMode buffer_mode)
const JoggingDynamics & jogging_dynamics() const
rt::Result< std::uint32_t > track_conveyor(AxisModel &conveyor, const ToolData &origin, const ToolData &initial_object, CoordSystem coord_system, BufferMode buffer_mode)
rt::ErrorCode transform_position(const GroupPosition &position, CoordSystem source, CoordSystem target, GroupPosition &output, bool &singular_position) const
bool cartesian_connector_active() const
static constexpr std::size_t QueueCapacity
bool group_to_axis_sync_aborted(std::uint32_t command_id) const
bool wait_command_active(std::uint32_t command_id) const
AxisModel * member(IdentInGroup ident)
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)
rt::ErrorCode set_cartesian_velocity_limit(double limit)
bool halt_command_done(std::uint32_t command_id) const
const AxisModel * member(IdentInGroup ident) const
double path_derivative(bool acceleration) const
rt::ErrorCode remove_axis(AxisModel &axis)
rt::Result< GroupKinematicsInfo > kinematics_info() const
rt::ErrorCode set_coordinate_transform(CoordSystem coordinate_system, const ToolData &transform, ExecutionMode execution_mode)
bool direct_command_busy(std::uint32_t command_id) const
rt::ErrorCode read_cartesian_twist_from_joints(CoordSystem cs, const GroupPosition &joints, const GroupPosition &joint_velocities, CartesianTwist &out) const
bool jog_command_active(std::uint32_t command_id) const
rt::ErrorCode write_group_sw_limits(const GroupSWLimits &limits)
rt::ErrorCode set_pose_window_enabled(bool enabled)
bool direct_command_done(std::uint32_t command_id) const
bool direct_command_aborted(std::uint32_t command_id) const
GroupStatus status() const
std::size_t read_payload(SelectionSource source) const
static constexpr std::size_t RigidBodyCapacity
rt::Result< std::uint32_t > submit_group_home(const GroupPosition &position, CoordSystem coordinate_system, BufferMode buffer_mode)
rt::ErrorCode coordinate_transform(CoordSystem coordinate_system, ToolData &transform) const
rt::ErrorCode set_tool_offset(double x, double y, double z)
rt::Result< std::uint32_t > submit_group_sw_limits(const GroupSWLimits &limits, ExecutionMode mode)
rt::ErrorCode remove_axis(IdentInGroup ident)
bool tracking_command_active(std::uint32_t command_id) const
AxisGroup & operator=(AxisGroup &&)=delete
bool wait_command_busy(std::uint32_t command_id) const
void workpiece_frame_rpy(double out[6]) const
rt::ErrorCode set_window_depth(std::size_t depth)
rt::ErrorCode read_cartesian(CoordSystem cs, PositionSource source, GroupPosition &out, bool *gimbal_lock=nullptr) const
rt::ErrorCode set_group_power(bool enabled)
rt::Result< std::uint32_t > submit_linear(GroupCommand command)
AxisGroup(const AxisGroup &)=delete
rt::Result< GroupSiConfig > group_si_config(const rt::CycleConfig &cycle) const
std::uint32_t last_blend_degraded_command() const
rt::Result< std::uint32_t > track_rotary_table(AxisModel &rotary, const ToolData &origin, const ToolData &initial_object, CoordSystem coord_system, BufferMode buffer_mode)
IdentInGroup member_ident(const AxisModel &axis) const
rt::ErrorCode write_group_si_config(const GroupSiConfig &config)
rt::ErrorCode write_reference_dynamics(const PathDynamics &update)
rt::ErrorCode set_task_cycle_period_ns(std::int64_t period_ns)
rt::Result< std::uint32_t > begin_jog(CoordSystem coord_system, const GroupPosition &direction, const JogCommandOptions &options={})
rt::Result< std::uint32_t > submit_circular(GroupCommand command)
rt::ErrorCode set_pose_kinematics(const kin::PoseKinematics *plugin, double min_singularity_margin, double max_joint_step)
rt::ErrorCode write_payload_data(std::size_t number, const PayloadData &data)
rt::Result< double > read_group_parameter(GroupParameter parameter) const
static constexpr std::size_t PayloadCapacity
rt::ErrorCode last_cartesian_error() const
rt::Result< RigidBodyDynamics > rigid_body_dynamics() const
rt::Result< std::uint32_t > submit_direct(GroupCommand command)
bool tracking_command_aborted(std::uint32_t command_id) const
rt::ErrorCode write_group_parameter(GroupParameter parameter, double value)
const PathDynamics & default_dynamics() const
const PathDynamics & reference_dynamics() const
double connector_tube_radius() const
rt::ErrorCode write_tool_data(std::size_t number, const ToolData &data)
bool management_command_aborted(std::uint32_t command_id) const
std::int64_t task_cycle_period_ns() const
bool management_command_done(std::uint32_t command_id) const
rt::ErrorCode stop(double deceleration=1.0, double jerk=1.0)
rt::ErrorCode tracking_command_error(std::uint32_t command_id) const
rt::ErrorCode add_axis(AxisModel &axis)
rt::ErrorCode select_payload(std::size_t number)
rt::ErrorCode select_tool(std::size_t number)
AxisGroup & operator=(const AxisGroup &)=delete
rt::ErrorCode set_group_position(const GroupPosition &position, bool relative, CoordSystem coordinate_system, ExecutionMode execution_mode)
rt::Result< GroupSWLimits > group_sw_limits() const
static bool verify_profile_monotonic(const otg::Profile1D &p, double length)
rt::ErrorCode set_translation_path_differential(const kin::TranslationPathDifferential *differential)
bool wait_command_done(std::uint32_t command_id) const
rt::Result< PayloadData > read_payload_data(std::size_t number) const
AxisGroup(AxisGroup &&)=delete
rt::ErrorCode bind_kinematics_info(const GroupKinematicsInfo &info)
bool halt_command_active(std::uint32_t command_id) const
GroupMotionState motion_state() const
rt::Result< GroupCommandInfo > command_info(std::uint32_t command_id) const
bool group_to_axis_sync_active(std::uint32_t command_id) const
rt::Result< std::uint32_t > submit_wait(std::int64_t duration_ns, BufferMode buffer_mode)
rt::ErrorCode set_tool_transform_rpy(double x, double y, double z, double roll, double pitch, double yaw)
rt::Result< std::uint32_t > submit_tool_data(std::size_t number, const ToolData &data, ExecutionMode mode)
rt::Result< std::uint32_t > submit_kinematics(const KinTransformRef &kin_transform, double min_singularity_margin, double max_joint_step, ExecutionMode mode)
rt::ErrorCode set_linear_path_metric(LinearPathMetric metric)
bool jog_command_aborted(std::uint32_t command_id) const
std::size_t member_count() const
rt::ErrorCode management_command_error(std::uint32_t command_id) const
const AxisSnapshot & snapshot() const
static rt::Result< otg::Profile1D > plan_rest_base_profile(double path_length, const otg::Limits1D &limits)
static rt::Result< otg::Profile1D > plan_bounded_1d_profile(const otg::State1D &from, double target_pos, double path_length, const otg::Limits1D &limits, const otg::Limits1D *verify_limits=nullptr)
static constexpr CycleConfig at_1khz()
定义 units.h:17
static constexpr CycleTick from_cycles(std::int64_t cycles)
定义 cycle.h:42
constexpr const T & value() const
定义 error.h:49
constexpr ErrorCode error() const
定义 error.h:44
static constexpr Result success(const T &value)
定义 error.h:24
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
rt::Result< ArcSegment > make_arc_center_xy(Vec3 start, Vec3 center, Vec3 finish, bool counter_clockwise)
void rotation_multiply(const double a[3][3], const double b[3][3], double out[3][3])
Vec3 transform_point(const RigidTransform &transform, Vec3 p)
RigidTransform invert(const RigidTransform &transform)
Vec3 sample(LineSegment line, double arclength)
double norm(Vec3 value)
void rodrigues(const double axis[3], double angle, double out[3][3])
rt::Result< ArcSegment > make_arc_radius_xy(Vec3 start, Vec3 finish, double signed_radius, bool counter_clockwise)
rt::Result< ArcSegment > make_arc(Vec3 start, Vec3 via, Vec3 finish)
bool extract_rpy(const double rotation[3][3], double &roll, double &pitch, double &yaw)
double angle_of(Vec3 point, Vec3 center)
RigidTransform make_rpy_transform(double x, double y, double z, double roll, double pitch, double yaw)
定义 frame.h:71
double normalize_sweep(double sweep, double orientation)
void relative_axis_angle(const double a[3][3], const double b[3][3], double axis[3], double &angle)
RigidTransform compose(const RigidTransform &a, const RigidTransform &b)
RampTiming ramp_between(double va, double vb, const Limits1D &limits)
rt::Result< Profile1D > plan_time_optimal(State1D from, Target1D to, Limits1D limits)
State1D sample(const Profile1D &profile, rt::CycleTick tick)
std::array< DHParameter, GroupPosition::MaxAxes > value
定义 group.h:55
geom::RigidTransform tool_inverse
InterpolationSpace interpolation_space
std::array< DHParameter, GroupPosition::MaxAxes > dh
定义 group.h:67
std::array< JointInfo, GroupPosition::MaxAxes > joint
定义 group.h:68
std::array< double, MaxAxes > value
定义 group.h:30
static constexpr std::size_t MaxAxes
定义 group.h:29
std::array< AxisSiConfig, GroupPosition::MaxAxes > value
std::array< double, GroupPosition::MaxAxes > axis_acceleration
std::array< double, GroupPosition::MaxAxes > axis_velocity
std::array< double, GroupPosition::MaxAxes > axis_jerk
std::array< double, GroupPosition::MaxAxes > axis_deceleration
const kin::Kinematics * kinematics
const kin::PoseKinematics * pose
std::array< RigidBodyDynamic, GroupPosition::MaxAxes+1 > value
std::array< double, 6 > value