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

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

Static Protected Member Functions

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

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_joints.hpp.

Constructor & Destructor Documentation

◆ CbMoveJoints() [1/2]

cl_moveit2z::CbMoveJoints::CbMoveJoints ( )
inline

Definition at line 41 of file cb_move_joints.hpp.

41{}

◆ CbMoveJoints() [2/2]

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

Definition at line 43 of file cb_move_joints.hpp.

44 : jointValueTarget_(jointValueTarget)
45 {
46 }
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 66 of file cb_move_joints.hpp.

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

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 89 of file cb_move_joints.hpp.

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

References cl_moveit2z::CbMoveit2zClientBehaviorBase::cpMotionPlanner_, cl_moveit2z::CbMoveit2zClientBehaviorBase::cpTrajectoryExecutor_, 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::CbMoveit2zClientBehaviorBase::postMotionFailure(), cl_moveit2z::CbMoveit2zClientBehaviorBase::postMotionSuccess(), scalingFactor_, 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 48 of file cb_move_joints.hpp.

49 {
50 // components resolved in onStateOrthogonalAllocation (base class)
51 if (this->group_)
52 {
53 moveit::planning_interface::MoveGroupInterface move_group(
54 getNode(), moveit::planning_interface::MoveGroupInterface::Options(*(this->group_)));
55 this->moveJoints(move_group);
56 }
57 else
58 {
60 }
61 }
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 cl_moveit2z::CbMoveit2zClientBehaviorBase::cpMoveGroup_, smacc2::ISmaccClientBehavior::getNode(), cl_moveit2z::CpMoveGroupInterface::moveGroupClientInterface, and moveJoints().

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 63 of file cb_move_joints.hpp.

63{}

Member Data Documentation

◆ group_

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

Definition at line 39 of file cb_move_joints.hpp.

◆ jointValueTarget_

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

Definition at line 38 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 37 of file cb_move_joints.hpp.

Referenced by moveJoints().


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