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
 
 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 onOrthogonalAllocation ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual ~SmaccAsyncClientBehavior ()
 
template<typename TCallback , typename T >
boost::signals2::connection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
boost::signals2::connection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
boost::signals2::connection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
boost::signals2::connection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
boost::signals2::connection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
boost::signals2::connection 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, bool throwExceptionIfNotExist)
 
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)
 
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

ClMoveit2zmovegroupClient_
 

Detailed Description

Definition at line 28 of file cb_move_end_effector.hpp.

Constructor & Destructor Documentation

◆ CbMoveEndEffector() [1/4]

cl_moveit2z::CbMoveEndEffector::CbMoveEndEffector ( )
inline

Definition at line 43 of file cb_move_end_effector.hpp.

43{}

◆ CbMoveEndEffector() [2/4]

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

Definition at line 45 of file cb_move_end_effector.hpp.

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

References tip_link_.

◆ CbMoveEndEffector() [3/4]

cl_moveit2z::CbMoveEndEffector::CbMoveEndEffector ( )

◆ CbMoveEndEffector() [4/4]

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

Member Function Documentation

◆ moveToAbsolutePose() [1/2]

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

Definition at line 75 of file cb_move_end_effector.hpp.

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

References cl_moveit2z::CpTrajectoryExecutor::executePlan(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), movegroupClient_, cl_moveit2z::PlanningOptions::planningTime, cl_moveit2z::CpMotionPlanner::planToPose(), cl_moveit2z::PlanningOptions::poseReferenceFrame, cl_moveit2z::ClMoveit2z::postEventMotionExecutionFailed(), cl_moveit2z::ClMoveit2z::postEventMotionExecutionSucceded(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), smacc2::ISmaccClientBehavior::requiresComponent(), 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:

◆ moveToAbsolutePose() [2/2]

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

◆ onEntry() [1/2]

void cl_moveit2z::CbMoveEndEffector::onEntry ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 51 of file cb_move_end_effector.hpp.

52 {
54
55 if (this->group_)
56 {
57 RCLCPP_DEBUG(
58 getLogger(), "[CbMoveEndEfector] new thread started to move absolute end effector");
59 moveit::planning_interface::MoveGroupInterface move_group(getNode(), *group_);
60 this->moveToAbsolutePose(move_group, targetPose);
61 RCLCPP_DEBUG(
62 getLogger(), "[CbMoveEndEfector] to move absolute end effector thread destroyed");
63 }
64 else
65 {
66 RCLCPP_DEBUG(
67 getLogger(), "[CbMoveEndEfector] new thread started to move absolute end effector");
69 RCLCPP_DEBUG(
70 getLogger(), "[CbMoveEndEfector] to move absolute end effector thread destroyed");
71 }
72 }
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
void requiresClient(SmaccClientType *&storage)

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getNode(), group_, movegroupClient_, cl_moveit2z::ClMoveit2z::moveGroupClientInterface, moveToAbsolutePose(), smacc2::ISmaccClientBehavior::requiresClient(), and targetPose.

Here is the call graph for this function:

◆ onEntry() [2/2]

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

Reimplemented from smacc2::ISmaccClientBehavior.

Member Data Documentation

◆ group_

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

Definition at line 41 of file cb_move_end_effector.hpp.

Referenced by onEntry().

◆ movegroupClient_

ClMoveit2z * cl_moveit2z::CbMoveEndEffector::movegroupClient_
protected

Definition at line 216 of file cb_move_end_effector.hpp.

Referenced by moveToAbsolutePose(), and onEntry().

◆ targetPose

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

Definition at line 39 of file cb_move_end_effector.hpp.

Referenced by onEntry().

◆ tip_link_

std::string cl_moveit2z::CbMoveEndEffector::tip_link_

Definition at line 40 of file cb_move_end_effector.hpp.

Referenced by CbMoveEndEffector(), and moveToAbsolutePose().


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