22 #include "nav2_route/path_converter.hpp"
30 density_ =
static_cast<float>(node->declare_or_get_parameter(
"path_density", 0.05));
31 smoothing_radius_ =
static_cast<float>(
32 node->declare_or_get_parameter(
"smoothing_radius", 1.0));
33 smoothing_angle_threshold_ =
static_cast<float>(
34 node->declare_or_get_parameter(
"smoothing_angle_threshold", 2.9));
35 smooth_corners_ = node->declare_or_get_parameter(
"smooth_corners",
false);
37 path_pub_ = node->create_publisher<nav_msgs::msg::Path>(
"plan");
38 path_pub_->on_activate();
39 logger_ = node->get_logger();
45 const std::string & frame,
46 const rclcpp::Time & now)
48 nav_msgs::msg::Path path;
49 path.header.stamp = now;
50 path.header.frame_id = frame;
55 if (rerouting_info.curr_edge) {
56 const Coordinates & start = rerouting_info.closest_pt_on_edge;
57 const Coordinates & end = rerouting_info.curr_edge->end->coords;
64 if (!route.edges.empty()) {
65 start = route.edges[0]->start->coords;
68 for (
unsigned int i = 0; i < route.edges.size() - 1; i++) {
69 const EdgePtr edge = route.edges[i];
70 const EdgePtr & next_edge = route.edges[i + 1];
71 end = edge->end->coords;
73 CornerArc corner_arc(start, end, next_edge->end->coords, smoothing_radius_,
74 smoothing_angle_threshold_);
83 corner_arc.
interpolateArc(density_ / smoothing_radius_, path.poses);
88 if (smooth_corners_) {
90 logger_,
"Unable to smooth corner between edge %i and edge %i", edge->edgeid,
99 if (route.edges.empty()) {
100 path.poses.push_back(utils::toMsg(route.start_node->coords.x, route.start_node->coords.y));
103 start.x, start.y, route.edges.back()->end->coords.x,
104 route.edges.back()->end->coords.y, path.poses);
106 path.poses.push_back(
107 utils::toMsg(route.edges.back()->end->coords.x, route.edges.back()->end->coords.y));
111 for (
size_t i = 0; i < path.poses.size() - 1; ++i) {
112 const auto & pose = path.poses[i];
113 const auto & next_pose = path.poses[i + 1];
114 const double dx = next_pose.pose.position.x - pose.pose.position.x;
115 const double dy = next_pose.pose.position.y - pose.pose.position.y;
116 const double yaw = atan2(dy, dx);
117 path.poses[i].pose.orientation = nav2_util::geometry_utils::orientationAroundZAxis(yaw);
121 if (!route.edges.empty()) {
122 const auto & last_edge = route.edges.back();
123 const double dx = last_edge->end->coords.x - last_edge->start->coords.x;
124 const double dy = last_edge->end->coords.y - last_edge->start->coords.y;
125 path.poses.back().pose.orientation =
126 nav2_util::geometry_utils::orientationAroundZAxis(atan2(dy, dx));
130 path_pub_->publish(std::make_unique<nav_msgs::msg::Path>(path));
136 float x0,
float y0,
float x1,
float y1,
137 std::vector<geometry_msgs::msg::PoseStamped> & poses)
140 const float mag = hypotf(x1 - x0, y1 - y0);
141 const unsigned int num_pts = ceil(mag / density_);
147 const float iterpolated_dist = mag / num_pts;
150 float ux = (x1 - x0) / mag;
151 float uy = (y1 - y0) / mag;
156 poses.push_back(utils::toMsg(x, y));
158 unsigned int pt_ctr = 0;
159 while (pt_ctr < num_pts - 1) {
160 x += ux * iterpolated_dist;
161 y += uy * iterpolated_dist;
163 poses.push_back(utils::toMsg(x, y));
A class used to smooth corners defined by the edges and nodes of the route graph. Used with path conv...
bool isCornerValid() const
return if a valid corner arc (one that doesn't overrun the edge lengths) is generated
void interpolateArc(const float &max_angle_resolution, std::vector< geometry_msgs::msg::PoseStamped > &poses)
interpolates the arc for a path of certain density
Coordinates getCornerStart() const
return the start coordinate of the corner arc
Coordinates getCornerEnd() const
return the end coordinate of the corner arc
void interpolateEdge(float x0, float y0, float x1, float y1, std::vector< geometry_msgs::msg::PoseStamped > &poses)
Convert an individual edge into a dense line.
void configure(nav2::LifecycleNode::SharedPtr node)
Configure the object.
nav_msgs::msg::Path densify(const Route &route, const ReroutingState &rerouting_info, const std::string &frame, const rclcpp::Time &now)
Convert a Route into a dense path.
An object to store Node coordinates in different frames.
An object representing edges between nodes.
State shared to objects to communicate important rerouting data to avoid rerouting over blocked edges...
An ordered set of nodes and edges corresponding to the planned route.