88 const planning_scene_monitor::CurrentStateMonitorPtr& csm);
92 const planning_scene_monitor::CurrentStateMonitorPtr& csm,
bool manage_controllers);
98 bool isManagingControllers()
const;
101 const moveit_controller_manager::MoveItControllerManagerPtr& getControllerManager()
const;
104 void processEvent(
const std::string& event);
110 bool ensureActiveControllersForGroup(
const std::string& group);
116 bool ensureActiveControllersForJoints(
const std::vector<std::string>& joints);
121 bool ensureActiveController(
const std::string& controller);
126 bool ensureActiveControllers(
const std::vector<std::string>& controllers);
129 bool isControllerActive(
const std::string& controller);
132 bool areControllersActive(
const std::vector<std::string>& controllers);
136 bool push(
const moveit_msgs::msg::RobotTrajectory& trajectory,
const std::string& controller =
"");
140 bool push(
const trajectory_msgs::msg::JointTrajectory& trajectory,
const std::string& controller =
"");
147 bool push(
const trajectory_msgs::msg::JointTrajectory& trajectory,
const std::vector<std::string>& controllers);
154 bool push(
const moveit_msgs::msg::RobotTrajectory& trajectory,
const std::vector<std::string>& controllers);
157 const std::vector<TrajectoryExecutionContext*>& getTrajectories()
const;
165 bool auto_clear =
true);
181 std::pair<int, int> getCurrentExpectedTrajectoryIndex()
const;
187 void stopExecution(
bool auto_clear =
true);
194 void enableExecutionDurationMonitoring(
bool flag);
197 bool executionDurationMonitoring()
const;
201 void setAllowedExecutionDurationScaling(
double scaling);
204 double allowedExecutionDurationScaling()
const;
208 void setAllowedGoalDurationMargin(
double margin);
211 double allowedGoalDurationMargin()
const;
215 void setExecutionVelocityScaling(
double scaling);
218 double executionVelocityScaling()
const;
221 void setAllowedStartTolerance(
double tolerance);
224 double allowedStartTolerance()
const;
227 void setWaitForTrajectoryCompletion(
bool flag);
230 bool waitForTrajectoryCompletion()
const;
234 return controller_mgr_node_;
238 struct ControllerInformation
241 std::set<std::string> joints_;
242 std::set<std::string> overlapping_controllers_;
244 rclcpp::Time last_update_{ 0, 0, RCL_ROS_TIME };
246 bool operator<(ControllerInformation& other)
const
248 if (joints_.size() != other.joints_.size())
249 return joints_.size() < other.joints_.size();
250 return name_ < other.name_;
256 void reloadControllerInformation();
259 bool validate(
const TrajectoryExecutionContext& context)
const;
260 bool configure(TrajectoryExecutionContext& context,
const moveit_msgs::msg::RobotTrajectory& trajectory,
261 const std::vector<std::string>& controllers);
263 void updateControllersState(
const rclcpp::Duration& age);
264 void updateControllerState(
const std::string& controller,
const rclcpp::Duration& age);
265 void updateControllerState(ControllerInformation& ci,
const rclcpp::Duration& age);
267 bool distributeTrajectory(
const moveit_msgs::msg::RobotTrajectory& trajectory,
268 const std::vector<std::string>& controllers,
269 std::vector<moveit_msgs::msg::RobotTrajectory>& parts);
271 bool findControllers(
const std::set<std::string>& actuated_joints, std::size_t controller_count,
272 const std::vector<std::string>& available_controllers,
273 std::vector<std::string>& selected_controllers);
274 bool checkControllerCombination(std::vector<std::string>& controllers,
const std::set<std::string>& actuated_joints);
275 void generateControllerCombination(std::size_t start_index, std::size_t controller_count,
276 const std::vector<std::string>& available_controllers,
277 std::vector<std::string>& selected_controllers,
279 const std::set<std::string>& actuated_joints);
280 bool selectControllers(
const std::set<std::string>& actuated_joints,
281 const std::vector<std::string>& available_controllers,
282 std::vector<std::string>& selected_controllers);
284 void executeThread(
const ExecutionCompleteCallback& callback,
const PathSegmentCompleteCallback& part_callback,
286 bool executePart(std::size_t part_index);
287 bool waitForRobotToStop(
const TrajectoryExecutionContext& context,
double wait_time = 1.0);
289 void stopExecutionInternal();
291 void receiveEvent(
const std_msgs::msg::String::ConstSharedPtr& event);
293 void loadControllerParams();
296 const std::string name_ =
"trajectory_execution_manager";
298 rclcpp::Node::SharedPtr node_;
299 rclcpp::Logger logger_;
300 rclcpp::Node::SharedPtr controller_mgr_node_;
301 std::shared_ptr<rclcpp::executors::SingleThreadedExecutor> private_executor_;
302 std::thread private_executor_thread_;
303 moveit::core::RobotModelConstPtr robot_model_;
304 planning_scene_monitor::CurrentStateMonitorPtr csm_;
305 rclcpp::Subscription<std_msgs::msg::String>::SharedPtr event_topic_subscriber_;
306 std::map<std::string, ControllerInformation> known_controllers_;
307 bool manage_controllers_;
310 std::unique_ptr<std::thread> execution_thread_;
312 std::mutex execution_state_mutex_;
313 std::mutex execution_thread_mutex_;
316 std::condition_variable execution_complete_condition_;
319 std::vector<moveit_controller_manager::MoveItControllerHandlePtr> active_handles_;
320 int current_context_;
321 std::vector<rclcpp::Time> time_index_;
322 mutable std::mutex time_index_mutex_;
323 bool execution_complete_;
325 std::vector<TrajectoryExecutionContext*> trajectories_;
327 std::unique_ptr<pluginlib::ClassLoader<moveit_controller_manager::MoveItControllerManager> > controller_manager_loader_;
328 moveit_controller_manager::MoveItControllerManagerPtr controller_manager_;
332 bool execution_duration_monitoring_;
334 double allowed_execution_duration_scaling_;
335 double allowed_goal_duration_margin_;
336 bool control_multi_dof_joint_variables_;
339 std::map<std::string, double> controller_allowed_execution_duration_scaling_;
340 std::map<std::string, double> controller_allowed_goal_duration_margin_;
342 double allowed_start_tolerance_;
343 double execution_velocity_scaling_;
344 bool wait_for_trajectory_completion_;
346 rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr callback_handler_;