Bird
Raised Fist0
ROSframework~20 mins

Action server implementation in ROS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ROS Action Server Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output behavior of this ROS action server code?
Consider a ROS action server implemented in Python that accepts a goal to count up to a number. What will the server do when it receives a goal with count=5?
ROS
import rclpy
from rclpy.action import ActionServer
from example_interfaces.action import Fibonacci

class CountActionServer:
    def __init__(self, node):
        self._action_server = ActionServer(
            node,
            Fibonacci,
            'count_action',
            self.execute_callback)

    def execute_callback(self, goal_handle):
        feedback_msg = Fibonacci.Feedback()
        feedback_msg.sequence = [0, 1]
        for i in range(1, goal_handle.request.order):
            feedback_msg.sequence.append(
                feedback_msg.sequence[i] + feedback_msg.sequence[i - 1])
            goal_handle.publish_feedback(feedback_msg)
        goal_handle.succeed()
        result = Fibonacci.Result()
        result.sequence = feedback_msg.sequence
        return result
AThe server publishes Fibonacci sequence feedback up to the requested order and returns the full sequence as result.
BThe server immediately returns an empty result without publishing any feedback.
CThe server publishes feedback but never returns a result, causing the client to wait indefinitely.
DThe server returns a result with only the first two numbers regardless of the requested order.
Attempts:
2 left
💡 Hint
Think about how the feedback sequence is built and when the result is returned.
📝 Syntax
intermediate
1:30remaining
Which option contains a syntax error in ROS action server implementation?
Identify the option that will cause a syntax error when defining the execute callback method for a ROS action server in Python.
A
def execute_callback(self, goal_handle):
    goal_handle.publish_feedback(feedback)
    goal_handle.succeed()
    return Result()
B
def execute_callback(self goal_handle):
    goal_handle.succeed()
    return Result()
C
def execute_callback(self, goal_handle):
    goal_handle.succeed()
    return Result()
D
def execute_callback(self, goal_handle):
    if goal_handle.is_cancel_requested:
        goal_handle.canceled()
        return Result()
Attempts:
2 left
💡 Hint
Check the function parameter list syntax carefully.
❓ state_output
advanced
2:00remaining
What is the final state of the action server after this code runs?
Given this ROS action server code snippet, what will be the final state of the goal after execute_callback finishes?
ROS
def execute_callback(self, goal_handle):
    if goal_handle.is_cancel_requested:
        goal_handle.canceled()
        return Fibonacci.Result()
    goal_handle.succeed()
    result = Fibonacci.Result()
    result.sequence = [0, 1, 1, 2, 3]
    return result
AThe goal state remains PENDING because no succeed or cancel is called.
BThe goal state is CANCELED with an empty result.
CThe goal state is ABORTED due to missing error handling.
DThe goal state is SUCCEEDED with the Fibonacci sequence result.
Attempts:
2 left
💡 Hint
Check the order of cancel request check and succeed call.
🔧 Debug
advanced
2:00remaining
Why does this ROS action server code cause the client to never receive a result?
Examine the code and select the reason why the client never gets a result from the action server.
ROS
def execute_callback(self, goal_handle):
    feedback = Fibonacci.Feedback()
    feedback.sequence = [0, 1]
    for i in range(1, goal_handle.request.order):
        feedback.sequence.append(feedback.sequence[i] + feedback.sequence[i - 1])
        goal_handle.publish_feedback(feedback)
    # Missing goal_handle.succeed() call
    result = Fibonacci.Result()
    result.sequence = feedback.sequence
    return result
AThe server returns result before publishing any feedback, causing a race condition.
BThe feedback sequence is empty, so the client ignores the result.
CThe server never calls goal_handle.succeed(), so the goal remains active and client waits indefinitely.
DThe server calls succeed() too early, before building the feedback sequence.
Attempts:
2 left
💡 Hint
Check if the server signals goal completion properly.
🧠 Conceptual
expert
1:30remaining
Which statement best describes the role of feedback in a ROS action server?
Select the most accurate description of how feedback is used in a ROS action server implementation.
AFeedback provides incremental updates to the client during goal execution, allowing progress monitoring without completing the goal.
BFeedback is sent only once after the goal completes to summarize the result.
CFeedback replaces the final result and is the only way the client receives data from the server.
DFeedback is used to cancel the goal from the server side when an error occurs.
Attempts:
2 left
💡 Hint
Think about how clients track progress during long-running tasks.

Practice

(1/5)
1. What is the main role of an action server in ROS?
easy
A. To handle long-running tasks and provide feedback during execution
B. To send simple messages without feedback
C. To only receive goals without processing them
D. To replace the ROS parameter server

Solution

  1. Step 1: Understand the purpose of an action server

    An action server is designed to manage tasks that take time and can provide updates while working.
  2. Step 2: Compare options with the role

    Only To handle long-running tasks and provide feedback during execution correctly describes handling long tasks and sending feedback, unlike others which describe unrelated roles.
  3. Final Answer:

    To handle long-running tasks and provide feedback during execution -> Option A
  4. Quick Check:

    Action server = long tasks + feedback [OK]
Hint: Remember: action servers manage long tasks with feedback [OK]
Common Mistakes:
  • Confusing action server with simple message publishers
  • Thinking action server only receives goals without processing
  • Mixing action server with parameter server functionality
2. Which of the following is the correct way to define the execute callback function in a ROS action server using Python?
easy
A. def execute(goal, self):
B. def executeCallback(goal):
C. def callback_execute(goal, self):
D. def execute_callback(self, goal):

Solution

  1. Step 1: Recall the standard signature for execute callback

    In ROS Python action servers, the execute callback is a method with 'self' and 'goal' parameters.
  2. Step 2: Match options to this signature

    Only def execute_callback(self, goal): correctly uses 'def execute_callback(self, goal):' matching the expected pattern.
  3. Final Answer:

    def execute_callback(self, goal): -> Option D
  4. Quick Check:

    Method signature = self first, then goal [OK]
Hint: Method callbacks in classes always have self first [OK]
Common Mistakes:
  • Omitting 'self' parameter in method definition
  • Swapping parameter order incorrectly
  • Using camelCase instead of snake_case for method name
3. Given this snippet inside an action server's execute callback:
for i in range(3):
    feedback.percent_complete = (i + 1) * 33
    self._action_server.publish_feedback(feedback)
    rospy.sleep(1)
result.success = True
self._action_server.set_succeeded(result)

What will the client receive?
medium
A. No feedback updates, only success result
B. Three feedback updates at 33%, 66%, and 99%, then success result
C. Only one feedback update at 99%, then success result
D. Feedback updates but the result will be failure

Solution

  1. Step 1: Analyze the loop sending feedback

    The loop runs 3 times, each time publishing feedback with percent_complete increasing by 33.
  2. Step 2: Check the result setting after loop

    After feedback, the result.success is set to True and the goal is marked succeeded.
  3. Final Answer:

    Three feedback updates at 33%, 66%, and 99%, then success result -> Option B
  4. Quick Check:

    Loop feedback + success result = Three feedback updates at 33%, 66%, and 99%, then success result [OK]
Hint: Loop sends multiple feedbacks before final success [OK]
Common Mistakes:
  • Assuming feedback is sent only once after loop
  • Confusing success with failure result
  • Ignoring the sleep delay between feedbacks
4. Identify the error in this action server execute callback snippet:
def execute_callback(self, goal):
    if goal.order < 0:
        self._action_server.set_aborted()
    result = Result()
    result.output = goal.order * 2
    self._action_server.set_succeeded(result)
medium
A. set_aborted() is called without a result argument
B. Result() is not imported or defined
C. The goal attribute 'order' does not exist
D. set_succeeded() should be called before set_aborted()

Solution

  1. Step 1: Check set_aborted() usage

    set_aborted() requires a result argument to inform the client about failure details.
  2. Step 2: Verify other parts

    Result() usage is typical; goal.order is assumed valid; set_succeeded() after set_aborted() is not called sequentially here.
  3. Final Answer:

    set_aborted() is called without a result argument -> Option A
  4. Quick Check:

    set_aborted needs result argument [OK]
Hint: Always pass a result when aborting goals [OK]
Common Mistakes:
  • Calling set_aborted() without result causes runtime error
  • Assuming set_aborted() can be called without parameters
  • Ignoring the need to inform client on abort
5. You want to implement an action server that cancels the goal if a certain condition is met during execution. Which approach correctly handles goal cancellation in the execute callback?
hard
A. Call set_aborted() immediately when the goal is received without checking cancellation
B. Ignore cancellation requests and always call set_succeeded() at the end
C. Check self._action_server.is_preempt_requested() inside the loop, then call self._action_server.set_preempted() and return
D. Use rospy.sleep() to delay cancellation handling until after completion

Solution

  1. Step 1: Understand cancellation handling in action servers

    Cancellation requests are detected by checking is_preempt_requested() during execution.
  2. Step 2: Proper response to cancellation

    When cancellation is requested, call set_preempted() to notify client and stop processing.
  3. Final Answer:

    Check self._action_server.is_preempt_requested() inside the loop, then call self._action_server.set_preempted() and return -> Option C
  4. Quick Check:

    Cancellation check + set_preempted = Check self._action_server.is_preempt_requested() inside the loop, then call self._action_server.set_preempted() and return [OK]
Hint: Use is_preempt_requested() to detect and handle cancellations [OK]
Common Mistakes:
  • Ignoring cancellation requests during execution
  • Calling set_aborted() instead of set_preempted() on cancel
  • Delaying cancellation handling until after task finishes
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard