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 (const 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 ()
 
 SmaccAsyncClientBehavior ()=default
 
 ~SmaccAsyncClientBehavior () override
 
 SmaccAsyncClientBehavior (const SmaccAsyncClientBehavior &)=delete
 
SmaccAsyncClientBehavior & operator= (const SmaccAsyncClientBehavior &)=delete
 
 SmaccAsyncClientBehavior (SmaccAsyncClientBehavior &&)=delete
 
SmaccAsyncClientBehavior & operator= (SmaccAsyncClientBehavior &&)=delete
 
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 ()
 
 ISmaccClientBehavior (const ISmaccClientBehavior &)=delete
 
ISmaccClientBehavior & operator= (const ISmaccClientBehavior &)=delete
 
 ISmaccClientBehavior (ISmaccClientBehavior &&)=delete
 
ISmaccClientBehavior & operator= (ISmaccClientBehavior &&)=delete
 
ISmaccStateMachine * getStateMachine ()
 
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 (const 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 ()
 
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 ()
 
ISmaccState * getCurrentState ()
 
void postInitializationFailureEvent (const std::string &what)
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 
std::string getTraceStateName () const
 
std::string getTraceOrthogonalName () const
 

Additional Inherited Members

- Protected Attributes inherited from cl_moveit2z::CbMoveit2zClientBehaviorBase
CpMoveGroupInterface * cpMoveGroup_ = nullptr
 
CpMotionPlanner * cpMotionPlanner_ = nullptr
 
CpTrajectoryExecutor * cpTrajectoryExecutor_ = nullptr
 
CpTrajectoryHistory * cpTrajectoryHistory_ = 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 ( const 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), tip_link_(std::move(tip_link))
45 {
46 }
geometry_msgs::msg::PoseStamped targetPose

Member Function Documentation

◆ moveToAbsolutePose()

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

Definition at line 71 of file cb_move_end_effector.hpp.

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

49 {
50 // components resolved in onStateOrthogonalAllocation (base class)
51 if (this->group_)
52 {
53 RCLCPP_DEBUG(
54 getLogger(), "[CbMoveEndEfector] new thread started to move absolute end effector");
55 moveit::planning_interface::MoveGroupInterface move_group(getNode(), *group_);
56 this->moveToAbsolutePose(move_group, targetPose);
57 RCLCPP_DEBUG(
58 getLogger(), "[CbMoveEndEfector] to move absolute end effector thread destroyed");
59 }
60 else
61 {
62 RCLCPP_DEBUG(
63 getLogger(), "[CbMoveEndEfector] new thread started to move absolute end effector");
65 RCLCPP_DEBUG(
66 getLogger(), "[CbMoveEndEfector] to move absolute end effector thread destroyed");
67 }
68 }
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 moveToAbsolutePose().


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