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

#include <cb_move_joints.hpp>

Inheritance diagram for cl_moveit2z::CbMoveJoints:
Inheritance graph
Collaboration diagram for cl_moveit2z::CbMoveJoints:
Collaboration graph

Public Member Functions

 CbMoveJoints ()
 
 CbMoveJoints (const std::map< std::string, double > &jointValueTarget)
 
virtual void onEntry () override
 
virtual void onExit () 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)
 

Public Attributes

std::optional< double > scalingFactor_
 
std::map< std::string, double > jointValueTarget_
 
std::optional< std::string > group_
 

Protected Member Functions

void moveJoints (moveit::planning_interface::MoveGroupInterface &moveGroupInterface)
 
- 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
 

Static Protected Member Functions

static std::string currentJointStatesToString (moveit::planning_interface::MoveGroupInterface &moveGroupInterface, std::map< std::string, double > &targetJoints)
 

Protected Attributes

CpMoveGroupInterfacecpMoveGroup_ = nullptr
 

Detailed Description

Definition at line 37 of file cb_move_joints.hpp.

Constructor & Destructor Documentation

◆ CbMoveJoints() [1/2]

cl_moveit2z::CbMoveJoints::CbMoveJoints ( )
inline

Definition at line 44 of file cb_move_joints.hpp.

44{}

◆ CbMoveJoints() [2/2]

cl_moveit2z::CbMoveJoints::CbMoveJoints ( const std::map< std::string, double > & jointValueTarget)
inline

Definition at line 46 of file cb_move_joints.hpp.

47 : jointValueTarget_(jointValueTarget)
48 {
49 }
std::map< std::string, double > jointValueTarget_

Member Function Documentation

◆ currentJointStatesToString()

static std::string cl_moveit2z::CbMoveJoints::currentJointStatesToString ( moveit::planning_interface::MoveGroupInterface & moveGroupInterface,
std::map< std::string, double > & targetJoints )
inlinestaticprotected

Definition at line 70 of file cb_move_joints.hpp.

73 {
74 auto state = moveGroupInterface.getCurrentState();
75
76 if (state == nullptr) return std::string();
77
78 auto vnames = state->getVariableNames();
79
80 std::stringstream ss;
81
82 for (auto & tgj : targetJoints)
83 {
84 auto it = std::find(vnames.begin(), vnames.end(), tgj.first);
85 auto index = std::distance(vnames.begin(), it);
86
87 ss << tgj.first << ":" << state->getVariablePosition(index) << std::endl;
88 }
89
90 return ss.str();
91 }

Referenced by moveJoints().

Here is the caller graph for this function:

◆ moveJoints()

void cl_moveit2z::CbMoveJoints::moveJoints ( moveit::planning_interface::MoveGroupInterface & moveGroupInterface)
inlineprotected

Definition at line 93 of file cb_move_joints.hpp.

94 {
95 if (jointValueTarget_.size() == 0)
96 {
97 RCLCPP_WARN(getLogger(), "[CbMoveJoints] No joint value specified. Skipping planning call.");
99 this->postFailureEvent();
100 return;
101 }
102
103 // Try to use CpMotionPlanner component (preferred)
104 CpMotionPlanner * motionPlanner = nullptr;
105 this->requiresComponent(
106 motionPlanner, smacc2::ComponentRequirement::SOFT); // Optional component
107
108 bool success = false;
109 moveit::planning_interface::MoveGroupInterface::Plan computedMotionPlan;
110
111 if (motionPlanner != nullptr)
112 {
113 // Use component-based motion planner (preferred)
114 RCLCPP_INFO(getLogger(), "[CbMoveJoints] Using CpMotionPlanner component for joint planning");
115
116 PlanningOptions options;
117 if (scalingFactor_)
118 {
119 options.maxVelocityScaling = *scalingFactor_;
120 }
121
122 auto result = motionPlanner->planToJointTarget(jointValueTarget_, options);
123
124 success = result.success;
125 if (success)
126 {
127 computedMotionPlan = result.plan;
128 RCLCPP_INFO(getLogger(), "[CbMoveJoints] Planning succeeded (via CpMotionPlanner)");
129 }
130 else
131 {
132 RCLCPP_WARN(
133 getLogger(), "[CbMoveJoints] Planning failed (via CpMotionPlanner): %s",
134 result.errorMessage.c_str());
135 }
136 }
137 else
138 {
139 // Fallback to legacy direct API calls
140 RCLCPP_WARN(
141 getLogger(),
142 "[CbMoveJoints] CpMotionPlanner component not available, using legacy planning "
143 "(consider adding CpMotionPlanner component)");
144
145 if (scalingFactor_) moveGroupInterface.setMaxVelocityScalingFactor(*scalingFactor_);
146
147 moveGroupInterface.setJointValueTarget(jointValueTarget_);
148
149 auto result = moveGroupInterface.plan(computedMotionPlan);
150
151 success = (result == moveit::core::MoveItErrorCode::SUCCESS);
152
153 RCLCPP_INFO(
154 getLogger(), "[CbMoveJoints] Planning %s (legacy mode, code: %d)",
155 success ? "SUCCESS" : "FAILED", result.val);
156 }
157
158 // Execution
159 if (success)
160 {
161 // Try to use CpTrajectoryExecutor component (preferred)
162 CpTrajectoryExecutor * trajectoryExecutor = nullptr;
163 this->requiresComponent(
164 trajectoryExecutor, smacc2::ComponentRequirement::SOFT); // Optional component
165
166 bool executionSuccess = false;
167
168 if (trajectoryExecutor != nullptr)
169 {
170 // Use component-based trajectory executor (preferred)
171 RCLCPP_INFO(
172 getLogger(), "[CbMoveJoints] Using CpTrajectoryExecutor component for execution");
173
174 ExecutionOptions execOptions;
175 execOptions.trajectoryName = this->getName();
176 if (scalingFactor_)
177 {
178 execOptions.maxVelocityScaling = *scalingFactor_;
179 }
180
181 auto execResult = trajectoryExecutor->executePlan(computedMotionPlan, execOptions);
182 executionSuccess = execResult.success;
183
184 if (executionSuccess)
185 {
186 RCLCPP_INFO(getLogger(), "[CbMoveJoints] Execution succeeded (via CpTrajectoryExecutor)");
187 }
188 else
189 {
190 RCLCPP_WARN(
191 getLogger(), "[CbMoveJoints] Execution failed (via CpTrajectoryExecutor): %s",
192 execResult.errorMessage.c_str());
193 }
194 }
195 else
196 {
197 // Fallback to legacy direct execution
198 RCLCPP_WARN(
199 getLogger(),
200 "[CbMoveJoints] CpTrajectoryExecutor component not available, using legacy execution "
201 "(consider adding CpTrajectoryExecutor component)");
202
203 auto executionResult = moveGroupInterface.execute(computedMotionPlan);
204 executionSuccess = (executionResult == moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
205
206 RCLCPP_INFO(
207 getLogger(), "[CbMoveJoints] Execution %s (legacy mode)",
208 executionSuccess ? "succeeded" : "failed");
209 }
210
211 // Post events
212 if (executionSuccess)
213 {
214 RCLCPP_INFO_STREAM(
215 getLogger(),
216 "[" << this->getName() << "] motion execution succeeded. Throwing success event.");
218 this->postSuccessEvent();
219 }
220 else
221 {
222 RCLCPP_WARN_STREAM(
223 getLogger(), "[" << this->getName() << "] motion execution failed. Throwing fail event.");
225 this->postFailureEvent();
226 }
227 }
228 else
229 {
230 auto statestr = currentJointStatesToString(moveGroupInterface, jointValueTarget_);
231 RCLCPP_WARN_STREAM(
232 getLogger(), "[" << this->getName() << "] planning failed. Throwing fail event."
233 << std::endl
234 << statestr);
236 this->postFailureEvent();
237 }
238 }
static std::string currentJointStatesToString(moveit::planning_interface::MoveGroupInterface &moveGroupInterface, std::map< std::string, double > &targetJoints)
CpMoveGroupInterface * cpMoveGroup_
std::optional< double > scalingFactor_
virtual rclcpp::Logger getLogger() const
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)

References cpMoveGroup_, currentJointStatesToString(), cl_moveit2z::CpTrajectoryExecutor::executePlan(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), jointValueTarget_, cl_moveit2z::ExecutionOptions::maxVelocityScaling, cl_moveit2z::PlanningOptions::maxVelocityScaling, cl_moveit2z::CpMotionPlanner::planToJointTarget(), cl_moveit2z::CpMoveGroupInterface::postEventMotionExecutionFailed(), cl_moveit2z::CpMoveGroupInterface::postEventMotionExecutionSucceeded(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), smacc2::ISmaccClientBehavior::requiresComponent(), scalingFactor_, smacc2::SOFT, 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::CbMoveJoints::onEntry ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Reimplemented in cl_moveit2z::CbMoveKnownState.

Definition at line 51 of file cb_move_joints.hpp.

52 {
54
55 if (this->group_)
56 {
57 moveit::planning_interface::MoveGroupInterface move_group(
58 getNode(), moveit::planning_interface::MoveGroupInterface::Options(*(this->group_)));
59 this->moveJoints(move_group);
60 }
61 else
62 {
64 }
65 }
void moveJoints(moveit::planning_interface::MoveGroupInterface &moveGroupInterface)
std::optional< std::string > group_
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
virtual rclcpp::Node::SharedPtr getNode() const

References cpMoveGroup_, smacc2::ISmaccClientBehavior::getNode(), cl_moveit2z::CpMoveGroupInterface::moveGroupClientInterface, moveJoints(), and smacc2::ISmaccClientBehavior::requiresComponent().

Referenced by cl_moveit2z::CbMoveKnownState::onEntry().

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

◆ onExit()

virtual void cl_moveit2z::CbMoveJoints::onExit ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 67 of file cb_move_joints.hpp.

67{}

Member Data Documentation

◆ cpMoveGroup_

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

Definition at line 240 of file cb_move_joints.hpp.

Referenced by moveJoints(), and onEntry().

◆ group_

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

Definition at line 42 of file cb_move_joints.hpp.

◆ jointValueTarget_

std::map<std::string, double> cl_moveit2z::CbMoveJoints::jointValueTarget_

Definition at line 41 of file cb_move_joints.hpp.

Referenced by moveJoints(), and cl_moveit2z::CbMoveKnownState::onEntry().

◆ scalingFactor_

std::optional<double> cl_moveit2z::CbMoveJoints::scalingFactor_

Definition at line 40 of file cb_move_joints.hpp.

Referenced by moveJoints().


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