📖 Scenario: You are building a ROS node that sends a goal to a robot's action server to move to a target position. You want to receive feedback during the movement to monitor progress.
🎯 Goal: Create a ROS action client node that sends a goal to the move_base action server, receives feedback, and prints the feedback progress.
📋 What You'll Learn
Create a ROS action client node named move_client
Send a goal with position x=1.0 and y=2.0
Implement a feedback callback function named feedback_cb
Print feedback progress inside the feedback callback
Use the MoveBaseAction action type from move_base_msgs
💡 Why This Matters
🌍 Real World
Robots often need to move to specific locations while providing progress updates. This project shows how to build a client that commands movement and monitors feedback.
💼 Career
Understanding ROS action clients and feedback handling is essential for robotics software engineers working on autonomous navigation and control.
Progress0 / 4 steps
1
DATA SETUP: Import ROS libraries and create the action client
Import rospy, actionlib, and MoveBaseAction from move_base_msgs.msg. Create an action client named client for move_base using MoveBaseAction.
ROS
Hint
Use actionlib.SimpleActionClient with the server name 'move_base' and action type MoveBaseAction.
2
CONFIGURATION: Wait for the server and create a goal
Call client.wait_for_server() to wait for the action server. Create a MoveBaseGoal object named goal and set its target position to x=1.0 and y=2.0 in the goal.target_pose.pose.position.
ROS
Hint
Remember to set the header.frame_id to 'map' and orientation w to 1.0 for a valid pose.
3
CORE LOGIC: Define the feedback callback and send the goal
Define a function named feedback_cb that takes one argument feedback. Inside it, print the feedback's current position feedback.base_position.pose.position.x and feedback.base_position.pose.position.y. Then send the goal using client.send_goal(goal, feedback_cb=feedback_cb).
ROS
Hint
The feedback callback receives a feedback object with base_position. Use an f-string to print the x and y positions.
4
COMPLETION: Wait for the result and shutdown the node
Call client.wait_for_result() to wait for the action to finish. Then call rospy.signal_shutdown('Goal reached') to cleanly stop the node.
ROS
Hint
Use client.wait_for_result() to block until the goal finishes, then call rospy.signal_shutdown() with the message.
Practice
(1/5)
1. What is the main purpose of an action client in ROS when using feedback?
easy
A. To directly control robot hardware without feedback
B. To send goals to an action server and receive progress updates
C. To replace service calls with simpler requests
D. To only receive the final result without intermediate updates
Solution
Step 1: Understand the role of an action client
An action client sends goals to an action server and can receive feedback during execution.
Step 2: Identify feedback purpose
Feedback callbacks provide real-time progress updates while the task runs.
Final Answer:
To send goals to an action server and receive progress updates -> Option B
Quick Check:
Action client = send goals + get feedback [OK]
Hint: Action clients send goals and get feedback updates [OK]
Common Mistakes:
Thinking action clients only get final results
Confusing action clients with service clients
Ignoring feedback callbacks
2. Which of the following is the correct way to create an action client with feedback in ROS Python?
easy
A. client = actionlib.SimpleActionClient('move', MoveAction, feedback_cb=feedback_cb)
B. client = actionlib.ActionClient('move', MoveAction, feedback_cb=feedback_cb)
C. client = actionlib.SimpleActionClient('move', MoveAction)
D. client = actionlib.ActionClient('move', MoveAction)
Solution
Step 1: Recall ROS Python action client syntax
The standard way is to use SimpleActionClient with server name and action type.
Step 2: Feedback callback is set separately
Feedback callbacks are registered when sending goals, not in constructor.
Final Answer:
client = actionlib.SimpleActionClient('move', MoveAction) -> Option C
Quick Check:
SimpleActionClient + feedback_cb separate [OK]
Hint: Feedback callback is passed when sending goal, not client creation [OK]
Common Mistakes:
Passing feedback_cb in constructor (wrong)
Using ActionClient instead of SimpleActionClient
Missing action type argument
3. Given this ROS Python snippet, what will be printed if the feedback callback receives progress=50?
A. wait_for_server() should be called before send_goal()
B. feedback_cb cannot be passed to send_goal()
C. TaskGoal() must be assigned to a variable before sending
D. SimpleActionClient requires a third argument for feedback
Solution
Step 1: Check action client usage order
wait_for_server() must be called before sending a goal to ensure server is ready.
Step 2: Identify error in code order
Here, send_goal() is called before wait_for_server(), which is incorrect.
Final Answer:
wait_for_server() should be called before send_goal() -> Option A
Quick Check:
wait_for_server() before send_goal() [OK]
Hint: Always wait for server before sending goal [OK]
Common Mistakes:
Calling send_goal before wait_for_server
Misunderstanding feedback_cb usage
Assuming feedback_cb is constructor argument
5. You want to implement an action client that sends multiple goals sequentially and prints feedback for each. Which approach correctly handles feedback for each goal without mixing updates?
hard
A. Ignore feedback and only wait for final results of each goal
B. Use a single global feedback callback for all goals without distinguishing them
C. Send all goals at once without waiting and use one feedback callback
D. Create a new feedback callback function for each goal that captures its goal ID
Solution
Step 1: Understand feedback handling for multiple goals
Each goal's feedback should be handled separately to avoid mixing progress updates.
Step 2: Use closures or separate callbacks
Creating a unique feedback callback per goal that captures its ID ensures correct feedback association.
Final Answer:
Create a new feedback callback function for each goal that captures its goal ID -> Option D
Quick Check:
Separate feedback callbacks per goal prevent mix-up [OK]
Hint: Use unique feedback callbacks per goal to track progress separately [OK]
Common Mistakes:
Using one callback for all goals causing mixed feedback
Sending all goals simultaneously without control
Ignoring feedback defeats purpose of action client
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.