SMACC
Loading...
Searching...
No Matches
cb_pouring_motion.cpp
Go to the documentation of this file.
2
3/*****************************************************************************************************************
4 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018-2020
5 * Authors: Pablo Inigo Blasco, Brett Aldrich
6 *
7 ******************************************************************************************************************/
8
10
12{
13 CbCircularPouringMotion::CbCircularPouringMotion(const geometry_msgs::Point &relativePivotPoint, double deltaHeight, std::string tipLink, std::string globalFrame)
14 : relativePivotPoint_(relativePivotPoint)
15 , deltaHeight_(deltaHeight)
17 , globalFrame_(globalFrame)
18 {
19 }
20
22 {
23 // at least 1 sample per centimeter (average)
24 const double METERS_PER_SAMPLE = 0.001;
25
26 float dist_meters =0;
27 float totallineardist = fabs(this->deltaHeight_);
28
29 int totalSamplesCount = totallineardist / METERS_PER_SAMPLE;
30 int steps = totallineardist/ METERS_PER_SAMPLE;
31
32 float interpolation_factor_step = 1.0/totalSamplesCount;
33
34 double secondsPerSample;
35
37 {
38 secondsPerSample = METERS_PER_SAMPLE / (*linearSpeed_m_s_);
39 }
40 else
41 {
42 secondsPerSample = std::numeric_limits<double>::max();
43 }
44
45 tf::StampedTransform currentEndEffectorTransform;
46
47 this->getCurrentEndEffectorPose(globalFrame_, currentEndEffectorTransform);
48
49 tf::Transform lidEndEffectorTransform;
50 tf::poseMsgToTF(this->pointerRelativePose_, lidEndEffectorTransform);
51
52 tf::Vector3 v0, v1;
53 v0 = (currentEndEffectorTransform * lidEndEffectorTransform).getOrigin();
54
55 tf::Point pivotPoint;
56 tf::pointMsgToTF(this->relativePivotPoint_, pivotPoint);
57
58 tf::Vector3 pivot = (currentEndEffectorTransform * pivotPoint);
59
60 v0 = v0 - pivot;
61 v1 = v0;
62 v1.setZ(v1.z() + this->deltaHeight_);
63
64 tf::Vector3 vp1(v1);
65 tf::Vector3 vp0(v0);
66 tf::Quaternion rotation = tf::shortestArcQuatNormalize2(vp0, vp1);
67
68 tf::Quaternion initialEndEffectorOrientation = currentEndEffectorTransform.getRotation();
69 auto finalEndEffectorOrientation = initialEndEffectorOrientation* rotation;
70
71 tf::Quaternion initialPointerOrientation = initialEndEffectorOrientation * lidEndEffectorTransform.getRotation();
72 tf::Quaternion finalPointerOrientation = finalEndEffectorOrientation * lidEndEffectorTransform.getRotation();
73
74 auto shortestAngle = tf::angleShortestPath(initialEndEffectorOrientation, finalEndEffectorOrientation);
75
76 v0+=pivot;
77 v1+=pivot;
78
79 float linc = deltaHeight_/steps;// METERS_PER_SAMPLE with sign
80 float interpolation_factor = 0;
81 tf::Vector3 vi = v0;
82
83 tf::Transform invertedLidTransform = lidEndEffectorTransform.inverse();
84 ros::Time startTime = ros::Time::now();
85
86 for (float i =0; i < steps; i++)
87 {
88 auto currentEndEffectorOrientation = tf::slerp(initialEndEffectorOrientation, finalEndEffectorOrientation, interpolation_factor);
89 auto currentPointerOrientation = tf::slerp(initialPointerOrientation, finalPointerOrientation, interpolation_factor);
90
91 interpolation_factor += interpolation_factor_step;
92 dist_meters += linc;
93
94 vi = v0;
95 vi.setZ(vi.getZ() + dist_meters);
96
97 tf::Transform pose;
98 pose.setOrigin(vi);
99 pose.setRotation(currentPointerOrientation);
100
101 geometry_msgs::PoseStamped pointerPose;
102 tf::poseTFToMsg(pose, pointerPose.pose);
103 pointerPose.header.frame_id = globalFrame_;
104 pointerPose.header.stamp = startTime + ros::Duration(i * secondsPerSample);
105 this->pointerTrajectory_.push_back(pointerPose);
106
107 tf::Transform poseEndEffector = pose * invertedLidTransform;
108
109 geometry_msgs::PoseStamped globalEndEffectorPose;
110 tf::poseTFToMsg(poseEndEffector, globalEndEffectorPose.pose);
111 globalEndEffectorPose.header.frame_id = globalFrame_;
112 globalEndEffectorPose.header.stamp = startTime + ros::Duration(i * secondsPerSample);
113
114 this->endEffectorTrajectory_.push_back(globalEndEffectorPose);
115 }
116 }
117
119 {
121
122 tf::StampedTransform currentEndEffectorTransform;
123 this->getCurrentEndEffectorPose(globalFrame_, currentEndEffectorTransform);
124 tf::Point pivotPoint;
125 tf::pointMsgToTF(this->relativePivotPoint_, pivotPoint);
126 tf::Vector3 pivot = (currentEndEffectorTransform * pivotPoint);
127
128
129 visualization_msgs::Marker marker;
130
131 marker.ns = "trajectory";
132 marker.id = beahiorMarkers_.markers.size();
133 marker.type = visualization_msgs::Marker::SPHERE;
134 marker.action = visualization_msgs::Marker::ADD;
135 marker.scale.x = 0.01;
136 marker.scale.y = 0.01;
137 marker.scale.z = 0.01;
138
139 marker.color.a = 1.0;
140 marker.color.r = 0.0;
141 marker.color.g = 0;
142 marker.color.b = 1.0;
143
144 tf::pointTFToMsg(pivot, marker.pose.position);
145 marker.header.frame_id = globalFrame_;
146 marker.header.stamp = ros::Time::now();
147
148 beahiorMarkers_.markers.push_back(marker);
149
150 tf::Transform localdirection;
151 localdirection.setIdentity();
152 localdirection.setOrigin(tf::Vector3(0.05, 0, 0));
153 auto frameid = this->pointerTrajectory_.front().header.frame_id;
154
155 for (auto &pose : this->pointerTrajectory_)
156 {
157 visualization_msgs::Marker marker;
158 marker.header.frame_id = frameid;
159 marker.header.stamp = ros::Time::now();
160 marker.ns = "trajectory";
161 marker.id = this->beahiorMarkers_.markers.size();
162 marker.type = visualization_msgs::Marker::ARROW;
163 marker.action = visualization_msgs::Marker::ADD;
164 marker.scale.x = 0.005;
165 marker.scale.y = 0.01;
166 marker.scale.z = 0.01;
167 marker.color.a = 0.8;
168 marker.color.r = 0.0;
169 marker.color.g = 1;
170 marker.color.b = 0.0;
171
172 geometry_msgs::Point start, end;
173 start.x = 0;
174 start.y = 0;
175 start.z = 0;
176
177 tf::Transform basetransform;
178 tf::poseMsgToTF(pose.pose, basetransform);
179 tf::Transform endarrow = localdirection * basetransform;
180
181 end.x = localdirection.getOrigin().x();
182 end.y = localdirection.getOrigin().y();
183 end.z = localdirection.getOrigin().z();
184
185 marker.pose.position = pose.pose.position;
186 marker.pose.orientation = pose.pose.orientation;
187 marker.points.push_back(start);
188 marker.points.push_back(end);
189
190 beahiorMarkers_.markers.push_back(marker);
191 }
192 }
193
194} // namespace cl_move_group_interface
std::vector< geometry_msgs::PoseStamped > pointerTrajectory_
CbCircularPouringMotion(const geometry_msgs::Point &pivotPoint, double deltaHeight, std::string tipLink, std::string globalFrame)
void getCurrentEndEffectorPose(std::string globalFrame, tf::StampedTransform &currentEndEffectorTransform)
std::vector< geometry_msgs::PoseStamped > endEffectorTrajectory_