Complete the code to initialize the global planner node in ROS.
ros::init(argc, argv, [1]);The global planner node must be initialized with its unique name, here "global_planner_node".
Complete the code to create a ROS publisher for the planned path.
ros::Publisher path_pub = nh.advertise<nav_msgs::Path>([1], 1);
The global planner publishes the planned path on the topic "/planned_path".
Fix the error in the A* heuristic function signature.
double heuristic([1] const Node& a, const Node& b) {The heuristic function parameters should be constant references to avoid copying and allow read-only access.
Fill both blanks to correctly update the cost in Dijkstra's algorithm.
if (distances[neighbor] > distances[current] [1] graph.getCost(current, neighbor)) { distances[neighbor] = distances[current] [2] graph.getCost(current, neighbor); }
In Dijkstra's algorithm, the new cost is the sum of the current cost and the edge cost.
Fill all three blanks to implement the main loop of the A* algorithm.
while (!open_set.empty()) { Node current = open_set.top(); open_set.pop(); if (current == [1]) { return reconstructPath(came_from, current); } for (auto& neighbor : graph.getNeighbors(current)) { double tentative_gScore = g_score[current] [2] graph.getCost(current, neighbor); if (tentative_gScore < g_score[neighbor]) { came_from[neighbor] = current; g_score[neighbor] = tentative_gScore; f_score[neighbor] = g_score[neighbor] [3] heuristic(neighbor, goal); open_set.push(neighbor); } } }
The loop checks if the current node is the goal, updates scores by adding costs and heuristic, and pushes neighbors to the open set.
