39{
40
41 const double METERS_PER_SAMPLE = 0.001;
42
43 float dist_meters = 0;
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
65
66 tf2::Transform lidEndEffectorTransform;
68
69 tf2::Vector3 v0, v1;
70 v0 = (currentEndEffectorTransform * lidEndEffectorTransform).getOrigin();
71
72 tf2::Vector3 pivotPoint;
73
75
76 tf2::Vector3 pivot = (currentEndEffectorTransform * pivotPoint);
77
78 v0 = v0 - pivot;
79 v1 = v0;
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
95
96
97 v0 += pivot;
98 v1 += pivot;
99
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
111
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);
128 pointerPose.header.stamp = startTime + rclcpp::Duration::from_seconds(i * secondsPerSample);
130
131 tf2::Transform poseEndEffector = pose * invertedLidTransform;
132
133 geometry_msgs::msg::PoseStamped globalEndEffectorPose;
134 tf2::toMsg(poseEndEffector, globalEndEffectorPose.pose);
136 globalEndEffectorPose.header.stamp =
137 startTime + rclcpp::Duration::from_seconds(i * secondsPerSample);
138
140 RCLCPP_INFO_STREAM(
141 getLogger(),
"[" <<
getName() <<
"] " << i <<
" - " << globalEndEffectorPose);
142 }
143 RCLCPP_INFO_STREAM(
getLogger(),
"[" <<
getName() <<
"]trajectory generated, size: " << steps);
144}
std::optional< double > linearSpeed_m_s_
geometry_msgs::msg::Pose pointerRelativePose_
std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_
std::string getName() const
virtual rclcpp::Logger getLogger() const