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

#include <cb_pouring_motion.hpp>

Inheritance diagram for cl_moveit2z::CbCircularPouringMotion:
Inheritance graph
Collaboration diagram for cl_moveit2z::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_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 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)
 
- 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_moveit2z::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_moveit2z::CbMoveEndEffectorTrajectory
std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_
 
ClMoveit2zmovegroupClient_ = 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_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 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
 

Detailed Description

Definition at line 27 of file cb_pouring_motion.hpp.

Constructor & Destructor Documentation

◆ CbCircularPouringMotion()

cl_moveit2z::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}
geometry_msgs::msg::Point relativePivotPoint_
CbMoveEndEffectorTrajectory(std::optional< std::string > tipLink=std::nullopt)

Member Function Documentation

◆ computeCurrentEndEffectorPoseRelativeToPivot()

void cl_moveit2z::CbCircularPouringMotion::computeCurrentEndEffectorPoseRelativeToPivot ( )
private

◆ createMarkers()

void cl_moveit2z::CbCircularPouringMotion::createMarkers ( )
overridevirtual

Reimplemented from cl_moveit2z::CbMoveEndEffectorTrajectory.

Definition at line 146 of file cb_pouring_motion.cpp.

147{
149
150 tf2::Stamped<tf2::Transform> currentEndEffectorTransform;
151 this->getCurrentEndEffectorPose(globalFrame_, currentEndEffectorTransform);
152 tf2::Vector3 pivotPoint;
153
154 tf2::fromMsg(this->relativePivotPoint_, pivotPoint);
155
156 tf2::Vector3 pivot = (currentEndEffectorTransform * pivotPoint);
157
158 visualization_msgs::msg::Marker marker;
159
160 marker.ns = "trajectory";
161 marker.id = beahiorMarkers_.markers.size();
162 marker.type = visualization_msgs::msg::Marker::SPHERE;
163 marker.action = visualization_msgs::msg::Marker::ADD;
164 marker.scale.x = 0.01;
165 marker.scale.y = 0.01;
166 marker.scale.z = 0.01;
167
168 marker.color.a = 1.0;
169 marker.color.r = 0.0;
170 marker.color.g = 0;
171 marker.color.b = 1.0;
172
173 tf2::toMsg(pivot, marker.pose.position);
174
175 marker.header.frame_id = globalFrame_;
176 marker.header.stamp = getNode()->now();
177
178 beahiorMarkers_.markers.push_back(marker);
179
180 tf2::Transform localdirection;
181 localdirection.setIdentity();
182 localdirection.setOrigin(tf2::Vector3(0.05, 0, 0));
183 auto frameid = this->pointerTrajectory_.front().header.frame_id;
184
185 for (auto & pose : this->pointerTrajectory_)
186 {
187 visualization_msgs::msg::Marker marker;
188 marker.header.frame_id = frameid;
189 marker.header.stamp = getNode()->now();
190 marker.ns = "trajectory";
191 marker.id = this->beahiorMarkers_.markers.size();
192 marker.type = visualization_msgs::msg::Marker::ARROW;
193 marker.action = visualization_msgs::msg::Marker::ADD;
194 marker.scale.x = 0.005;
195 marker.scale.y = 0.01;
196 marker.scale.z = 0.01;
197 marker.color.a = 0.8;
198 marker.color.r = 0.0;
199 marker.color.g = 1;
200 marker.color.b = 0.0;
201
202 geometry_msgs::msg::Point start, end;
203 start.x = 0;
204 start.y = 0;
205 start.z = 0;
206
207 tf2::Transform basetransform;
208 tf2::fromMsg(pose.pose, basetransform);
209 // tf2::Transform endarrow = localdirection * basetransform;
210
211 end.x = localdirection.getOrigin().x();
212 end.y = localdirection.getOrigin().y();
213 end.z = localdirection.getOrigin().z();
214
215 marker.pose.position = pose.pose.position;
216 marker.pose.orientation = pose.pose.orientation;
217 marker.points.push_back(start);
218 marker.points.push_back(end);
219
220 beahiorMarkers_.markers.push_back(marker);
221 }
222}
std::vector< geometry_msgs::msg::PoseStamped > pointerTrajectory_
void getCurrentEndEffectorPose(std::string globalFrame, tf2::Stamped< tf2::Transform > &currentEndEffectorTransform)
virtual rclcpp::Node::SharedPtr getNode() const
const std::string frameid

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

Here is the call graph for this function:

◆ generateTrajectory()

void cl_moveit2z::CbCircularPouringMotion::generateTrajectory ( )
overridevirtual

Implements cl_moveit2z::CbMoveEndEffectorTrajectory.

Definition at line 38 of file cb_pouring_motion.cpp.

39{
40 // at least 1 sample per centimeter (average)
41 const double METERS_PER_SAMPLE = 0.001;
42
43 float dist_meters = 0;
44 float totallineardist = fabs(this->deltaHeight_);
45
46 int totalSamplesCount = totallineardist / METERS_PER_SAMPLE;
47 int steps = totallineardist / METERS_PER_SAMPLE;
48
49 float interpolation_factor_step = 1.0 / totalSamplesCount;
50
51 double secondsPerSample;
52
54 {
55 secondsPerSample = METERS_PER_SAMPLE / (*linearSpeed_m_s_);
56 }
57 else
58 {
59 secondsPerSample = std::numeric_limits<double>::max();
60 }
61
62 tf2::Stamped<tf2::Transform> currentEndEffectorTransform;
63
64 this->getCurrentEndEffectorPose(globalFrame_, currentEndEffectorTransform);
65
66 tf2::Transform lidEndEffectorTransform;
67 tf2::fromMsg(this->pointerRelativePose_, lidEndEffectorTransform);
68
69 tf2::Vector3 v0, v1;
70 v0 = (currentEndEffectorTransform * lidEndEffectorTransform).getOrigin();
71
72 tf2::Vector3 pivotPoint;
73
74 tf2::fromMsg(this->relativePivotPoint_, pivotPoint);
75
76 tf2::Vector3 pivot = (currentEndEffectorTransform * pivotPoint);
77
78 v0 = v0 - pivot;
79 v1 = v0;
80 v1.setZ(v1.z() + this->deltaHeight_);
81
82 tf2::Vector3 vp1(v1);
83 tf2::Vector3 vp0(v0);
84 tf2::Quaternion rotation = tf2::shortestArcQuatNormalize2(vp0, vp1);
85
86 tf2::Quaternion initialEndEffectorOrientation = currentEndEffectorTransform.getRotation();
87 auto finalEndEffectorOrientation = initialEndEffectorOrientation * rotation;
88
89 tf2::Quaternion initialPointerOrientation =
90 initialEndEffectorOrientation * lidEndEffectorTransform.getRotation();
91 tf2::Quaternion finalPointerOrientation =
92 finalEndEffectorOrientation * lidEndEffectorTransform.getRotation();
93
94 // auto shortestAngle =
95 // tf2::angleShortestPath(initialEndEffectorOrientation, finalEndEffectorOrientation);
96
97 v0 += pivot;
98 v1 += pivot;
99
100 float linc = deltaHeight_ / steps; // METERS_PER_SAMPLE with sign
101 float interpolation_factor = 0;
102 tf2::Vector3 vi = v0;
103
104 tf2::Transform invertedLidTransform = lidEndEffectorTransform.inverse();
105 rclcpp::Time startTime = getNode()->now();
106
107 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] trajectory steps: " << steps);
108 for (float i = 0; i < steps; i++)
109 {
110 // auto currentEndEffectorOrientation =
111 // tf2::slerp(initialEndEffectorOrientation, finalEndEffectorOrientation, interpolation_factor);
112 auto currentPointerOrientation =
113 tf2::slerp(initialPointerOrientation, finalPointerOrientation, interpolation_factor);
114
115 interpolation_factor += interpolation_factor_step;
116 dist_meters += linc;
117
118 vi = v0;
119 vi.setZ(vi.getZ() + dist_meters);
120
121 tf2::Transform pose;
122 pose.setOrigin(vi);
123 pose.setRotation(currentPointerOrientation);
124
125 geometry_msgs::msg::PoseStamped pointerPose;
126 tf2::toMsg(pose, pointerPose.pose);
127 pointerPose.header.frame_id = globalFrame_;
128 pointerPose.header.stamp = startTime + rclcpp::Duration::from_seconds(i * secondsPerSample);
129 this->pointerTrajectory_.push_back(pointerPose);
130
131 tf2::Transform poseEndEffector = pose * invertedLidTransform;
132
133 geometry_msgs::msg::PoseStamped globalEndEffectorPose;
134 tf2::toMsg(poseEndEffector, globalEndEffectorPose.pose);
135 globalEndEffectorPose.header.frame_id = globalFrame_;
136 globalEndEffectorPose.header.stamp =
137 startTime + rclcpp::Duration::from_seconds(i * secondsPerSample);
138
139 this->endEffectorTrajectory_.push_back(globalEndEffectorPose);
140 RCLCPP_INFO_STREAM(
141 getLogger(), "[" << getName() << "] " << i << " - " << globalEndEffectorPose);
142 }
143 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "]trajectory generated, size: " << steps);
144}
geometry_msgs::msg::Pose pointerRelativePose_
std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_
virtual rclcpp::Logger getLogger() const

References deltaHeight_, cl_moveit2z::CbMoveEndEffectorTrajectory::endEffectorTrajectory_, cl_moveit2z::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_moveit2z::CbCircularPouringMotion::angularSpeed_rad_s_

Definition at line 30 of file cb_pouring_motion.hpp.

◆ deltaHeight_

double cl_moveit2z::CbCircularPouringMotion::deltaHeight_
protected

Definition at line 52 of file cb_pouring_motion.hpp.

Referenced by generateTrajectory().

◆ directionVector_

geometry_msgs::msg::Vector3 cl_moveit2z::CbCircularPouringMotion::directionVector_

Definition at line 42 of file cb_pouring_motion.hpp.

◆ globalFrame_

std::string cl_moveit2z::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_moveit2z::CbCircularPouringMotion::linearSpeed_m_s_

Definition at line 32 of file cb_pouring_motion.hpp.

Referenced by generateTrajectory().

◆ pointerRelativePose_

geometry_msgs::msg::Pose cl_moveit2z::CbCircularPouringMotion::pointerRelativePose_

Definition at line 46 of file cb_pouring_motion.hpp.

Referenced by generateTrajectory().

◆ pointerTrajectory_

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

Definition at line 54 of file cb_pouring_motion.hpp.

Referenced by createMarkers(), and generateTrajectory().

◆ relativePivotPoint_

geometry_msgs::msg::Point cl_moveit2z::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: