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

#include <cb_move_end_effector.hpp>

Inheritance diagram for cl_moveit2z::CbMoveEndEffector:
Inheritance graph
Collaboration diagram for cl_moveit2z::CbMoveEndEffector:
Collaboration graph

Public Member Functions

 CbMoveEndEffector ()
 
 CbMoveEndEffector (geometry_msgs::msg::PoseStamped target_pose, std::string tip_link="")
 
virtual void onEntry () override
 
- Public Member Functions inherited from cl_moveit2z::CbMoveit2zClientBehaviorBase
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual ~CbMoveit2zClientBehaviorBase ()
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual ~SmaccAsyncClientBehavior ()
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFailure (TCallbackMethod callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
ISmaccStateMachinegetStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename SmaccComponentType >
void requiresComponent (std::string name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
virtual void onExit ()
 

Public Attributes

geometry_msgs::msg::PoseStamped targetPose
 
std::string tip_link_
 
std::optional< std::string > group_
 

Protected Member Functions

bool moveToAbsolutePose (moveit::planning_interface::MoveGroupInterface &moveGroupInterface, geometry_msgs::msg::PoseStamped &targetObjectPose)
 
- Protected Member Functions inherited from cl_moveit2z::CbMoveit2zClientBehaviorBase
void postMotionSuccess ()
 
void postMotionFailure ()
 
- Protected Member Functions inherited from smacc2::SmaccAsyncClientBehavior
void postSuccessEvent ()
 
void postFailureEvent ()
 
virtual void dispose () override
 
bool isShutdownRequested ()
 onEntry is executed in a new thread. However the current state cannot be left until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
virtual void runtimeConfigure ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccStategetCurrentState ()
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 

Additional Inherited Members

- Protected Attributes inherited from cl_moveit2z::CbMoveit2zClientBehaviorBase
CpMoveGroupInterfacecpMoveGroup_ = nullptr
 
CpMotionPlannercpMotionPlanner_ = nullptr
 
CpTrajectoryExecutorcpTrajectoryExecutor_ = nullptr
 
CpTrajectoryHistorycpTrajectoryHistory_ = nullptr
 

Detailed Description

Definition at line 34 of file cb_move_end_effector.hpp.

Constructor & Destructor Documentation

◆ CbMoveEndEffector() [1/2]

cl_moveit2z::CbMoveEndEffector::CbMoveEndEffector ( )
inline

Definition at line 41 of file cb_move_end_effector.hpp.

41{}

◆ CbMoveEndEffector() [2/2]

cl_moveit2z::CbMoveEndEffector::CbMoveEndEffector ( geometry_msgs::msg::PoseStamped target_pose,
std::string tip_link = "" )
inline

Definition at line 43 of file cb_move_end_effector.hpp.

44 : targetPose(target_pose)
45 {
46 tip_link_ = tip_link;
47 }
geometry_msgs::msg::PoseStamped targetPose

References tip_link_.

Member Function Documentation

◆ moveToAbsolutePose()

bool cl_moveit2z::CbMoveEndEffector::moveToAbsolutePose ( moveit::planning_interface::MoveGroupInterface & moveGroupInterface,
geometry_msgs::msg::PoseStamped & targetObjectPose )
inlineprotected

Definition at line 72 of file cb_move_end_effector.hpp.

75 {
76 RCLCPP_DEBUG(getLogger(), "[CbMoveEndEffector] Synchronous sleep of 1 seconds");
77 rclcpp::sleep_for(500ms);
78
79 // Try to use CpMotionPlanner component (preferred)
80 CpMotionPlanner * motionPlanner = cpMotionPlanner_;
81
82 bool success = false;
83 moveit::planning_interface::MoveGroupInterface::Plan computedMotionPlan;
84
85 RCLCPP_INFO_STREAM(
86 getLogger(), "[CbMoveEndEffector] Target End effector Pose: " << targetObjectPose);
87
88 if (motionPlanner != nullptr)
89 {
90 // Use component-based motion planner (preferred)
91 RCLCPP_INFO(getLogger(), "[CbMoveEndEffector] Using CpMotionPlanner component for planning");
92
93 PlanningOptions options;
94 options.planningTime = 1.0;
95 options.poseReferenceFrame = targetObjectPose.header.frame_id;
96
97 std::optional<std::string> tipLinkOpt;
98 if (!tip_link_.empty())
99 {
100 tipLinkOpt = tip_link_;
101 }
102
103 auto result = motionPlanner->planToPose(targetObjectPose, tipLinkOpt, options);
104
105 success = result.success;
106 if (success)
107 {
108 computedMotionPlan = result.plan;
109 RCLCPP_INFO(getLogger(), "[CbMoveEndEffector] Planning succeeded (via CpMotionPlanner)");
110 }
111 else
112 {
113 RCLCPP_WARN(
114 getLogger(), "[CbMoveEndEffector] Planning failed (via CpMotionPlanner): %s",
115 result.errorMessage.c_str());
116 }
117 }
118 else
119 {
120 // Fallback to legacy direct API calls
121 RCLCPP_WARN(
122 getLogger(),
123 "[CbMoveEndEffector] CpMotionPlanner component not available, using legacy planning "
124 "(consider adding CpMotionPlanner component)");
125
126 moveGroupInterface.setPlanningTime(1.0);
127 moveGroupInterface.setPoseTarget(targetObjectPose, tip_link_);
128 moveGroupInterface.setPoseReferenceFrame(targetObjectPose.header.frame_id);
129
130 success =
131 (moveGroupInterface.plan(computedMotionPlan) == moveit::core::MoveItErrorCode::SUCCESS);
132 RCLCPP_INFO(
133 getLogger(), "[CbMoveEndEffector] Planning %s (legacy mode)",
134 success ? "succeeded" : "FAILED");
135 }
136
137 // Execution
138 if (success)
139 {
140 // Try to use CpTrajectoryExecutor component (preferred)
141 CpTrajectoryExecutor * trajectoryExecutor = cpTrajectoryExecutor_;
142
143 bool executionSuccess = false;
144
145 if (trajectoryExecutor != nullptr)
146 {
147 // Use component-based trajectory executor (preferred)
148 RCLCPP_INFO(
149 getLogger(), "[CbMoveEndEffector] Using CpTrajectoryExecutor component for execution");
150
151 ExecutionOptions execOptions;
152 execOptions.trajectoryName = this->getName();
153
154 auto execResult = trajectoryExecutor->executePlan(computedMotionPlan, execOptions);
155 executionSuccess = execResult.success;
156
157 if (executionSuccess)
158 {
159 RCLCPP_INFO(
160 getLogger(), "[CbMoveEndEffector] Execution succeeded (via CpTrajectoryExecutor)");
161 }
162 else
163 {
164 RCLCPP_WARN(
165 getLogger(), "[CbMoveEndEffector] Execution failed (via CpTrajectoryExecutor): %s",
166 execResult.errorMessage.c_str());
167 }
168 }
169 else
170 {
171 // Fallback to legacy direct execution
172 RCLCPP_WARN(
173 getLogger(),
174 "[CbMoveEndEffector] CpTrajectoryExecutor component not available, using legacy "
175 "execution "
176 "(consider adding CpTrajectoryExecutor component)");
177
178 auto executionResult = moveGroupInterface.execute(computedMotionPlan);
179 executionSuccess = (executionResult == moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
180
181 RCLCPP_INFO(
182 getLogger(), "[CbMoveEndEffector] Execution %s (legacy mode)",
183 executionSuccess ? "succeeded" : "failed");
184 }
185
186 // Post events
187 if (executionSuccess)
188 {
189 this->postMotionSuccess();
190 }
191 else
192 {
193 this->postMotionFailure();
194 }
195 }
196 else
197 {
198 RCLCPP_INFO(getLogger(), "[CbMoveEndEffector] planning failed, skipping execution");
199 this->postMotionFailure();
200 }
201
202 RCLCPP_DEBUG(getLogger(), "[CbMoveEndEffector] Synchronous sleep of 1 seconds");
203 rclcpp::sleep_for(500ms);
204
205 return success;
206 }
virtual rclcpp::Logger getLogger() const

References cl_moveit2z::CbMoveit2zClientBehaviorBase::cpMotionPlanner_, cl_moveit2z::CbMoveit2zClientBehaviorBase::cpTrajectoryExecutor_, cl_moveit2z::CpTrajectoryExecutor::executePlan(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), cl_moveit2z::PlanningOptions::planningTime, cl_moveit2z::CpMotionPlanner::planToPose(), cl_moveit2z::PlanningOptions::poseReferenceFrame, cl_moveit2z::CbMoveit2zClientBehaviorBase::postMotionFailure(), cl_moveit2z::CbMoveit2zClientBehaviorBase::postMotionSuccess(), tip_link_, and cl_moveit2z::ExecutionOptions::trajectoryName.

Referenced by onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onEntry()

virtual void cl_moveit2z::CbMoveEndEffector::onEntry ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 49 of file cb_move_end_effector.hpp.

50 {
51 // components resolved in onStateOrthogonalAllocation (base class)
52 if (this->group_)
53 {
54 RCLCPP_DEBUG(
55 getLogger(), "[CbMoveEndEfector] new thread started to move absolute end effector");
56 moveit::planning_interface::MoveGroupInterface move_group(getNode(), *group_);
57 this->moveToAbsolutePose(move_group, targetPose);
58 RCLCPP_DEBUG(
59 getLogger(), "[CbMoveEndEfector] to move absolute end effector thread destroyed");
60 }
61 else
62 {
63 RCLCPP_DEBUG(
64 getLogger(), "[CbMoveEndEfector] new thread started to move absolute end effector");
66 RCLCPP_DEBUG(
67 getLogger(), "[CbMoveEndEfector] to move absolute end effector thread destroyed");
68 }
69 }
bool moveToAbsolutePose(moveit::planning_interface::MoveGroupInterface &moveGroupInterface, geometry_msgs::msg::PoseStamped &targetObjectPose)
std::optional< std::string > group_
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
virtual rclcpp::Node::SharedPtr getNode() const

References cl_moveit2z::CbMoveit2zClientBehaviorBase::cpMoveGroup_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getNode(), group_, cl_moveit2z::CpMoveGroupInterface::moveGroupClientInterface, moveToAbsolutePose(), and targetPose.

Here is the call graph for this function:

Member Data Documentation

◆ group_

std::optional<std::string> cl_moveit2z::CbMoveEndEffector::group_

Definition at line 39 of file cb_move_end_effector.hpp.

Referenced by onEntry().

◆ targetPose

geometry_msgs::msg::PoseStamped cl_moveit2z::CbMoveEndEffector::targetPose

Definition at line 37 of file cb_move_end_effector.hpp.

Referenced by onEntry().

◆ tip_link_

std::string cl_moveit2z::CbMoveEndEffector::tip_link_

Definition at line 38 of file cb_move_end_effector.hpp.

Referenced by CbMoveEndEffector(), and moveToAbsolutePose().


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