SMACC2
Loading...
Searching...
No Matches
cl_moveit2z::CpMotionPlanner Class Reference

Component for centralized motion planning operations. More...

#include <cp_motion_planner.hpp>

Inheritance diagram for cl_moveit2z::CpMotionPlanner:
Inheritance graph
Collaboration diagram for cl_moveit2z::CpMotionPlanner:
Collaboration graph

Public Member Functions

 CpMotionPlanner ()=default
 
virtual ~CpMotionPlanner ()=default
 
void onInitialize () override
 Initialize the component and get reference to ClMoveit2z client.
 
PlanningResult planToPose (const geometry_msgs::msg::PoseStamped &target, const std::optional< std::string > &tipLink=std::nullopt, const PlanningOptions &options={})
 Plan to a Cartesian pose.
 
PlanningResult planToJointTarget (const std::map< std::string, double > &jointTargets, const PlanningOptions &options={})
 Plan to joint values.
 
PlanningResult planCartesianPath (const std::vector< geometry_msgs::msg::Pose > &waypoints, double maxStep=0.01, double jumpThreshold=0.0, bool avoidCollisions=true)
 Plan a Cartesian path.
 
moveit::core::RobotStatePtr getCurrentState (double waitTime=1.0)
 Get current robot state.
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
virtual std::string getName () const
 

Private Member Functions

void applyPlanningOptions (moveit::planning_interface::MoveGroupInterface &moveGroup, const PlanningOptions &options)
 Apply planning options to MoveGroupInterface.
 

Private Attributes

ClMoveit2zmoveit2zClient_ = nullptr
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::ISmaccComponent
template<typename TOrthogonal , typename TClient >
void onComponentInitialization ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onOrthogonalAllocation ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, bool throwExceptionIfNotExist)
 
template<typename TComponent >
void requiresComponent (std::string name, TComponent *&requiredComponentStorage, bool throwExceptionIfNotExist)
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TComponent >
void requiresComponent (std::string name, TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (TArgs... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (std::string name, TArgs... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachinegetStateMachine ()
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachinestateMachine_
 
ISmaccClientowner_
 

Detailed Description

Component for centralized motion planning operations.

This component wraps all MoveGroupInterface planning operations to provide a consistent interface for planning motions. It supports planning to:

  • Cartesian poses
  • Joint configurations
  • Named targets
  • Cartesian paths

Pattern: API wrapper component with result types

Definition at line 79 of file cp_motion_planner.hpp.

Constructor & Destructor Documentation

◆ CpMotionPlanner()

cl_moveit2z::CpMotionPlanner::CpMotionPlanner ( )
default

◆ ~CpMotionPlanner()

virtual cl_moveit2z::CpMotionPlanner::~CpMotionPlanner ( )
virtualdefault

Member Function Documentation

◆ applyPlanningOptions()

void cl_moveit2z::CpMotionPlanner::applyPlanningOptions ( moveit::planning_interface::MoveGroupInterface & moveGroup,
const PlanningOptions & options )
inlineprivate

Apply planning options to MoveGroupInterface.

Parameters
moveGroupReference to MoveGroupInterface
optionsPlanning options to apply

Definition at line 341 of file cp_motion_planner.hpp.

343 {
344 if (options.planningTime)
345 {
346 moveGroup.setPlanningTime(*options.planningTime);
347 }
348
349 if (options.maxVelocityScaling)
350 {
351 moveGroup.setMaxVelocityScalingFactor(*options.maxVelocityScaling);
352 }
353
354 if (options.maxAccelerationScaling)
355 {
356 moveGroup.setMaxAccelerationScalingFactor(*options.maxAccelerationScaling);
357 }
358
359 if (options.planningPipelineId)
360 {
361 moveGroup.setPlanningPipelineId(*options.planningPipelineId);
362 }
363
364 if (options.plannerId)
365 {
366 moveGroup.setPlannerId(*options.plannerId);
367 }
368 }

References cl_moveit2z::PlanningOptions::maxAccelerationScaling, cl_moveit2z::PlanningOptions::maxVelocityScaling, cl_moveit2z::PlanningOptions::plannerId, cl_moveit2z::PlanningOptions::planningPipelineId, and cl_moveit2z::PlanningOptions::planningTime.

◆ getCurrentState()

moveit::core::RobotStatePtr cl_moveit2z::CpMotionPlanner::getCurrentState ( double waitTime = 1.0)
inline

Get current robot state.

Parameters
waitTimeMaximum time to wait for state (seconds)
Returns
Pointer to current robot state, or nullptr if unavailable

Definition at line 311 of file cp_motion_planner.hpp.

312 {
313 if (!moveit2zClient_)
314 {
315 RCLCPP_ERROR(getLogger(), "[CpMotionPlanner] ClMoveit2z client not available");
316 return nullptr;
317 }
318
319 auto & moveGroup = moveit2zClient_->moveGroupClientInterface;
320
321 try
322 {
323 return moveGroup->getCurrentState(waitTime);
324 }
325 catch (const std::exception & e)
326 {
327 RCLCPP_ERROR(getLogger(), "[CpMotionPlanner] Exception getting current state: %s", e.what());
328 return nullptr;
329 }
330 }
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
rclcpp::Logger getLogger() const

References smacc2::ISmaccComponent::getLogger(), cl_moveit2z::ClMoveit2z::moveGroupClientInterface, and moveit2zClient_.

Here is the call graph for this function:

◆ onInitialize()

void cl_moveit2z::CpMotionPlanner::onInitialize ( )
inlineoverridevirtual

Initialize the component and get reference to ClMoveit2z client.

Reimplemented from smacc2::ISmaccComponent.

Definition at line 88 of file cp_motion_planner.hpp.

89 {
91 RCLCPP_INFO(getLogger(), "[CpMotionPlanner] Component initialized");
92 }
void requiresClient(TClient *&requiredClientStorage)

References smacc2::ISmaccComponent::getLogger(), moveit2zClient_, and smacc2::ISmaccComponent::requiresClient().

Here is the call graph for this function:

◆ planCartesianPath()

PlanningResult cl_moveit2z::CpMotionPlanner::planCartesianPath ( const std::vector< geometry_msgs::msg::Pose > & waypoints,
double maxStep = 0.01,
double jumpThreshold = 0.0,
bool avoidCollisions = true )
inline

Plan a Cartesian path.

Parameters
waypointsVector of waypoint poses
maxStepMaximum distance between path points (meters)
jumpThresholdMaximum joint jump threshold (0.0 = disabled)
avoidCollisionsWhether to check for collisions
Returns
PlanningResult with success status and computed trajectory

Definition at line 243 of file cp_motion_planner.hpp.

246 {
247 PlanningResult result;
248
249 if (!moveit2zClient_)
250 {
251 result.errorMessage = "ClMoveit2z client not available";
252 RCLCPP_ERROR(getLogger(), "[CpMotionPlanner] %s", result.errorMessage.c_str());
253 return result;
254 }
255
256 if (waypoints.empty())
257 {
258 result.errorMessage = "No waypoints specified";
259 RCLCPP_WARN(getLogger(), "[CpMotionPlanner] %s", result.errorMessage.c_str());
260 return result;
261 }
262
263 auto & moveGroup = moveit2zClient_->moveGroupClientInterface;
264
265 try
266 {
267 RCLCPP_INFO(
268 getLogger(), "[CpMotionPlanner] Planning Cartesian path with %lu waypoints...",
269 waypoints.size());
270
271 moveit_msgs::msg::RobotTrajectory trajectory;
272 double fractionAchieved = moveGroup->computeCartesianPath(
273 waypoints, maxStep, jumpThreshold, trajectory, avoidCollisions);
274
275 result.plan.trajectory_ = trajectory;
276
277 // Consider successful if we achieved at least 95% of the path
278 result.success = (fractionAchieved >= 0.95);
279
280 if (result.success)
281 {
282 result.errorCode = moveit::core::MoveItErrorCode::SUCCESS;
283 RCLCPP_INFO(
284 getLogger(), "[CpMotionPlanner] Cartesian path planning succeeded (%.1f%% achieved)",
285 fractionAchieved * 100.0);
286 }
287 else
288 {
289 result.errorCode = moveit::core::MoveItErrorCode::PLANNING_FAILED;
290 result.errorMessage = "Cartesian path planning achieved only " +
291 std::to_string(fractionAchieved * 100.0) + "% of the path";
292 RCLCPP_WARN(getLogger(), "[CpMotionPlanner] %s", result.errorMessage.c_str());
293 }
294 }
295 catch (const std::exception & e)
296 {
297 result.success = false;
298 result.errorMessage = std::string("Exception during Cartesian path planning: ") + e.what();
299 RCLCPP_ERROR(getLogger(), "[CpMotionPlanner] %s", result.errorMessage.c_str());
300 }
301
302 return result;
303 }

References cl_moveit2z::PlanningResult::errorCode, cl_moveit2z::PlanningResult::errorMessage, smacc2::ISmaccComponent::getLogger(), cl_moveit2z::ClMoveit2z::moveGroupClientInterface, moveit2zClient_, cl_moveit2z::PlanningResult::plan, and cl_moveit2z::PlanningResult::success.

Here is the call graph for this function:

◆ planToJointTarget()

PlanningResult cl_moveit2z::CpMotionPlanner::planToJointTarget ( const std::map< std::string, double > & jointTargets,
const PlanningOptions & options = {} )
inline

Plan to joint values.

Parameters
jointTargetsMap of joint names to target values
optionsPlanning configuration options
Returns
PlanningResult with success status and computed plan

Definition at line 176 of file cp_motion_planner.hpp.

177 {})
178 {
179 PlanningResult result;
180
181 if (!moveit2zClient_)
182 {
183 result.errorMessage = "ClMoveit2z client not available";
184 RCLCPP_ERROR(getLogger(), "[CpMotionPlanner] %s", result.errorMessage.c_str());
185 return result;
186 }
187
188 if (jointTargets.empty())
189 {
190 result.errorMessage = "No joint targets specified";
191 RCLCPP_WARN(getLogger(), "[CpMotionPlanner] %s", result.errorMessage.c_str());
192 return result;
193 }
194
195 auto & moveGroup = moveit2zClient_->moveGroupClientInterface;
196
197 try
198 {
199 // Apply planning options
200 applyPlanningOptions(*moveGroup, options);
201
202 // Set joint value targets
203 moveGroup->setJointValueTarget(jointTargets);
204
205 RCLCPP_INFO(
206 getLogger(), "[CpMotionPlanner] Planning to joint configuration (%lu joints)...",
207 jointTargets.size());
208
209 // Plan
210 result.errorCode = moveGroup->plan(result.plan);
211 result.success = (result.errorCode == moveit::core::MoveItErrorCode::SUCCESS);
212
213 if (result.success)
214 {
215 RCLCPP_INFO(getLogger(), "[CpMotionPlanner] Planning to joint configuration succeeded");
216 }
217 else
218 {
219 result.errorMessage = "Planning to joint configuration failed with error code: " +
220 std::to_string(result.errorCode.val);
221 RCLCPP_WARN(getLogger(), "[CpMotionPlanner] %s", result.errorMessage.c_str());
222 }
223 }
224 catch (const std::exception & e)
225 {
226 result.success = false;
227 result.errorMessage = std::string("Exception during planning: ") + e.what();
228 RCLCPP_ERROR(getLogger(), "[CpMotionPlanner] %s", result.errorMessage.c_str());
229 }
230
231 return result;
232 }
void applyPlanningOptions(moveit::planning_interface::MoveGroupInterface &moveGroup, const PlanningOptions &options)
Apply planning options to MoveGroupInterface.

Referenced by cl_moveit2z::CbMoveJoints::moveJoints().

Here is the caller graph for this function:

◆ planToPose()

PlanningResult cl_moveit2z::CpMotionPlanner::planToPose ( const geometry_msgs::msg::PoseStamped & target,
const std::optional< std::string > & tipLink = std::nullopt,
const PlanningOptions & options = {} )
inline

Plan to a Cartesian pose.

Parameters
targetTarget pose (position and orientation)
tipLinkEnd effector tip link (optional, uses default if not specified)
optionsPlanning configuration options
Returns
PlanningResult with success status and computed plan

Definition at line 102 of file cp_motion_planner.hpp.

104 {})
105 {
106 PlanningResult result;
107
108 if (!moveit2zClient_)
109 {
110 result.errorMessage = "ClMoveit2z client not available";
111 RCLCPP_ERROR(getLogger(), "[CpMotionPlanner] %s", result.errorMessage.c_str());
112 return result;
113 }
114
115 auto & moveGroup = moveit2zClient_->moveGroupClientInterface;
116
117 try
118 {
119 // Apply planning options
120 applyPlanningOptions(*moveGroup, options);
121
122 // Set pose target
123 if (tipLink && !tipLink->empty())
124 {
125 moveGroup->setPoseTarget(target, *tipLink);
126 }
127 else
128 {
129 moveGroup->setPoseTarget(target);
130 }
131
132 // Set reference frame if specified
133 if (options.poseReferenceFrame)
134 {
135 moveGroup->setPoseReferenceFrame(*options.poseReferenceFrame);
136 }
137 else if (!target.header.frame_id.empty())
138 {
139 moveGroup->setPoseReferenceFrame(target.header.frame_id);
140 }
141
142 RCLCPP_INFO(getLogger(), "[CpMotionPlanner] Planning to pose...");
143
144 // Plan
145 result.errorCode = moveGroup->plan(result.plan);
146 result.success = (result.errorCode == moveit::core::MoveItErrorCode::SUCCESS);
147
148 if (result.success)
149 {
150 RCLCPP_INFO(getLogger(), "[CpMotionPlanner] Planning to pose succeeded");
151 }
152 else
153 {
154 result.errorMessage =
155 "Planning to pose failed with error code: " + std::to_string(result.errorCode.val);
156 RCLCPP_WARN(getLogger(), "[CpMotionPlanner] %s", result.errorMessage.c_str());
157 }
158 }
159 catch (const std::exception & e)
160 {
161 result.success = false;
162 result.errorMessage = std::string("Exception during planning: ") + e.what();
163 RCLCPP_ERROR(getLogger(), "[CpMotionPlanner] %s", result.errorMessage.c_str());
164 }
165
166 return result;
167 }

Referenced by cl_moveit2z::CbMoveEndEffector::moveToAbsolutePose().

Here is the caller graph for this function:

Member Data Documentation

◆ moveit2zClient_

ClMoveit2z* cl_moveit2z::CpMotionPlanner::moveit2zClient_ = nullptr
private

Definition at line 333 of file cp_motion_planner.hpp.

Referenced by getCurrentState(), onInitialize(), and planCartesianPath().


The documentation for this class was generated from the following file: