SMACC2
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | Private Attributes | List of all members
cl_move_group_interface::CbCircularPouringMotion Class Reference

#include <cb_pouring_motion.hpp>

Inheritance diagram for cl_move_group_interface::CbCircularPouringMotion:
Inheritance graph
Collaboration diagram for cl_move_group_interface::CbCircularPouringMotion:
Collaboration graph

Public Member Functions

 CbCircularPouringMotion (const geometry_msgs::msg::Point &pivotPoint, double deltaHeight, std::string tipLink, std::string globalFrame)
 
virtual void generateTrajectory () override
 
virtual void createMarkers () override
 
- Public Member Functions inherited from cl_move_group_interface::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 onOrthogonalAllocation ()
 
virtual void onEntry () override
 
virtual void onExit () override
 
virtual void update () override
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onOrthogonalAllocation ()
 
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=false)
 
virtual void onEntry ()
 
virtual void onExit ()
 
virtual void executeOnEntry ()
 
virtual void executeOnExit ()
 
- Public Member Functions inherited from smacc2::ISmaccUpdatable
 ISmaccUpdatable ()
 
 ISmaccUpdatable (rclcpp::Duration duration)
 
void executeUpdate (rclcpp::Node::SharedPtr node)
 
void setUpdatePeriod (rclcpp::Duration duration)
 

Public Attributes

std::optional< double > angularSpeed_rad_s_
 
std::optional< double > linearSpeed_m_s_
 
geometry_msgs::msg::Vector3 directionVector_
 
geometry_msgs::msg::Pose pointerRelativePose_
 
- Public Attributes inherited from cl_move_group_interface::CbMoveEndEffectorTrajectory
std::optional< std::string > group_
 
std::optional< std::string > tipLink_
 
std::optional< boolallowInitialTrajectoryStateJointDiscontinuity_
 

Protected Attributes

geometry_msgs::msg::Point relativePivotPoint_
 
double deltaHeight_
 
std::vector< geometry_msgs::msg::PoseStamped > pointerTrajectory_
 
- Protected Attributes inherited from cl_move_group_interface::CbMoveEndEffectorTrajectory
std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_
 
ClMoveGroupmovegroupClient_ = nullptr
 
visualization_msgs::msg::MarkerArray beahiorMarkers_
 

Private Member Functions

void computeCurrentEndEffectorPoseRelativeToPivot ()
 

Private Attributes

std::string globalFrame_
 

Additional Inherited Members

- Protected Member Functions inherited from cl_move_group_interface::CbMoveEndEffectorTrajectory
ComputeJointTrajectoryErrorCode computeJointSpaceTrajectory (moveit_msgs::msg::RobotTrajectory &computedJointTrajectory)
 
void executeJointSpaceTrajectory (const moveit_msgs::msg::RobotTrajectory &computedJointTrajectory)
 
virtual void generateTrajectory ()=0
 
virtual void createMarkers ()
 
void getCurrentEndEffectorPose (std::string globalFrame, tf2::Stamped< tf2::Transform > &currentEndEffectorTransform)
 
- Protected Member Functions inherited from smacc2::SmaccAsyncClientBehavior
void postSuccessEvent ()
 
void postFailureEvent ()
 
virtual void dispose () override
 
bool isShutdownRequested ()
 
- 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 void dispose ()
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 
virtual void update ()=0
 

Detailed Description

Definition at line 27 of file cb_pouring_motion.hpp.

Constructor & Destructor Documentation

◆ CbCircularPouringMotion()

cl_move_group_interface::CbCircularPouringMotion::CbCircularPouringMotion ( const geometry_msgs::msg::Point &  pivotPoint,
double  deltaHeight,
std::string  tipLink,
std::string  globalFrame 
)

Definition at line 27 of file cb_pouring_motion.cpp.

31 relativePivotPoint_(relativePivotPoint),
32 deltaHeight_(deltaHeight),
33 globalFrame_(globalFrame)
34
35{
36}
CbMoveEndEffectorTrajectory(std::optional< std::string > tipLink=std::nullopt)

Member Function Documentation

◆ computeCurrentEndEffectorPoseRelativeToPivot()

void cl_move_group_interface::CbCircularPouringMotion::computeCurrentEndEffectorPoseRelativeToPivot ( )
private

◆ createMarkers()

void cl_move_group_interface::CbCircularPouringMotion::createMarkers ( )
overridevirtual

Reimplemented from cl_move_group_interface::CbMoveEndEffectorTrajectory.

Definition at line 175 of file cb_pouring_motion.cpp.

176{
178
179 tf2::Stamped<tf2::Transform> currentEndEffectorTransform;
180 this->getCurrentEndEffectorPose(globalFrame_, currentEndEffectorTransform);
181 tf2::Vector3 pivotPoint;
182
183#ifdef ROS_ROLLING
184 tf2::fromMsg(this->relativePivotPoint_, pivotPoint);
185#else
186 fromMsg(this->relativePivotPoint_, pivotPoint);
187
188#endif
189 tf2::Vector3 pivot = (currentEndEffectorTransform * pivotPoint);
190
191 visualization_msgs::msg::Marker marker;
192
193 marker.ns = "trajectory";
194 marker.id = beahiorMarkers_.markers.size();
195 marker.type = visualization_msgs::msg::Marker::SPHERE;
196 marker.action = visualization_msgs::msg::Marker::ADD;
197 marker.scale.x = 0.01;
198 marker.scale.y = 0.01;
199 marker.scale.z = 0.01;
200
201 marker.color.a = 1.0;
202 marker.color.r = 0.0;
203 marker.color.g = 0;
204 marker.color.b = 1.0;
205
206#ifdef ROS_ROLLING
207 tf2::toMsg(pivot, marker.pose.position);
208#else
209 toMsg(pivot, marker.pose.position);
210#endif
211 marker.header.frame_id = globalFrame_;
212 marker.header.stamp = getNode()->now();
213
214 beahiorMarkers_.markers.push_back(marker);
215
216 tf2::Transform localdirection;
217 localdirection.setIdentity();
218 localdirection.setOrigin(tf2::Vector3(0.05, 0, 0));
219 auto frameid = this->pointerTrajectory_.front().header.frame_id;
220
221 for (auto & pose : this->pointerTrajectory_)
222 {
223 visualization_msgs::msg::Marker marker;
224 marker.header.frame_id = frameid;
225 marker.header.stamp = getNode()->now();
226 marker.ns = "trajectory";
227 marker.id = this->beahiorMarkers_.markers.size();
228 marker.type = visualization_msgs::msg::Marker::ARROW;
229 marker.action = visualization_msgs::msg::Marker::ADD;
230 marker.scale.x = 0.005;
231 marker.scale.y = 0.01;
232 marker.scale.z = 0.01;
233 marker.color.a = 0.8;
234 marker.color.r = 0.0;
235 marker.color.g = 1;
236 marker.color.b = 0.0;
237
238 geometry_msgs::msg::Point start, end;
239 start.x = 0;
240 start.y = 0;
241 start.z = 0;
242
243 tf2::Transform basetransform;
244 tf2::fromMsg(pose.pose, basetransform);
245 // tf2::Transform endarrow = localdirection * basetransform;
246
247 end.x = localdirection.getOrigin().x();
248 end.y = localdirection.getOrigin().y();
249 end.z = localdirection.getOrigin().z();
250
251 marker.pose.position = pose.pose.position;
252 marker.pose.orientation = pose.pose.orientation;
253 marker.points.push_back(start);
254 marker.points.push_back(end);
255
256 beahiorMarkers_.markers.push_back(marker);
257 }
258}
std::vector< geometry_msgs::msg::PoseStamped > pointerTrajectory_
void getCurrentEndEffectorPose(std::string globalFrame, tf2::Stamped< tf2::Transform > &currentEndEffectorTransform)
virtual rclcpp::Node::SharedPtr getNode() const
geometry_msgs::msg::Point & toMsg(const tf2::Vector3 &in, geometry_msgs::msg::Point &out)
void fromMsg(const geometry_msgs::msg::Point &in, tf2::Vector3 &out)
const std::string frameid

References cl_move_group_interface::CbMoveEndEffectorTrajectory::beahiorMarkers_, cl_move_group_interface::CbMoveEndEffectorTrajectory::createMarkers(), cl_move_group_interface::fromMsg(), cl_move_group_interface::CbMoveEndEffectorTrajectory::getCurrentEndEffectorPose(), smacc2::ISmaccClientBehavior::getNode(), globalFrame_, pointerTrajectory_, relativePivotPoint_, and cl_move_group_interface::toMsg().

Here is the call graph for this function:

◆ generateTrajectory()

void cl_move_group_interface::CbCircularPouringMotion::generateTrajectory ( )
overridevirtual

Implements cl_move_group_interface::CbMoveEndEffectorTrajectory.

Definition at line 62 of file cb_pouring_motion.cpp.

63{
64 // at least 1 sample per centimeter (average)
65 const double METERS_PER_SAMPLE = 0.001;
66
67 float dist_meters = 0;
68 float totallineardist = fabs(this->deltaHeight_);
69
70 int totalSamplesCount = totallineardist / METERS_PER_SAMPLE;
71 int steps = totallineardist / METERS_PER_SAMPLE;
72
73 float interpolation_factor_step = 1.0 / totalSamplesCount;
74
75 double secondsPerSample;
76
78 {
79 secondsPerSample = METERS_PER_SAMPLE / (*linearSpeed_m_s_);
80 }
81 else
82 {
83 secondsPerSample = std::numeric_limits<double>::max();
84 }
85
86 tf2::Stamped<tf2::Transform> currentEndEffectorTransform;
87
88 this->getCurrentEndEffectorPose(globalFrame_, currentEndEffectorTransform);
89
90 tf2::Transform lidEndEffectorTransform;
91 tf2::fromMsg(this->pointerRelativePose_, lidEndEffectorTransform);
92
93 tf2::Vector3 v0, v1;
94 v0 = (currentEndEffectorTransform * lidEndEffectorTransform).getOrigin();
95
96 tf2::Vector3 pivotPoint;
97
98#ifdef ROS_ROLLING
99 tf2::fromMsg(this->relativePivotPoint_, pivotPoint);
100#else
101 fromMsg(this->relativePivotPoint_, pivotPoint);
102
103#endif
104
105 tf2::Vector3 pivot = (currentEndEffectorTransform * pivotPoint);
106
107 v0 = v0 - pivot;
108 v1 = v0;
109 v1.setZ(v1.z() + this->deltaHeight_);
110
111 tf2::Vector3 vp1(v1);
112 tf2::Vector3 vp0(v0);
113 tf2::Quaternion rotation = tf2::shortestArcQuatNormalize2(vp0, vp1);
114
115 tf2::Quaternion initialEndEffectorOrientation = currentEndEffectorTransform.getRotation();
116 auto finalEndEffectorOrientation = initialEndEffectorOrientation * rotation;
117
118 tf2::Quaternion initialPointerOrientation =
119 initialEndEffectorOrientation * lidEndEffectorTransform.getRotation();
120 tf2::Quaternion finalPointerOrientation =
121 finalEndEffectorOrientation * lidEndEffectorTransform.getRotation();
122
123 // auto shortestAngle =
124 // tf2::angleShortestPath(initialEndEffectorOrientation, finalEndEffectorOrientation);
125
126 v0 += pivot;
127 v1 += pivot;
128
129 float linc = deltaHeight_ / steps; // METERS_PER_SAMPLE with sign
130 float interpolation_factor = 0;
131 tf2::Vector3 vi = v0;
132
133 tf2::Transform invertedLidTransform = lidEndEffectorTransform.inverse();
134 rclcpp::Time startTime = getNode()->now();
135
136 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] trajectory steps: " << steps);
137 for (float i = 0; i < steps; i++)
138 {
139 // auto currentEndEffectorOrientation =
140 // tf2::slerp(initialEndEffectorOrientation, finalEndEffectorOrientation, interpolation_factor);
141 auto currentPointerOrientation =
142 tf2::slerp(initialPointerOrientation, finalPointerOrientation, interpolation_factor);
143
144 interpolation_factor += interpolation_factor_step;
145 dist_meters += linc;
146
147 vi = v0;
148 vi.setZ(vi.getZ() + dist_meters);
149
150 tf2::Transform pose;
151 pose.setOrigin(vi);
152 pose.setRotation(currentPointerOrientation);
153
154 geometry_msgs::msg::PoseStamped pointerPose;
155 tf2::toMsg(pose, pointerPose.pose);
156 pointerPose.header.frame_id = globalFrame_;
157 pointerPose.header.stamp = startTime + rclcpp::Duration::from_seconds(i * secondsPerSample);
158 this->pointerTrajectory_.push_back(pointerPose);
159
160 tf2::Transform poseEndEffector = pose * invertedLidTransform;
161
162 geometry_msgs::msg::PoseStamped globalEndEffectorPose;
163 tf2::toMsg(poseEndEffector, globalEndEffectorPose.pose);
164 globalEndEffectorPose.header.frame_id = globalFrame_;
165 globalEndEffectorPose.header.stamp =
166 startTime + rclcpp::Duration::from_seconds(i * secondsPerSample);
167
168 this->endEffectorTrajectory_.push_back(globalEndEffectorPose);
169 RCLCPP_INFO_STREAM(
170 getLogger(), "[" << getName() << "] " << i << " - " << globalEndEffectorPose);
171 }
172 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "]trajectory generated, size: " << steps);
173}
std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_
virtual rclcpp::Logger getLogger() const

References deltaHeight_, cl_move_group_interface::CbMoveEndEffectorTrajectory::endEffectorTrajectory_, cl_move_group_interface::fromMsg(), cl_move_group_interface::CbMoveEndEffectorTrajectory::getCurrentEndEffectorPose(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::getNode(), globalFrame_, linearSpeed_m_s_, pointerRelativePose_, pointerTrajectory_, and relativePivotPoint_.

Here is the call graph for this function:

Member Data Documentation

◆ angularSpeed_rad_s_

std::optional<double> cl_move_group_interface::CbCircularPouringMotion::angularSpeed_rad_s_

Definition at line 30 of file cb_pouring_motion.hpp.

◆ deltaHeight_

double cl_move_group_interface::CbCircularPouringMotion::deltaHeight_
protected

Definition at line 52 of file cb_pouring_motion.hpp.

Referenced by generateTrajectory().

◆ directionVector_

geometry_msgs::msg::Vector3 cl_move_group_interface::CbCircularPouringMotion::directionVector_

Definition at line 42 of file cb_pouring_motion.hpp.

◆ globalFrame_

std::string cl_move_group_interface::CbCircularPouringMotion::globalFrame_
private

Definition at line 59 of file cb_pouring_motion.hpp.

Referenced by createMarkers(), and generateTrajectory().

◆ linearSpeed_m_s_

std::optional<double> cl_move_group_interface::CbCircularPouringMotion::linearSpeed_m_s_

Definition at line 32 of file cb_pouring_motion.hpp.

Referenced by generateTrajectory().

◆ pointerRelativePose_

geometry_msgs::msg::Pose cl_move_group_interface::CbCircularPouringMotion::pointerRelativePose_

Definition at line 46 of file cb_pouring_motion.hpp.

Referenced by generateTrajectory().

◆ pointerTrajectory_

std::vector<geometry_msgs::msg::PoseStamped> cl_move_group_interface::CbCircularPouringMotion::pointerTrajectory_
protected

Definition at line 54 of file cb_pouring_motion.hpp.

Referenced by createMarkers(), and generateTrajectory().

◆ relativePivotPoint_

geometry_msgs::msg::Point cl_move_group_interface::CbCircularPouringMotion::relativePivotPoint_
protected

Definition at line 49 of file cb_pouring_motion.hpp.

Referenced by createMarkers(), and generateTrajectory().


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