Setting navigation goals helps a robot know where to go. It tells the robot the exact place to move to.
Setting navigation goals in ROS
Introduction
Syntax
ROS
goal.target_pose.header.frame_id = "map"; goal.target_pose.header.stamp = ros::Time::now(); goal.target_pose.pose.position.x = X; goal.target_pose.pose.position.y = Y; goal.target_pose.pose.orientation.w = 1.0;
The frame_id "map" means the goal is set in the map's coordinate system.
Orientation is set as a quaternion; setting w=1.0 means no rotation.
Examples
ROS
goal.target_pose.header.frame_id = "map"; goal.target_pose.header.stamp = ros::Time::now(); goal.target_pose.pose.position.x = 2.0; goal.target_pose.pose.position.y = 3.0; goal.target_pose.pose.orientation.w = 1.0;
ROS
goal.target_pose.header.frame_id = "map"; goal.target_pose.header.stamp = ros::Time::now(); goal.target_pose.pose.position.x = -1.5; goal.target_pose.pose.position.y = 0.0; goal.target_pose.pose.orientation.w = 1.0;
Sample Program
This program connects to the move_base server, sends a goal at position (1.0, 2.0) with no rotation, and waits for the robot to reach it. It then prints if the goal was reached.
ROS
#include <ros/ros.h> #include <move_base_msgs/MoveBaseAction.h> #include <actionlib/client/simple_action_client.h> int main(int argc, char** argv) { ros::init(argc, argv, "send_goal_node"); actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> ac("move_base", true); ROS_INFO("Waiting for the move_base action server..."); ac.waitForServer(); move_base_msgs::MoveBaseGoal goal; goal.target_pose.header.frame_id = "map"; goal.target_pose.header.stamp = ros::Time::now(); goal.target_pose.pose.position.x = 1.0; goal.target_pose.pose.position.y = 2.0; goal.target_pose.pose.orientation.w = 1.0; ROS_INFO("Sending goal to (1.0, 2.0)..."); ac.sendGoal(goal); ac.waitForResult(); if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) ROS_INFO("Goal reached successfully!"); else ROS_INFO("Failed to reach the goal."); return 0; }
Important Notes
Always set the header timestamp to ros::Time::now() to avoid old data errors.
Orientation uses quaternions; setting w=1.0 means facing forward with no rotation.
Make sure the move_base action server is running before sending goals.
Summary
Setting navigation goals tells the robot where to go using coordinates and orientation.
Use the "map" frame to set goals relative to the environment.
Send goals through the move_base action client and wait for the result.
Practice
1. What is the main purpose of setting a navigation goal in ROS?
easy
Solution
Step 1: Understand navigation goals
Navigation goals specify a target position and orientation for the robot to reach.Step 2: Identify the purpose
Setting a navigation goal directs the robot where to move in its environment.Final Answer:
To tell the robot where to move using coordinates and orientation -> Option AQuick Check:
Navigation goal = target position [OK]
Hint: Navigation goals set robot's target position and direction [OK]
Common Mistakes:
- Confusing navigation goals with software updates
- Thinking navigation goals change robot appearance
- Assuming navigation goals stop the robot
2. Which ROS frame is commonly used to set navigation goals relative to the environment?
easy
Solution
Step 1: Identify common frames in ROS navigation
Frames like "base_link", "odom", and "map" represent different coordinate systems.Step 2: Choose the frame for environment-relative goals
The "map" frame is fixed to the environment and used for global navigation goals.Final Answer:
"map" frame -> Option CQuick Check:
Environment-relative goals use "map" frame [OK]
Hint: "map" frame is fixed to environment, perfect for goals [OK]
Common Mistakes:
- Using "base_link" which is robot-centered
- Choosing "odom" which drifts over time
- Selecting "camera" which is unrelated to navigation
3. Given this ROS Python snippet to send a navigation goal:
goal.target_pose.header.frame_id = "map" goal.target_pose.pose.position.x = 2.0 goal.target_pose.pose.position.y = 3.0 goal.target_pose.pose.orientation.w = 1.0 client.send_goal(goal) client.wait_for_result()What will the robot do?
medium
Solution
Step 1: Analyze position and orientation values
Position is set to x=2.0, y=3.0; orientation.w=1.0 means no rotation (facing forward).Step 2: Understand client commands
Sending goal and waiting for result commands the robot to move to the specified pose.Final Answer:
Move to position (2.0, 3.0) on the map facing forward -> Option DQuick Check:
Goal pose = (2.0,3.0), orientation forward [OK]
Hint: Orientation w=1 means facing forward, position sets location [OK]
Common Mistakes:
- Mixing up x and y coordinates
- Assuming missing orientation x,y,z causes error
- Thinking orientation.w=1 means backward
4. What is wrong with this ROS Python code snippet for setting a navigation goal?
goal.target_pose.header.frame_id = "map" goal.target_pose.pose.position.x = 1.0 goal.target_pose.pose.position.y = 2.0 client.send_goal(goal) client.wait_for_result()
medium
Solution
Step 1: Check completeness of goal pose
Orientation is not set, which is required for a valid navigation goal.Step 2: Verify other parts
frame_id "map" is correct; position floats are allowed; wait_for_result() must follow send_goal().Final Answer:
Missing orientation in goal.pose causes navigation failure -> Option BQuick Check:
Orientation required for goal [OK]
Hint: Always set orientation when sending navigation goals [OK]
Common Mistakes:
- Ignoring missing orientation
- Changing frame_id unnecessarily
- Misordering wait_for_result and send_goal
5. You want the robot to navigate to two different points sequentially using ROS move_base. Which approach correctly sets and sends these goals?
hard
Solution
Step 1: Understand sequential goal sending
To visit points in order, send one goal and wait for it to finish before sending the next.Step 2: Evaluate options
Sending both simultaneously confuses the robot; sending second first breaks order; last goal alone ignores first.Final Answer:
Send first goal, wait for result, then send second goal and wait again -> Option AQuick Check:
Sequential goals need wait between sends [OK]
Hint: Wait for each goal to finish before sending next [OK]
Common Mistakes:
- Sending multiple goals simultaneously
- Assuming robot queues goals automatically
- Sending goals in wrong order
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
