28 const geometry_msgs::msg::Point & relativePivotPoint,
double deltaHeight, std::string tipLink,
29 std::string globalFrame)
31 relativePivotPoint_(relativePivotPoint),
32 deltaHeight_(deltaHeight),
33 globalFrame_(globalFrame)
40geometry_msgs::msg::Point &
toMsg(
const tf2::Vector3 & in, geometry_msgs::msg::Point & out)
48void toMsg(
const tf2::Transform & in, geometry_msgs::msg::Pose & out)
50 out.position.x = in.getOrigin().getX();
51 out.position.y = in.getOrigin().getY();
52 out.position.z = in.getOrigin().getZ();
53 out.orientation =
toMsg(in.getRotation());
56void fromMsg(
const geometry_msgs::msg::Point & in, tf2::Vector3 & out)
58 out = tf2::Vector3(in.x, in.y, in.z);
65 const double METERS_PER_SAMPLE = 0.001;
67 float dist_meters = 0;
70 int totalSamplesCount = totallineardist / METERS_PER_SAMPLE;
71 int steps = totallineardist / METERS_PER_SAMPLE;
73 float interpolation_factor_step = 1.0 / totalSamplesCount;
75 double secondsPerSample;
79 secondsPerSample = METERS_PER_SAMPLE / (*linearSpeed_m_s_);
83 secondsPerSample = std::numeric_limits<double>::max();
86 tf2::Stamped<tf2::Transform> currentEndEffectorTransform;
90 tf2::Transform lidEndEffectorTransform;
94 v0 = (currentEndEffectorTransform * lidEndEffectorTransform).getOrigin();
96 tf2::Vector3 pivotPoint;
105 tf2::Vector3 pivot = (currentEndEffectorTransform * pivotPoint);
111 tf2::Vector3 vp1(v1);
112 tf2::Vector3 vp0(v0);
113 tf2::Quaternion rotation = tf2::shortestArcQuatNormalize2(vp0, vp1);
115 tf2::Quaternion initialEndEffectorOrientation = currentEndEffectorTransform.getRotation();
116 auto finalEndEffectorOrientation = initialEndEffectorOrientation * rotation;
118 tf2::Quaternion initialPointerOrientation =
119 initialEndEffectorOrientation * lidEndEffectorTransform.getRotation();
120 tf2::Quaternion finalPointerOrientation =
121 finalEndEffectorOrientation * lidEndEffectorTransform.getRotation();
130 float interpolation_factor = 0;
131 tf2::Vector3 vi = v0;
133 tf2::Transform invertedLidTransform = lidEndEffectorTransform.inverse();
134 rclcpp::Time startTime =
getNode()->now();
136 RCLCPP_INFO_STREAM(
getLogger(),
"[" <<
getName() <<
"] trajectory steps: " << steps);
137 for (
float i = 0; i < steps; i++)
141 auto currentPointerOrientation =
142 tf2::slerp(initialPointerOrientation, finalPointerOrientation, interpolation_factor);
144 interpolation_factor += interpolation_factor_step;
148 vi.setZ(vi.getZ() + dist_meters);
152 pose.setRotation(currentPointerOrientation);
154 geometry_msgs::msg::PoseStamped pointerPose;
155 tf2::toMsg(pose, pointerPose.pose);
157 pointerPose.header.stamp = startTime + rclcpp::Duration::from_seconds(i * secondsPerSample);
160 tf2::Transform poseEndEffector = pose * invertedLidTransform;
162 geometry_msgs::msg::PoseStamped globalEndEffectorPose;
163 tf2::toMsg(poseEndEffector, globalEndEffectorPose.pose);
165 globalEndEffectorPose.header.stamp =
166 startTime + rclcpp::Duration::from_seconds(i * secondsPerSample);
170 getLogger(),
"[" <<
getName() <<
"] " << i <<
" - " << globalEndEffectorPose);
172 RCLCPP_INFO_STREAM(
getLogger(),
"[" <<
getName() <<
"]trajectory generated, size: " << steps);
179 tf2::Stamped<tf2::Transform> currentEndEffectorTransform;
181 tf2::Vector3 pivotPoint;
189 tf2::Vector3 pivot = (currentEndEffectorTransform * pivotPoint);
191 visualization_msgs::msg::Marker marker;
193 marker.ns =
"trajectory";
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;
201 marker.color.a = 1.0;
202 marker.color.r = 0.0;
204 marker.color.b = 1.0;
207 tf2::toMsg(pivot, marker.pose.position);
209 toMsg(pivot, marker.pose.position);
212 marker.header.stamp =
getNode()->now();
216 tf2::Transform localdirection;
217 localdirection.setIdentity();
218 localdirection.setOrigin(tf2::Vector3(0.05, 0, 0));
223 visualization_msgs::msg::Marker marker;
224 marker.header.frame_id = frameid;
225 marker.header.stamp =
getNode()->now();
226 marker.ns =
"trajectory";
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;
236 marker.color.b = 0.0;
238 geometry_msgs::msg::Point start, end;
243 tf2::Transform basetransform;
244 tf2::fromMsg(pose.pose, basetransform);
247 end.x = localdirection.getOrigin().x();
248 end.y = localdirection.getOrigin().y();
249 end.z = localdirection.getOrigin().z();
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);
virtual void createMarkers() override
geometry_msgs::msg::Point relativePivotPoint_
virtual void generateTrajectory() override
CbCircularPouringMotion(const geometry_msgs::msg::Point &pivotPoint, double deltaHeight, std::string tipLink, std::string globalFrame)
std::optional< double > linearSpeed_m_s_
geometry_msgs::msg::Pose pointerRelativePose_
std::vector< geometry_msgs::msg::PoseStamped > pointerTrajectory_
virtual void createMarkers()
void getCurrentEndEffectorPose(std::string globalFrame, tf2::Stamped< tf2::Transform > ¤tEndEffectorTransform)
std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_
visualization_msgs::msg::MarkerArray beahiorMarkers_
std::string getName() const
virtual rclcpp::Logger getLogger() const
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)