46 CbMoveJoints(
const std::map<std::string, double> & jointValueTarget)
57 moveit::planning_interface::MoveGroupInterface move_group(
58 getNode(), moveit::planning_interface::MoveGroupInterface::Options(*(this->group_)));
71 moveit::planning_interface::MoveGroupInterface & moveGroupInterface,
72 std::map<std::string, double> & targetJoints)
74 auto state = moveGroupInterface.getCurrentState();
76 if (state ==
nullptr)
return std::string();
78 auto vnames = state->getVariableNames();
82 for (
auto & tgj : targetJoints)
84 auto it = std::find(vnames.begin(), vnames.end(), tgj.first);
85 auto index = std::distance(vnames.begin(), it);
87 ss << tgj.first <<
":" << state->getVariablePosition(index) << std::endl;
93 void moveJoints(moveit::planning_interface::MoveGroupInterface & moveGroupInterface)
97 RCLCPP_WARN(
getLogger(),
"[CbMoveJoints] No joint value specified. Skipping planning call.");
108 bool success =
false;
109 moveit::planning_interface::MoveGroupInterface::Plan computedMotionPlan;
111 if (motionPlanner !=
nullptr)
114 RCLCPP_INFO(
getLogger(),
"[CbMoveJoints] Using CpMotionPlanner component for joint planning");
124 success = result.success;
127 computedMotionPlan = result.plan;
128 RCLCPP_INFO(
getLogger(),
"[CbMoveJoints] Planning succeeded (via CpMotionPlanner)");
133 getLogger(),
"[CbMoveJoints] Planning failed (via CpMotionPlanner): %s",
134 result.errorMessage.c_str());
142 "[CbMoveJoints] CpMotionPlanner component not available, using legacy planning "
143 "(consider adding CpMotionPlanner component)");
149 auto result = moveGroupInterface.plan(computedMotionPlan);
151 success = (result == moveit::core::MoveItErrorCode::SUCCESS);
154 getLogger(),
"[CbMoveJoints] Planning %s (legacy mode, code: %d)",
155 success ?
"SUCCESS" :
"FAILED", result.val);
166 bool executionSuccess =
false;
168 if (trajectoryExecutor !=
nullptr)
172 getLogger(),
"[CbMoveJoints] Using CpTrajectoryExecutor component for execution");
181 auto execResult = trajectoryExecutor->
executePlan(computedMotionPlan, execOptions);
182 executionSuccess = execResult.success;
184 if (executionSuccess)
186 RCLCPP_INFO(
getLogger(),
"[CbMoveJoints] Execution succeeded (via CpTrajectoryExecutor)");
191 getLogger(),
"[CbMoveJoints] Execution failed (via CpTrajectoryExecutor): %s",
192 execResult.errorMessage.c_str());
200 "[CbMoveJoints] CpTrajectoryExecutor component not available, using legacy execution "
201 "(consider adding CpTrajectoryExecutor component)");
203 auto executionResult = moveGroupInterface.execute(computedMotionPlan);
204 executionSuccess = (executionResult == moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
207 getLogger(),
"[CbMoveJoints] Execution %s (legacy mode)",
208 executionSuccess ?
"succeeded" :
"failed");
212 if (executionSuccess)
216 "[" << this->
getName() <<
"] motion execution succeeded. Throwing success event.");
223 getLogger(),
"[" << this->
getName() <<
"] motion execution failed. Throwing fail event.");
232 getLogger(),
"[" << this->
getName() <<
"] planning failed. Throwing fail event."
virtual void onEntry() override
static std::string currentJointStatesToString(moveit::planning_interface::MoveGroupInterface &moveGroupInterface, std::map< std::string, double > &targetJoints)
CpMoveGroupInterface * cpMoveGroup_
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_
Component for centralized motion planning operations.
PlanningResult planToJointTarget(const std::map< std::string, double > &jointTargets, const PlanningOptions &options={})
Plan to joint values.
void postEventMotionExecutionFailed()
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
void postEventMotionExecutionSucceeded()
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 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