44 const costmap_cspace_msgs::MapMetaData3D& map_info,
45 const nav_msgs::Path& previous_path_msg,
65 return buildResults(local_goal_it, robot_pose, cm, result_start_grid);
70 return buildResults(expected_pose_it, robot_pose, cm, result_start_grid);
72 ROS_DEBUG(
"The robot will reach the goal in %f sec.", etas.back());
78 previous_path_2d_.clear();
79 preserved_path_.poses.clear();
80 preserved_path_length_ = 0.0;
85 const Eigen::Vector2d robot_pose_2d(start_metric.position.x, start_metric.position.y);
88 std::tie(it_nearest, dist_err) =
92 ROS_WARN(
"The robot is too far from path. An empty path is published. dist: %f, thr: %f",
101 if (nearest_pos == 1)
105 const double distance_from_start = std::hypot(start_metric.position.x -
previous_path_2d_.begin()->pos_.x(),
107 if (std::abs(distance_from_start - dist_err) < 1.0e-6)
109 ROS_DEBUG(
"Nearest pose in previous path: (%f, %f, %f), dist: %f, index: 0, remaining poses num: %lu",
115 ROS_DEBUG(
"Nearest pose in previous path: (%f, %f, %f), dist: %f, index: %lu, remaining poses num: %lu",
116 it_nearest->pos_.x(), it_nearest->pos_.y(), it_nearest->yaw_, dist_err, nearest_pos,
125 double angle_diff = std::abs(initial_path_pose.
yaw_ -
tf2::getYaw(robot_pose.orientation));
126 angle_diff = (angle_diff > M_PI) ? 2 * M_PI - angle_diff : angle_diff;
127 const double dist_diff = std::hypot(initial_path_pose.
pos_.x() - robot_pose.position.x,
128 initial_path_pose.
pos_.y() - robot_pose.position.y);
134 const geometry_msgs::Pose& robot_pose,
140 ROS_WARN(
"The robot might collide with an obstacle during the next planning. An empty path is published.");
146 map_info_, start_grid[0], start_grid[1], start_grid[2],
147 expected_start_pose_it->pos_.x(), expected_start_pose_it->pos_.y(), expected_start_pose_it->yaw_);
148 start_grid.cycleUnsigned(
map_info_.angle);
151 ROS_DEBUG(
"Robot Pose: (%f, %f, %f), Start Pose: (%f, %f, %f), Start Grid: (%d, %d, %d), path size: %lu -> %lu",
152 robot_pose.position.x, robot_pose.position.y,
tf2::getYaw(robot_pose.orientation),
153 expected_start_pose_it->pos_.x(), expected_start_pose_it->pos_.y(), expected_start_pose_it->yaw_,
154 start_grid[0], start_grid[1], start_grid[2], previous_path_size,
previous_path_2d_.size());
170 const float x_diff = std::abs(grid[0] - 0.5 - std::round(grid[0] - 0.5));
171 const float y_diff = std::abs(grid[1] - 0.5 - std::round(grid[1] - 0.5));
172 const float r_diff = std::abs(grid[2] - std::round(grid[2]));
173 return (x_diff < 1.0e-3) && (y_diff < 1.0e-3) && (r_diff < 1.0e-3);
180 for (
auto it = begin; it != end; ++it)
187 ROS_DEBUG(
"Path colliding at (%f, %f, %f)", it->pos_.x(), it->pos_.y(), it->yaw_);
198 if (local_goal_its.empty())
203 for (
const auto& local_goal : local_goal_its)
207 const double local_goal_eta = etas[local_goal_index];
208 ROS_DEBUG(
"Switch back index: %lu, eta: %f", local_goal_index, local_goal_eta);
214 ROS_INFO(
"The robot will reach a switch back point in %f sec. The next plan starts from the switch back.",
216 return local_goal - 1;
221 ROS_WARN(
"The switch back point is not placed on a grid center. (%f, %f, %f) -> (%f, %f, %f)",
238 ROS_DEBUG(
"The robot will reach a grid center in %f sec.", etas[i]);