45 CbMoveJoints(
const std::map<std::string, double> & jointValueTarget)
56 moveit::planning_interface::MoveGroupInterface move_group(
57 getNode(), moveit::planning_interface::MoveGroupInterface::Options(*(this->group_)));
70 moveit::planning_interface::MoveGroupInterface & moveGroupInterface,
71 std::map<std::string, double> & targetJoints)
73 auto state = moveGroupInterface.getCurrentState();
75 if (state ==
nullptr)
return std::string();
77 auto vnames = state->getVariableNames();
81 for (
auto & tgj : targetJoints)
83 auto it = std::find(vnames.begin(), vnames.end(), tgj.first);
84 auto index = std::distance(vnames.begin(), it);
86 ss << tgj.first <<
":" << state->getVariablePosition(index) << std::endl;
92 void moveJoints(moveit::planning_interface::MoveGroupInterface & moveGroupInterface)
96 RCLCPP_WARN(
getLogger(),
"[CbMoveJoints] No joint value specified. Skipping planning call.");
107 bool success =
false;
108 moveit::planning_interface::MoveGroupInterface::Plan computedMotionPlan;
110 if (motionPlanner !=
nullptr)
113 RCLCPP_INFO(
getLogger(),
"[CbMoveJoints] Using CpMotionPlanner component for joint planning");
123 success = result.success;
126 computedMotionPlan = result.plan;
127 RCLCPP_INFO(
getLogger(),
"[CbMoveJoints] Planning succeeded (via CpMotionPlanner)");
132 getLogger(),
"[CbMoveJoints] Planning failed (via CpMotionPlanner): %s",
133 result.errorMessage.c_str());
141 "[CbMoveJoints] CpMotionPlanner component not available, using legacy planning "
142 "(consider adding CpMotionPlanner component)");
148 auto result = moveGroupInterface.plan(computedMotionPlan);
150 success = (result == moveit::core::MoveItErrorCode::SUCCESS);
153 getLogger(),
"[CbMoveJoints] Planning %s (legacy mode, code: %d)",
154 success ?
"SUCCESS" :
"FAILED", result.val);
165 bool executionSuccess =
false;
167 if (trajectoryExecutor !=
nullptr)
171 getLogger(),
"[CbMoveJoints] Using CpTrajectoryExecutor component for execution");
180 auto execResult = trajectoryExecutor->
executePlan(computedMotionPlan, execOptions);
181 executionSuccess = execResult.success;
183 if (executionSuccess)
185 RCLCPP_INFO(
getLogger(),
"[CbMoveJoints] Execution succeeded (via CpTrajectoryExecutor)");
190 getLogger(),
"[CbMoveJoints] Execution failed (via CpTrajectoryExecutor): %s",
191 execResult.errorMessage.c_str());
199 "[CbMoveJoints] CpTrajectoryExecutor component not available, using legacy execution "
200 "(consider adding CpTrajectoryExecutor component)");
202 auto executionResult = moveGroupInterface.execute(computedMotionPlan);
203 executionSuccess = (executionResult == moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
206 getLogger(),
"[CbMoveJoints] Execution %s (legacy mode)",
207 executionSuccess ?
"succeeded" :
"failed");
211 if (executionSuccess)
215 "[" << this->
getName() <<
"] motion execution succeeded. Throwing success event.");
222 getLogger(),
"[" << this->
getName() <<
"] motion execution failed. Throwing fail event.");
231 getLogger(),
"[" << this->
getName() <<
"] planning failed. Throwing fail event."
ClMoveit2z * movegroupClient_
virtual void onEntry() override
static std::string currentJointStatesToString(moveit::planning_interface::MoveGroupInterface &moveGroupInterface, std::map< std::string, double > &targetJoints)
CbMoveJoints(const std::map< std::string, double > &jointValueTarget)
std::map< std::string, double > jointValueTarget_
void moveJoints(moveit::planning_interface::MoveGroupInterface &moveGroupInterface)
virtual void onExit() override
std::optional< double > scalingFactor_
std::optional< std::string > group_
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
void postEventMotionExecutionFailed()
void postEventMotionExecutionSucceded()
Component for centralized motion planning operations.
PlanningResult planToJointTarget(const std::map< std::string, double > &jointTargets, const PlanningOptions &options={})
Plan to joint values.
Component for centralized trajectory execution.
ExecutionResult executePlan(const moveit::planning_interface::MoveGroupInterface::Plan &plan, const ExecutionOptions &options={})
Execute a motion plan synchronously.
std::string getName() const
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
void requiresClient(SmaccClientType *&storage)
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
Configuration options for trajectory execution.
std::optional< double > maxVelocityScaling
std::optional< std::string > trajectoryName
Configuration options for motion planning.
std::optional< double > maxVelocityScaling