41 const std::vector<KDL::Frame>& waypoints,
42 KDL::RotationalInterpolation* rot_interpo,
43 double smoothness,
double eqradius)
45 std::vector<KDL::Frame> filtered_waypoints =
filterWaypoints(start_pose, waypoints);
48 KDL::Path_RoundedComposite* composite_path =
new KDL::Path_RoundedComposite(blend_radius, eqradius, rot_interpo);
50 for (
const auto& waypoint : filtered_waypoints)
52 composite_path->Add(waypoint);
55 composite_path->Finish();
56 return std::unique_ptr<KDL::Path>(composite_path);
60 const std::vector<KDL::Frame>& waypoints)
62 std::vector<KDL::Frame> filtered_waypoints = {};
65 filtered_waypoints.push_back(start_pose);
66 int last_added_point_indx = -1;
71 auto last_point = [&]() {
return last_added_point_indx != -1 ? waypoints[last_added_point_indx].p : start_pose.p; };
76 for (
const auto& waypoint : waypoints)
78 dist = (last_point() - waypoint.p).Norm();
79 if (dist > MIN_SEGMENT_LENGTH)
81 filtered_waypoints.push_back(waypoint);
82 ++last_added_point_indx;
85 return filtered_waypoints;
89 double max_allowed_radius = std::numeric_limits<double>::infinity();
91 auto pose_distance = [](
const KDL::Frame& p1,
const KDL::Frame& p2) {
return (p1.p - p2.p).Norm(); };
94 auto segment_angle = [](
const KDL::Frame& p1,
const KDL::Frame& p2,
const KDL::Frame& p3) {
95 KDL::Vector v1 = p2.p - p1.p;
96 KDL::Vector v2 = p2.p - p3.p;
98 double norm_product = v1.Norm() * v2.Norm();
99 if (norm_product < MIN_SEGMENT_LENGTH * MIN_SEGMENT_LENGTH)
102 double cos_theta = KDL::dot(v1, v2) / norm_product;
103 cos_theta = std::clamp(cos_theta, -1.0, 1.0);
105 return std::acos(cos_theta);
108 for (
size_t i = 1; i + 1 < waypoints_.size(); ++i)
110 double dist1 = pose_distance(waypoints_[i], waypoints_[i - 1]);
111 double dist2 = pose_distance(waypoints_[i + 1], waypoints_[i]);
113 if (dist1 < MIN_SEGMENT_LENGTH || dist2 < MIN_SEGMENT_LENGTH)
119 double theta = segment_angle(waypoints_[i - 1], waypoints_[i], waypoints_[i + 1]);
120 double local_max_radius = std::abs(std::tan(theta / 2.0)) * std::min(dist1 / 2.0, dist2 / 2.0);
124 if (local_max_radius < max_allowed_radius)
125 max_allowed_radius = local_max_radius;
128 max_allowed_radius *= std::clamp(smoothness, MIN_SMOOTHNESS, MAX_SMOOTHNESS);
130 return max_allowed_radius;
static std::unique_ptr< KDL::Path > polylineFromWaypoints(const KDL::Frame &start_pose, const std::vector< KDL::Frame > &waypoints, KDL::RotationalInterpolation *rot_interpo, double smoothness, double eqradius)
set the path polyline from waypoints