🤖
Introduction to ROS2 and Robotics
  • Introduction
  • ROS2
    • Index
    • IDE and CMake Setup
      • How to add additional include search path
    • ROS2 Building Blocks
      • ROS Workspace and Package Layout
      • Launch File
      • tf2
      • Quality of Service
      • Configurations
        • Rviz Configuration
      • Built-in Types
        • Built-in Message Type
    • ROS Architecture
      • Intra-process Communication
    • Navigation and Planning
      • Navigation Stack and Concepts
      • Navigation2 Implementation Overview
        • 🏗️Cost Map
        • Obstacle Avoidance and DWB Controller
      • DWB Controller
      • Page 5
    • How to launch the Nav2 stack
    • ROS2 Control
      • Online Resources
      • Overview of Codebase
    • 🍳Cookbook
      • Useful Commands
      • How to specify parameters
      • How to build the workspace
      • 🏗️How to publish message to a topic from command line?
      • How to inspect service and make a service call
      • How to properly terminate ROS and Gazebo
      • How to add and remove models in Gazebo simulation dynamically
      • 🚧How to spin nodes
    • 🛒Tutorials
      • Services and Communication between ROS2 and Gazebo
      • Subscription and Message Filters Demo
      • Executor and Spin Explained
      • Lifecycle Node Demo
      • Robotic Arm Demo
      • ⚒️Multiple Robotic Arms Simulation Demo
      • 🚧Introduction to xacro
    • Page
    • 🍺Tech Blog
      • Difference between URDF and SDF and how to convert
  • Gazebo
    • Index
    • Terminology
    • GUI
    • World Frame and Axis
    • Cookbook
    • Page 1
  • Programming in Robotics
    • C++
      • CMake
    • Python
    • Rust
  • Mathematics in Robotics
    • Linear Algebra
    • Matrix Properties
    • Probability
      • Expectation-Maximization Algorithm
    • Multivariable Function and Derivatives
  • Physics in Robotics
  • Control of Dynamic Systems
    • Dynamic Response and Transfer Function
    • Block Diagram
    • PID Controller
  • Robot Modeling and Control
    • Rotation and Homogeneous Transformation
  • Probabilistic Robotics
    • Bayes Filter
    • Kalman Filter
    • Particle Filter
    • Discrete Bayes Filter
    • Motion Model
    • Perception Model
    • Localization
    • SLAM
  • Miscellany
  • Concept Index
    • Quaternions
Powered by GitBook
On this page
  1. ROS2
  2. Cookbook

How to inspect service and make a service call

In this article, we will walk through the process of service inspection and present an example of making service call.

The first step is to list available services on the network

ros2 service list
ros2 service list -t

The second command list both service name and the request type.

Suppose we have a service called /add_entity. The next step is to find out the reques type of this service. This can be done using the following command:

ros2 service type /add_entity

The output of this command is the service request type. Suppose the output is entity_management/srv/AddEntity. The next step is to find out the details of this type. This can be done using the following command:

ros2 interface show entity_management/srv/AddEntity

The interface show command produces the details of the type. For example,

AddEntity
string name
string model_filepath
geometry_msgs/Point location
	float64 x
	float64 y
	float64 z
float64 theta
---
bool result

To summarize, we have collected the following information:

Item
Description

service name

/add_entity

service request type

entity_management/srv/AddEntity

service response type

bool

fields in the request type

name, model_filepath, location, theta

The remaining question is how can we make a service call? The command to use is ros2 service call <service_name> <service_type>. Here is an example:

ros2 service call /add_entity entity_management/srv/AddEntity "{name: 'name with space', model_filepath: 'test_path', location: {x: 1, y: 2, z: 3}, theta: 1.3}"

The space in the command is significant, especially the one following the colon (:) that comes after the field name.

©2023 - 2024 all rights reserved

PreviousHow to publish message to a topic from command line?NextHow to properly terminate ROS and Gazebo

Last updated 1 year ago

🍳