80 const geometry_msgs::msg::PoseStamped & start,
const geometry_msgs::msg::PoseStamped & goal)
82 RCLCPP_INFO(
nh_->get_logger(),
"[Forward Global Planner] planning");
86 RCLCPP_INFO(
nh_->get_logger(),
"[Forward Global Planner] getting start and goal poses");
88 geometry_msgs::msg::PoseStamped transformedStart;
89 nav_2d_utils::transformPose(
tf_,
costmap_ros_->getGlobalFrameID(), start, transformedStart, ttol);
90 transformedStart.header.frame_id =
costmap_ros_->getGlobalFrameID();
92 geometry_msgs::msg::PoseStamped transformedGoal;
93 nav_2d_utils::transformPose(
tf_,
costmap_ros_->getGlobalFrameID(), goal, transformedGoal, ttol);
94 transformedGoal.header.frame_id =
costmap_ros_->getGlobalFrameID();
97 RCLCPP_INFO(
nh_->get_logger(),
"[Forward Global Planner] creating plan vector");
98 nav_msgs::msg::Path planMsg;
99 std::vector<geometry_msgs::msg::PoseStamped> plan;
106 double dx = transformedGoal.pose.position.x - transformedStart.pose.position.x;
107 double dy = transformedGoal.pose.position.y - transformedStart.pose.position.y;
109 double length = sqrt(dx * dx + dy * dy);
111 geometry_msgs::msg::PoseStamped prevState;
115 RCLCPP_INFO(
nh_->get_logger(),
"1 - heading to goal position pure spinning");
116 double heading_direction = atan2(dy, dx);
126 prevState = transformedStart;
129 RCLCPP_INFO(
nh_->get_logger(),
"3 - heading to goal orientation");
130 double goalOrientation = angles::normalize_angle(tf2::getYaw(transformedGoal.pose.orientation));
132 planMsg.poses = plan;
133 planMsg.header.stamp = this->
nh_->now();
134 planMsg.header.frame_id = this->
costmap_ros_->getGlobalFrameID();
137 nh_->get_logger(),
"[Forward Global Planner] generated plan size: " << plan.size());
140 bool acceptedGlobalPlan =
true;
143 nh_->get_logger(),
"[Forward Global Planner] checking obstacles in the generated plan");
144 nav2_costmap_2d::Costmap2D * costmap2d = this->
costmap_ros_->getCostmap();
145 for (
auto & p : plan)
148 costmap2d->worldToMap(p.pose.position.x, p.pose.position.y, mx, my);
149 auto cost = costmap2d->getCost(mx, my);
156 if (cost >= nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
159 nh_->get_logger(),
"[Forward Global Planner] pose " << p.pose.position.x <<
", "
161 <<
" rejected, cost: " << cost);
162 acceptedGlobalPlan =
false;
167 if (acceptedGlobalPlan)
170 nh_->get_logger(),
"[Forward Global Planner] accepted plan: " << plan.size());
176 RCLCPP_INFO(
nh_->get_logger(),
"[Forward Global Planner] plan rejected");
177 planMsg.poses.clear();
geometry_msgs::msg::PoseStamped makePureStraightSubPlan(const geometry_msgs::msg::PoseStamped &startOrientedPose, const geometry_msgs::msg::Point &goal, double length, std::vector< geometry_msgs::msg::PoseStamped > &plan)