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

#include <cb_circular_pivot_motion.hpp>

Inheritance diagram for cl_moveit2z::CbCircularPivotMotion:
Inheritance graph
Collaboration diagram for cl_moveit2z::CbCircularPivotMotion:
Collaboration graph

Public Member Functions

 CbCircularPivotMotion (std::optional< std::string > tipLink=std::nullopt)
 
 CbCircularPivotMotion (const geometry_msgs::msg::PoseStamped &planePivotPose, double deltaRadians, std::optional< std::string > tipLink=std::nullopt)
 
 CbCircularPivotMotion (const geometry_msgs::msg::PoseStamped &planePivotPose, const geometry_msgs::msg::Pose &relativeInitialPose, double deltaRadians, std::optional< std::string > tipLink=std::nullopt)
 
virtual void generateTrajectory () override
 
virtual void createMarkers () override
 
- Public Member Functions inherited from cl_moveit2z::CbMoveEndEffectorTrajectory
 CbMoveEndEffectorTrajectory (std::optional< std::string > tipLink=std::nullopt)
 
 CbMoveEndEffectorTrajectory (const std::vector< geometry_msgs::msg::PoseStamped > &endEffectorTrajectory, std::optional< std::string > tipLink=std::nullopt)
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
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 ()
 
 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)
 

Public Attributes

std::optional< double > angularSpeed_rad_s_
 
std::optional< double > linearSpeed_m_s_
 
std::optional< geometry_msgs::msg::Pose > relativeInitialPose_
 
- Public Attributes inherited from cl_moveit2z::CbMoveEndEffectorTrajectory
std::optional< std::string > group_
 
std::optional< std::string > tipLink_
 
std::optional< bool > allowInitialTrajectoryStateJointDiscontinuity_
 

Protected Attributes

geometry_msgs::msg::PoseStamped planePivotPose_
 
double deltaRadians_ = 0.0
 
- Protected Attributes inherited from cl_moveit2z::CbMoveEndEffectorTrajectory
std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_
 
CpTrajectoryVisualizer * cpTrajectoryVisualizer_ = nullptr
 
CpJointSpaceTrajectoryPlanner * cpJointSpaceTrajectoryPlanner_ = nullptr
 
CpTfListener * cpTfListener_ = nullptr
 
visualization_msgs::msg::MarkerArray beahiorMarkers_
 
- Protected Attributes inherited from cl_moveit2z::CbMoveit2zClientBehaviorBase
CpMoveGroupInterface * cpMoveGroup_ = nullptr
 
CpMotionPlanner * cpMotionPlanner_ = nullptr
 
CpTrajectoryExecutor * cpTrajectoryExecutor_ = nullptr
 
CpTrajectoryHistory * cpTrajectoryHistory_ = nullptr
 

Private Member Functions

void computeCurrentEndEffectorPoseRelativeToPivot ()
 

Additional Inherited Members

- Protected Member Functions inherited from cl_moveit2z::CbMoveEndEffectorTrajectory
ComputeJointTrajectoryErrorCode computeJointSpaceTrajectory (moveit_msgs::msg::RobotTrajectory &computedJointTrajectory)
 
void executeJointSpaceTrajectory (const moveit_msgs::msg::RobotTrajectory &computedJointTrajectory)
 
void getCurrentEndEffectorPose (std::string globalFrame, tf2::Stamped< tf2::Transform > &currentEndEffectorTransform)
 
- 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
 

Detailed Description

Definition at line 34 of file cb_circular_pivot_motion.hpp.

Constructor & Destructor Documentation

◆ CbCircularPivotMotion() [1/3]

cl_moveit2z::CbCircularPivotMotion::CbCircularPivotMotion ( std::optional< std::string > tipLink = std::nullopt)
inline

Definition at line 43 of file cb_circular_pivot_motion.hpp.

45 {
46 }
CbMoveEndEffectorTrajectory(std::optional< std::string > tipLink=std::nullopt)

◆ CbCircularPivotMotion() [2/3]

cl_moveit2z::CbCircularPivotMotion::CbCircularPivotMotion ( const geometry_msgs::msg::PoseStamped & planePivotPose,
double deltaRadians,
std::optional< std::string > tipLink = std::nullopt )
inline

◆ CbCircularPivotMotion() [3/3]

cl_moveit2z::CbCircularPivotMotion::CbCircularPivotMotion ( const geometry_msgs::msg::PoseStamped & planePivotPose,
const geometry_msgs::msg::Pose & relativeInitialPose,
double deltaRadians,
std::optional< std::string > tipLink = std::nullopt )
inline

Definition at line 58 of file cb_circular_pivot_motion.hpp.

63 relativeInitialPose_(relativeInitialPose),
64 planePivotPose_(planePivotPose),
65 deltaRadians_(deltaRadians)
66 {
67 }
std::optional< geometry_msgs::msg::Pose > relativeInitialPose_

Member Function Documentation

◆ computeCurrentEndEffectorPoseRelativeToPivot()

void cl_moveit2z::CbCircularPivotMotion::computeCurrentEndEffectorPoseRelativeToPivot ( )
inlineprivate

Definition at line 237 of file cb_circular_pivot_motion.hpp.

238 {
239 // components resolved in onStateOrthogonalAllocation (base chain)
240 CpTfListener * tfListener = cpTfListener_;
241
242 tf2::Stamped<tf2::Transform> endEffectorInPivotFrame;
243
244 try
245 {
246 if (!tipLink_ || *tipLink_ == "")
247 {
248 tipLink_ = this->cpMoveGroup_->moveGroupClientInterface->getEndEffectorLink();
249 }
250
251 RCLCPP_INFO_STREAM(
252 getLogger(), "[" << getName() << "] waiting transform, pivot: '"
253 << planePivotPose_.header.frame_id << "' tipLink: '" << *tipLink_ << "'");
254
255 if (tfListener != nullptr)
256 {
257 // Use component-based TF listener (preferred)
258 auto transformOpt =
259 tfListener->lookupTransform(planePivotPose_.header.frame_id, *tipLink_, rclcpp::Time());
260
261 if (transformOpt)
262 {
263 tf2::fromMsg(transformOpt.value(), endEffectorInPivotFrame);
264 }
265 else
266 {
267 RCLCPP_ERROR_STREAM(
268 getLogger(), "[" << getName() << "] Failed to lookup transform from " << *tipLink_
269 << " to " << planePivotPose_.header.frame_id);
270 return;
271 }
272 }
273 else
274 {
275 // Fallback to legacy TF2 usage if component not available
276 RCLCPP_WARN_STREAM(
277 getLogger(), "[" << getName()
278 << "] CpTfListener component not available, using legacy TF2 (consider "
279 "adding CpTfListener component)");
280 tf2_ros::Buffer tfBuffer(getNode()->get_clock());
281 tf2_ros::TransformListener tfListenerLegacy(tfBuffer);
282
283 tf2::fromMsg(
284 tfBuffer.lookupTransform(
285 planePivotPose_.header.frame_id, *tipLink_, rclcpp::Time(), rclcpp::Duration(10s)),
286 endEffectorInPivotFrame);
287 }
288 }
289 catch (const std::exception & e)
290 {
291 RCLCPP_ERROR_STREAM(
292 getLogger(),
293 "[" << getName()
294 << "] Exception in computeCurrentEndEffectorPoseRelativeToPivot: " << e.what());
295 return;
296 }
297
298 // now pivot and EndEffector share a common reference frame (let say map)
299 // now get the current pose from the pivot reference frame with inverse composition
300 tf2::Transform pivotTransform;
301 tf2::fromMsg(planePivotPose_.pose, pivotTransform);
302 tf2::Transform invertedNewReferenceFrame = pivotTransform.inverse();
303
304 tf2::Transform currentPoseRelativeToPivot = invertedNewReferenceFrame * endEffectorInPivotFrame;
305
306 geometry_msgs::msg::Pose finalEndEffectorRelativePose;
307 tf2::toMsg(currentPoseRelativeToPivot, finalEndEffectorRelativePose);
308 relativeInitialPose_ = finalEndEffectorRelativePose;
309 }
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const

References cl_moveit2z::CbMoveit2zClientBehaviorBase::cpMoveGroup_, cl_moveit2z::CbMoveEndEffectorTrajectory::cpTfListener_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::getNode(), cl_moveit2z::CpTfListener::lookupTransform(), cl_moveit2z::CpMoveGroupInterface::moveGroupClientInterface, planePivotPose_, relativeInitialPose_, and cl_moveit2z::CbMoveEndEffectorTrajectory::tipLink_.

Referenced by generateTrajectory().

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

◆ createMarkers()

virtual void cl_moveit2z::CbCircularPivotMotion::createMarkers ( )
inlineoverridevirtual

Reimplemented from cl_moveit2z::CbMoveEndEffectorTrajectory.

Definition at line 186 of file cb_circular_pivot_motion.hpp.

187 {
189
190 tf2::Transform localdirection;
191 localdirection.setIdentity();
192 localdirection.setOrigin(tf2::Vector3(0.12, 0, 0));
193 auto frameid = planePivotPose_.header.frame_id;
194
195 visualization_msgs::msg::Marker marker;
196 marker.header.frame_id = frameid;
197 marker.header.stamp = getNode()->now();
198 marker.ns = "trajectory";
199 marker.id = static_cast<int>(beahiorMarkers_.markers.size());
200 marker.type = visualization_msgs::msg::Marker::ARROW;
201 marker.action = visualization_msgs::msg::Marker::ADD;
202 marker.scale.x = 0.01;
203 marker.scale.y = 0.02;
204 marker.scale.z = 0.02;
205 marker.color.a = 1.0;
206 marker.color.r = 0.0;
207 marker.color.g = 0;
208 marker.color.b = 1.0;
209
210 geometry_msgs::msg::Point start, end;
211 start.x = planePivotPose_.pose.position.x;
212 start.y = planePivotPose_.pose.position.y;
213 start.z = planePivotPose_.pose.position.z;
214
215 tf2::Transform basetransform;
216 tf2::fromMsg(planePivotPose_.pose, basetransform);
217 tf2::Transform endarrow = localdirection * basetransform;
218
219 end.x = endarrow.getOrigin().x();
220 end.y = endarrow.getOrigin().y();
221 end.z = endarrow.getOrigin().z();
222
223 marker.pose.orientation.w = 1;
224 marker.points.push_back(start);
225 marker.points.push_back(end);
226
227 beahiorMarkers_.markers.push_back(marker);
228 }
const std::string frameid

References cl_moveit2z::CbMoveEndEffectorTrajectory::beahiorMarkers_, cl_moveit2z::CbMoveEndEffectorTrajectory::createMarkers(), smacc2::ISmaccClientBehavior::getNode(), and planePivotPose_.

Here is the call graph for this function:

◆ generateTrajectory()

virtual void cl_moveit2z::CbCircularPivotMotion::generateTrajectory ( )
inlineoverridevirtual

Reimplemented from cl_moveit2z::CbMoveEndEffectorTrajectory.

Definition at line 69 of file cb_circular_pivot_motion.hpp.

70 {
72 {
74 }
75
76 // The transform lookup can fail and leave the pose unset: no trajectory, and the behavior fails.
78 {
79 RCLCPP_ERROR_STREAM(
80 getLogger(),
81 "[" << getName()
82 << "] no end effector pose relative to the pivot, no trajectory generated");
83 this->postMotionFailure();
84 return;
85 }
86 const geometry_msgs::msg::Pose & initialPose = *relativeInitialPose_;
87
88 // project offset into the xy-plane
89 // get the radius
90 double radius = sqrt(
91 initialPose.position.z * initialPose.position.z +
92 initialPose.position.y * initialPose.position.y);
93 double initialAngle = atan2(initialPose.position.z, initialPose.position.y);
94
95 double totallineardist = fabs(radius * deltaRadians_);
96 double totalangulardist = fabs(deltaRadians_);
97
98 // at least 1 sample per centimeter (average)
99 // at least 1 sample per ~1.1 degrees (average)
100
101 const double RADS_PER_SAMPLE = 0.02;
102 const double METERS_PER_SAMPLE = 0.01;
103
104 int totalSamplesCount = static_cast<int>(
105 std::max(totallineardist / METERS_PER_SAMPLE, totalangulardist / RADS_PER_SAMPLE));
106
107 double linearSecondsPerSample;
108 double angularSecondsPerSamples;
109 double secondsPerSample;
110
112 {
113 linearSecondsPerSample = METERS_PER_SAMPLE / (*linearSpeed_m_s_);
114 }
115 else
116 {
117 linearSecondsPerSample = std::numeric_limits<double>::max();
118 }
119
121 {
122 angularSecondsPerSamples = RADS_PER_SAMPLE / (*angularSpeed_rad_s_);
123 }
124 else
125 {
126 angularSecondsPerSamples = std::numeric_limits<double>::max();
127 }
128
130 {
131 secondsPerSample = 0.5;
132 }
133 else
134 {
135 secondsPerSample = std::min(linearSecondsPerSample, angularSecondsPerSamples);
136 }
137
138 double currentAngle = initialAngle;
139
140 double angleStep = deltaRadians_ / (double)totalSamplesCount;
141
142 tf2::Transform tfBasePose;
143 tf2::fromMsg(planePivotPose_.pose, tfBasePose);
144
145 RCLCPP_INFO_STREAM(
146 getLogger(),
147 "[" << getName() << "] generated trajectory, total samples: " << totalSamplesCount);
148 for (int i = 0; i < totalSamplesCount; i++)
149 {
150 // relativePose i
151 double y = radius * cos(currentAngle);
152 double z = radius * sin(currentAngle);
153
154 geometry_msgs::msg::Pose relativeCurrentPose;
155
156 relativeCurrentPose.position.x = initialPose.position.x;
157 relativeCurrentPose.position.y = y;
158 relativeCurrentPose.position.z = z;
159
160 tf2::Quaternion localquat;
161 localquat.setEuler(currentAngle, 0, 0);
162
163 relativeCurrentPose.orientation.w = 1;
164
165 tf2::Transform tfRelativeCurrentPose;
166 tf2::fromMsg(relativeCurrentPose, tfRelativeCurrentPose);
167
168 tf2::Transform tfGlobalPose = tfRelativeCurrentPose * tfBasePose;
169
170 tfGlobalPose.setRotation(tfGlobalPose.getRotation() * localquat);
171
172 geometry_msgs::msg::PoseStamped globalPose;
173 tf2::toMsg(tfGlobalPose, globalPose.pose);
174 globalPose.header.frame_id = planePivotPose_.header.frame_id;
175 globalPose.header.stamp = rclcpp::Time(planePivotPose_.header.stamp) +
176 rclcpp::Duration::from_seconds(i * secondsPerSample);
177 RCLCPP_INFO_STREAM(
178 getLogger(),
179 "[" << getName() << "]" << rclcpp::Time(globalPose.header.stamp).nanoseconds());
180
181 this->endEffectorTrajectory_.push_back(globalPose);
182 currentAngle += angleStep;
183 }
184 }
std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_

References angularSpeed_rad_s_, computeCurrentEndEffectorPoseRelativeToPivot(), deltaRadians_, cl_moveit2z::CbMoveEndEffectorTrajectory::endEffectorTrajectory_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), linearSpeed_m_s_, planePivotPose_, cl_moveit2z::CbMoveit2zClientBehaviorBase::postMotionFailure(), and relativeInitialPose_.

Here is the call graph for this function:

Member Data Documentation

◆ angularSpeed_rad_s_

std::optional<double> cl_moveit2z::CbCircularPivotMotion::angularSpeed_rad_s_

Definition at line 37 of file cb_circular_pivot_motion.hpp.

Referenced by generateTrajectory().

◆ deltaRadians_

double cl_moveit2z::CbCircularPivotMotion::deltaRadians_ = 0.0
protected

◆ linearSpeed_m_s_

std::optional<double> cl_moveit2z::CbCircularPivotMotion::linearSpeed_m_s_

Definition at line 38 of file cb_circular_pivot_motion.hpp.

Referenced by generateTrajectory().

◆ planePivotPose_

geometry_msgs::msg::PoseStamped cl_moveit2z::CbCircularPivotMotion::planePivotPose_
protected

◆ relativeInitialPose_

std::optional<geometry_msgs::msg::Pose> cl_moveit2z::CbCircularPivotMotion::relativeInitialPose_

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