43 CbMoveJoints(
const std::map<std::string, double> & jointValueTarget)
53 moveit::planning_interface::MoveGroupInterface move_group(
54 getNode(), moveit::planning_interface::MoveGroupInterface::Options(*(this->group_)));
67 moveit::planning_interface::MoveGroupInterface & moveGroupInterface,
68 std::map<std::string, double> & targetJoints)
70 auto state = moveGroupInterface.getCurrentState();
72 if (state ==
nullptr)
return std::string();
74 auto vnames = state->getVariableNames();
78 for (
auto & tgj : targetJoints)
80 auto it = std::find(vnames.begin(), vnames.end(), tgj.first);
81 auto index = std::distance(vnames.begin(), it);
83 ss << tgj.first <<
":" << state->getVariablePosition(index) << std::endl;
89 void moveJoints(moveit::planning_interface::MoveGroupInterface & moveGroupInterface)
93 RCLCPP_WARN(
getLogger(),
"[CbMoveJoints] No joint value specified. Skipping planning call.");
101 bool success =
false;
102 moveit::planning_interface::MoveGroupInterface::Plan computedMotionPlan;
104 if (motionPlanner !=
nullptr)
107 RCLCPP_INFO(
getLogger(),
"[CbMoveJoints] Using CpMotionPlanner component for joint planning");
117 success = result.success;
120 computedMotionPlan = result.plan;
121 RCLCPP_INFO(
getLogger(),
"[CbMoveJoints] Planning succeeded (via CpMotionPlanner)");
126 getLogger(),
"[CbMoveJoints] Planning failed (via CpMotionPlanner): %s",
127 result.errorMessage.c_str());
135 "[CbMoveJoints] CpMotionPlanner component not available, using legacy planning "
136 "(consider adding CpMotionPlanner component)");
142 auto result = moveGroupInterface.plan(computedMotionPlan);
144 success = (result == moveit::core::MoveItErrorCode::SUCCESS);
147 getLogger(),
"[CbMoveJoints] Planning %s (legacy mode, code: %d)",
148 success ?
"SUCCESS" :
"FAILED", result.val);
157 bool executionSuccess =
false;
159 if (trajectoryExecutor !=
nullptr)
163 getLogger(),
"[CbMoveJoints] Using CpTrajectoryExecutor component for execution");
172 auto execResult = trajectoryExecutor->
executePlan(computedMotionPlan, execOptions);
173 executionSuccess = execResult.success;
175 if (executionSuccess)
177 RCLCPP_INFO(
getLogger(),
"[CbMoveJoints] Execution succeeded (via CpTrajectoryExecutor)");
182 getLogger(),
"[CbMoveJoints] Execution failed (via CpTrajectoryExecutor): %s",
183 execResult.errorMessage.c_str());
191 "[CbMoveJoints] CpTrajectoryExecutor component not available, using legacy execution "
192 "(consider adding CpTrajectoryExecutor component)");
194 auto executionResult = moveGroupInterface.execute(computedMotionPlan);
195 executionSuccess = (executionResult == moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
198 getLogger(),
"[CbMoveJoints] Execution %s (legacy mode)",
199 executionSuccess ?
"succeeded" :
"failed");
203 if (executionSuccess)
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_
CpTrajectoryExecutor * cpTrajectoryExecutor_
CpMotionPlanner * cpMotionPlanner_
CpMoveGroupInterface * cpMoveGroup_
Component for centralized motion planning operations.
PlanningResult planToJointTarget(const std::map< std::string, double > &jointTargets, const PlanningOptions &options={})
Plan to joint values.
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
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
Configuration options for trajectory execution.
std::optional< double > maxVelocityScaling
std::optional< std::string > trajectoryName
Configuration options for motion planning.
std::optional< double > maxVelocityScaling