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 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)
 
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 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
 

Protected Attributes

CpMoveGroupInterfacecpMoveGroup_ = nullptr
 

Detailed Description

Definition at line 37 of file cb_move_end_effector.hpp.

Constructor & Destructor Documentation

◆ CbMoveEndEffector() [1/2]

cl_moveit2z::CbMoveEndEffector::CbMoveEndEffector ( )
inline

Definition at line 44 of file cb_move_end_effector.hpp.

44{}

◆ CbMoveEndEffector() [2/2]

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

Definition at line 46 of file cb_move_end_effector.hpp.

47 : targetPose(target_pose)
48 {
49 tip_link_ = tip_link;
50 }
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 76 of file cb_move_end_effector.hpp.

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

References cpMoveGroup_, cl_moveit2z::CpTrajectoryExecutor::executePlan(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), cl_moveit2z::PlanningOptions::planningTime, cl_moveit2z::CpMotionPlanner::planToPose(), cl_moveit2z::PlanningOptions::poseReferenceFrame, cl_moveit2z::CpMoveGroupInterface::postEventMotionExecutionFailed(), cl_moveit2z::CpMoveGroupInterface::postEventMotionExecutionSucceeded(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), smacc2::ISmaccClientBehavior::requiresComponent(), smacc2::SOFT, 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 52 of file cb_move_end_effector.hpp.

53 {
55
56 if (this->group_)
57 {
58 RCLCPP_DEBUG(
59 getLogger(), "[CbMoveEndEfector] new thread started to move absolute end effector");
60 moveit::planning_interface::MoveGroupInterface move_group(getNode(), *group_);
61 this->moveToAbsolutePose(move_group, targetPose);
62 RCLCPP_DEBUG(
63 getLogger(), "[CbMoveEndEfector] to move absolute end effector thread destroyed");
64 }
65 else
66 {
67 RCLCPP_DEBUG(
68 getLogger(), "[CbMoveEndEfector] new thread started to move absolute end effector");
70 RCLCPP_DEBUG(
71 getLogger(), "[CbMoveEndEfector] to move absolute end effector thread destroyed");
72 }
73 }
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 cpMoveGroup_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getNode(), group_, cl_moveit2z::CpMoveGroupInterface::moveGroupClientInterface, moveToAbsolutePose(), smacc2::ISmaccClientBehavior::requiresComponent(), and targetPose.

Here is the call graph for this function:

Member Data Documentation

◆ cpMoveGroup_

CpMoveGroupInterface* cl_moveit2z::CbMoveEndEffector::cpMoveGroup_ = nullptr
protected

Definition at line 219 of file cb_move_end_effector.hpp.

Referenced by moveToAbsolutePose(), and onEntry().

◆ group_

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

Definition at line 42 of file cb_move_end_effector.hpp.

Referenced by onEntry().

◆ targetPose

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

Definition at line 40 of file cb_move_end_effector.hpp.

Referenced by onEntry().

◆ tip_link_

std::string cl_moveit2z::CbMoveEndEffector::tip_link_

Definition at line 41 of file cb_move_end_effector.hpp.

Referenced by CbMoveEndEffector(), and moveToAbsolutePose().


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