28#include <moveit/move_group_interface/move_group_interface.h>
29#include <moveit_msgs/msg/move_it_error_codes.hpp>
30#include <moveit_msgs/msg/robot_trajectory.hpp>
61 errorCode.val = moveit_msgs::msg::MoveItErrorCodes::FAILURE;
96 "[CpTrajectoryExecutor] Component initialized with trajectory history recording enabled");
102 "[CpTrajectoryExecutor] Component initialized without CpTrajectoryHistory "
103 "(trajectory history will not be recorded)");
115 const moveit_msgs::msg::RobotTrajectory & trajectory,
const ExecutionOptions & options = {})
121 result.
errorMessage =
"ClMoveit2z client not available";
134 getLogger(),
"[CpTrajectoryExecutor] Executing trajectory with %lu points...",
135 trajectory.joint_trajectory.points.size());
138 auto startTime = std::chrono::steady_clock::now();
141 result.
errorCode = moveGroup->execute(trajectory);
143 auto endTime = std::chrono::steady_clock::now();
144 result.
executionTime = std::chrono::duration<double>(endTime - startTime);
146 result.
success = (result.
errorCode.val == moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
151 getLogger(),
"[CpTrajectoryExecutor] Trajectory execution succeeded (%.2f seconds)",
157 "Trajectory execution failed with error code: " + std::to_string(result.
errorCode.val);
164 std::string trajName = options.trajectoryName.value_or(
"unnamed_trajectory");
168 catch (
const std::exception & e)
171 result.
errorMessage = std::string(
"Exception during trajectory execution: ") + e.what();
188 const moveit::planning_interface::MoveGroupInterface::Plan & plan,
191 return execute(plan.trajectory_, options);
203 RCLCPP_ERROR(
getLogger(),
"[CpTrajectoryExecutor] Cannot cancel: client not available");
212 RCLCPP_INFO(
getLogger(),
"[CpTrajectoryExecutor] Trajectory execution cancelled");
214 catch (
const std::exception & e)
217 getLogger(),
"[CpTrajectoryExecutor] Exception during cancellation: %s", e.what());
239 moveit::planning_interface::MoveGroupInterface & moveGroup,
const ExecutionOptions & options)
260 const moveit_msgs::msg::RobotTrajectory & trajectory,
261 const moveit_msgs::msg::MoveItErrorCodes & errorCode,
const std::string & name)
272 getLogger(),
"[CpTrajectoryExecutor] Recorded trajectory '%s' to history", name.c_str());
274 catch (
const std::exception & e)
277 getLogger(),
"[CpTrajectoryExecutor] Failed to record trajectory to history: %s", e.what());
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
Component for centralized trajectory execution.
ExecutionResult execute(const moveit_msgs::msg::RobotTrajectory &trajectory, const ExecutionOptions &options={})
Execute a trajectory synchronously.
CpTrajectoryHistory * getTrajectoryHistory()
Get the trajectory history component.
CpTrajectoryExecutor()=default
ClMoveit2z * moveit2zClient_
virtual ~CpTrajectoryExecutor()=default
void recordToHistory(const moveit_msgs::msg::RobotTrajectory &trajectory, const moveit_msgs::msg::MoveItErrorCodes &errorCode, const std::string &name)
Record trajectory to history component.
void applyExecutionOptions(moveit::planning_interface::MoveGroupInterface &moveGroup, const ExecutionOptions &options)
Apply execution options to MoveGroupInterface.
void cancel()
Cancel ongoing execution.
void onInitialize() override
Initialize the component and get references to required components/clients.
ExecutionResult executePlan(const moveit::planning_interface::MoveGroupInterface::Plan &plan, const ExecutionOptions &options={})
Execute a motion plan synchronously.
CpTrajectoryHistory * trajectoryHistory_
void pushTrajectory(std::string name, const moveit_msgs::msg::RobotTrajectory &trajectory, moveit_msgs::msg::MoveItErrorCodes result)
void requiresClient(TClient *&requiredClientStorage)
rclcpp::Logger getLogger() const
void requiresComponent(TComponent *&requiredComponentStorage, bool throwExceptionIfNotExist)
Configuration options for trajectory execution.
std::optional< double > maxVelocityScaling
std::optional< double > maxAccelerationScaling
std::optional< std::string > trajectoryName
Result of a trajectory execution operation.
std::chrono::duration< double > executionTime
moveit_msgs::msg::MoveItErrorCodes errorCode