ROS2 Services - Basic Service Server

Hard ROS2 Services 71% pass rate
#services#server#request-response#python#ros2

Practice the ROS2 Services - Basic Service Server coding problem in ROS2 Services. Browser-based execution with automated grading — no local ROS install required. 71% of engineers pass this challenge.

🧠 Concept: Services (Request → Response)

Topics are fire-and-forget — the publisher doesn't know if anyone received the message. Services are different: they're synchronous request/response calls, like a function call between nodes.

[client node] ──request──▶ /add_two_ints ──response──▶ [client node]
                                ▲
                         [server node handles it]

Key API (server side):

self.srv = self.create_service(ServiceType, '/service_name', self.callback)

def callback(self, request, response):
    response.sum = request.a + request.b
    return response  # must return the response object

When to use services vs topics:

  • Topics: continuous data streams (sensor readings, robot state)
  • Services: one-time requests that need a response (compute path, take photo, open gripper)

Problem Statement

Services provide a synchronous Request/Response communication pattern. Create a service server that adds two integers.

Requirements

  • Create a node named add_two_ints_server
  • Create a service named add_two_ints
  • Service Type: example_interfaces/AddTwoInts
  • Callback: Sums request.a and request.b into response.sum
  • Log "Incoming request: a=[a] b=[b]" inside the callback

Input/Output Format

Input:

  • Service Request: a=2, b=3

Output:

  • Service Response: sum=5
  • Console Log: "Incoming request: a=2 b=3"

⚠️ Common Pitfalls

  • Returning None instead of response.
  • Forgetting to import the service type definition.

📚 Helpful Resources

Frequently asked questions

What is the ROS2 Services - Basic Service Server practice problem?

It is a hands-on ROS2 Services challenge on SimuCode where you implement and run ROS2 code in the browser with runtime-verified tests.

How do I practice ROS2 Services - Basic Service Server online?

Open this page, sign in, and solve the problem in the built-in IDE. Your solution is graded against real ROS2 execution checks.

What skills does ROS2 Services - Basic Service Server test?

This Hard problem focuses on services, server, request-response skills used in robotics interviews and production systems.