77 if (!relativeInitialPose_)
82 <<
"] no end effector pose relative to the pivot, no trajectory generated");
91 initialPose.position.z * initialPose.position.z +
92 initialPose.position.y * initialPose.position.y);
93 double initialAngle = atan2(initialPose.position.z, initialPose.position.y);
101 const double RADS_PER_SAMPLE = 0.02;
102 const double METERS_PER_SAMPLE = 0.01;
104 int totalSamplesCount =
static_cast<int>(
105 std::max(totallineardist / METERS_PER_SAMPLE, totalangulardist / RADS_PER_SAMPLE));
107 double linearSecondsPerSample;
108 double angularSecondsPerSamples;
109 double secondsPerSample;
113 linearSecondsPerSample = METERS_PER_SAMPLE / (*linearSpeed_m_s_);
117 linearSecondsPerSample = std::numeric_limits<double>::max();
122 angularSecondsPerSamples = RADS_PER_SAMPLE / (*angularSpeed_rad_s_);
126 angularSecondsPerSamples = std::numeric_limits<double>::max();
131 secondsPerSample = 0.5;
135 secondsPerSample = std::min(linearSecondsPerSample, angularSecondsPerSamples);
138 double currentAngle = initialAngle;
140 double angleStep =
deltaRadians_ / (double)totalSamplesCount;
142 tf2::Transform tfBasePose;
147 "[" <<
getName() <<
"] generated trajectory, total samples: " << totalSamplesCount);
148 for (
int i = 0; i < totalSamplesCount; i++)
151 double y = radius * cos(currentAngle);
152 double z = radius * sin(currentAngle);
154 geometry_msgs::msg::Pose relativeCurrentPose;
156 relativeCurrentPose.position.x = initialPose.position.x;
157 relativeCurrentPose.position.y = y;
158 relativeCurrentPose.position.z = z;
160 tf2::Quaternion localquat;
161 localquat.setEuler(currentAngle, 0, 0);
163 relativeCurrentPose.orientation.w = 1;
165 tf2::Transform tfRelativeCurrentPose;
166 tf2::fromMsg(relativeCurrentPose, tfRelativeCurrentPose);
168 tf2::Transform tfGlobalPose = tfRelativeCurrentPose * tfBasePose;
170 tfGlobalPose.setRotation(tfGlobalPose.getRotation() * localquat);
172 geometry_msgs::msg::PoseStamped globalPose;
173 tf2::toMsg(tfGlobalPose, globalPose.pose);
176 rclcpp::Duration::from_seconds(i * secondsPerSample);
179 "[" <<
getName() <<
"]" << rclcpp::Time(globalPose.header.stamp).nanoseconds());
182 currentAngle += angleStep;
190 tf2::Transform localdirection;
191 localdirection.setIdentity();
192 localdirection.setOrigin(tf2::Vector3(0.12, 0, 0));
195 visualization_msgs::msg::Marker marker;
196 marker.header.frame_id = frameid;
197 marker.header.stamp =
getNode()->now();
198 marker.ns =
"trajectory";
200 marker.type = visualization_msgs::msg::Marker::ARROW;
201 marker.action = visualization_msgs::msg::Marker::ADD;
202 marker.scale.x = 0.01;
203 marker.scale.y = 0.02;
204 marker.scale.z = 0.02;
205 marker.color.a = 1.0;
206 marker.color.r = 0.0;
208 marker.color.b = 1.0;
210 geometry_msgs::msg::Point start, end;
215 tf2::Transform basetransform;
217 tf2::Transform endarrow = localdirection * basetransform;
219 end.x = endarrow.getOrigin().x();
220 end.y = endarrow.getOrigin().y();
221 end.z = endarrow.getOrigin().z();
223 marker.pose.orientation.w = 1;
224 marker.points.push_back(start);
225 marker.points.push_back(end);
242 tf2::Stamped<tf2::Transform> endEffectorInPivotFrame;
255 if (tfListener !=
nullptr)
263 tf2::fromMsg(transformOpt.value(), endEffectorInPivotFrame);
278 <<
"] CpTfListener component not available, using legacy TF2 (consider "
279 "adding CpTfListener component)");
280 tf2_ros::Buffer tfBuffer(
getNode()->get_clock());
281 tf2_ros::TransformListener tfListenerLegacy(tfBuffer);
284 tfBuffer.lookupTransform(
286 endEffectorInPivotFrame);
289 catch (
const std::exception & e)
294 <<
"] Exception in computeCurrentEndEffectorPoseRelativeToPivot: " << e.what());
300 tf2::Transform pivotTransform;
302 tf2::Transform invertedNewReferenceFrame = pivotTransform.inverse();
304 tf2::Transform currentPoseRelativeToPivot = invertedNewReferenceFrame * endEffectorInPivotFrame;
306 geometry_msgs::msg::Pose finalEndEffectorRelativePose;
307 tf2::toMsg(currentPoseRelativeToPivot, finalEndEffectorRelativePose);