ROS2 tutorials

hogeol·2023년 1월 2일
0

ROS2

목록 보기
3/4

ROS2 topic

publish topic

ros2 topic pub <topic_name> <msg_type> '<args>'

It can publish data onto a topic directly from the command line

If you want to publish once, using

ros2 topic pub --once <topic_name> <msg_type> '<args>'

Or, publish data onto a topic with desired publish rate, using

ros2 topic pub --rate <desired hz> <topic_name> <msg_type> '<args>'

check topic

Check executing topics

ros2 topic list

Real time information of executing topic data

ros2 topic echo <topic_name>

Information of executing topic

ros2 topic info <topic_name>

Check executing topic data rate

ros2 topic hz <topic_name>

ROS2 service

check services

ros2 service list

service types have two parts: 1 message for the 'request' and another for the 'response'

ros2 service type <service_name>

If you want to see the types of all active services, using

ros2 service list -t

or

ros2 service list --show-types

find service

Find all services of a specific type

ros2 service find <type_name>

call service

If you want to know the structure for call service, using

ros2 interface show <type_name>

For example, if you run

ros2 interface show turtlesim/srv/Spawn

it return

float32 x
float32 y
float32 theta
string name # Optional. A unique name will be created and returned if this is empty
---
string name

Returned data is

Above the '---' line is request arguments and below the '---' line is response arguments
You need above the '---' line <In this case, {x, y, theta, name (optional)}> to call service

and call service,

ros2 service call <service name> <service_type> <arguments>

In above case, you can using <arguments> from command

ros2 service find <type_name>

For example,

ros2 service call /spawn turtlesim/srv/Spawn "{x: 1, y:1, theta: 0.2, name: ''}"

ROS2 parameters

ros param

Check active parameters

ros2 param list

Display current value of the parameter

ros2 param get <node_name> <parameter_name>

Change parameter value

ros2 param set <node_name> <parameter_name> <change value>

redirect parameter and file

View all of a node's current parameter

ros2 param dump <node_name>

If using,

ros2 param dump <node_name> > <file_name.yaml>

redirect the current parameter value into a file to save

Load parameters from a file to a currently running node

ros2 param load <node_name> <parameter_file>

Load parameter file when start the node

ros2 run <package_name> <executable_name> --ros-args --params-file <file_name>

0개의 댓글