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 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 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 all services of a specific type
ros2 service find <type_name>
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: ''}"
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>
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>