The article directories
-
- (1) background
- (2) the premise
- (3) task
-
- Ⅰ preparation
- ⅱ ros2 service Command
-
- ros2 service list
- Ros2 SRV show eloquent service type
-
- Eloquent version
- Ros2 service find (Dashing not supported)
- Ros2 interface show (Dashing not supported)
- ros2 service call
- (4) summarize
(1) background
Services are also a means of communication, req/ RESPone is a trigger, and topic is a subscription
(2) the premise
- Install ros2
- Configure the environment
- Put the turtle
(3) task
Ⅰ preparation
Start the turtle command:
ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key
Copy the code
ⅱ ros2 service Command
ros2 service list
Lists the service command prompt
usage: ros2 service list [-h] [--spin-time SPIN_TIME] [-t] [-c]
Output a list of available services
optional arguments:
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only
applies when not using an already running daemon)
-t, --show-types Additionally show the service type
-c, --count-services Only display the number of services discovered
Copy the code
You can see it through commands and RQT
Ros2 SRV show eloquent service type
Is to look at some of the ways that SRV messages,
- Execute command line
ros2 srv show turtlesim/srv/SetPen
- RQT view
- The file to view
Eloquent version
Ros2 service find (Dashing not supported)
Find a service by type, using the Eloquent version
ros2 service find <type_name>
Copy the code
For example,
ros2 service find std_srvs/srv/Empty
Copy the code
Ros2 interface show (Dashing not supported)
To view the service message information,Eloquent version
Command:ros2 interface show <type_name>.srv
Example:ros2 interface show turtlesim/srv/Spawn.srv
ros2 service call
Invoke service, command line mode
ros2 service call <service_name> <service_type> <arguments>
Copy the code
We call /clear and /spawn
ros2 service call /clear std_srvs/srv/Empty
ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: 'bigggg'}"
Copy the code
(4) summarize
If the communication is not continuous, it is better to use Services and actions