|
72 | 72 | #include <moveit/robot_trajectory/robot_trajectory.h> |
73 | 73 | #include <tf2_geometry_msgs/tf2_geometry_msgs.hpp> |
74 | 74 |
|
| 75 | +#include "ros2srrc_execution/trajectory_sender.hpp" |
| 76 | + |
75 | 77 | // Declaration of GLOBAL VARIABLES --> ROBOT / END-EFFECTOR / ENVIRONMENT PARAMETERS: |
76 | 78 | std::string param_ROB = "none"; |
77 | 79 | std::string param_EE = "none"; |
78 | 80 | std::string param_ENV = "none"; |
79 | 81 | std::string param_ROB_GROUP = "none"; |
| 82 | +bool sync_real_robot = false; |
80 | 83 |
|
81 | 84 | // Declaration of GLOBAL VARIABLES --> MoveIt!2 Interface: |
82 | 85 | moveit::planning_interface::MoveGroupInterface move_group_interface_ROB; |
83 | 86 | moveit::planning_interface::MoveGroupInterface move_group_interface_EE; |
84 | 87 |
|
| 88 | +std::shared_ptr<TrajectorySender> trajectory_sender; |
| 89 | + |
85 | 90 | // Declaration of GLOBAL VARIABLES --> JointModelGroup: |
86 | 91 | const moveit::core::JointModelGroup* joint_model_group_ROB; |
87 | 92 | const moveit::core::JointModelGroup* joint_model_group_EE; |
@@ -114,6 +119,17 @@ class ros2_RobotParam : public rclcpp::Node |
114 | 119 | RCLCPP_INFO(this->get_logger(), |
115 | 120 | "ROB_GROUP received -> %s", |
116 | 121 | param_ROB_GROUP.c_str()); |
| 122 | + |
| 123 | + this->declare_parameter("SYNC_REAL_ROBOT", false); |
| 124 | + |
| 125 | + sync_real_robot = |
| 126 | + this->get_parameter("SYNC_REAL_ROBOT").as_bool(); |
| 127 | + |
| 128 | + RCLCPP_INFO( |
| 129 | + this->get_logger(), |
| 130 | + "SYNC_REAL_ROBOT -> %s", |
| 131 | + sync_real_robot ? "true" : "false" |
| 132 | + ); |
117 | 133 | } |
118 | 134 | private: |
119 | 135 | }; |
@@ -432,6 +448,13 @@ class ActionServer : public rclcpp::Node |
432 | 448 |
|
433 | 449 | rt.getRobotTrajectoryMsg(MyPlan.trajectory_); |
434 | 450 |
|
| 451 | + if (sync_real_robot) |
| 452 | + { |
| 453 | + trajectory_sender->send( |
| 454 | + MyPlan.trajectory_.joint_trajectory |
| 455 | + ); |
| 456 | + } |
| 457 | + |
435 | 458 | bool ExecSUCCESS = (move_group_interface_ROB.execute(MyPlan) == moveit::planning_interface::MoveItErrorCode::SUCCESS); |
436 | 459 |
|
437 | 460 | if (goal_handle->is_canceling()) { |
@@ -543,6 +566,8 @@ int main(int argc, char ** argv) |
543 | 566 | .automatically_declare_parameters_from_overrides(true) |
544 | 567 | ); |
545 | 568 |
|
| 569 | + trajectory_sender = std::make_shared<TrajectorySender>(node2); |
| 570 | + |
546 | 571 | rclcpp::executors::SingleThreadedExecutor executor; |
547 | 572 | executor.add_node(node2); |
548 | 573 | std::thread([&executor]() { executor.spin(); }).detach(); |
|
0 commit comments