$ ros2 --help
usage: ros2 [-h] [--use-python-default-buffering] Call `ros2 <command> -h` for more detailed usage. ...
ros2 is an extensible command-line tool for ROS 2.
options:
-h, --help show this help message and exit
--use-python-default-buffering
Do not force line buffering in stdout and instead use the python default buffering, which might be affected by PYTHONUNBUFFERED/-u and depends on whatever
stdout is interactive or not
Commands:
action Various action related sub-commands
bag Various rosbag related sub-commands
component Various component related sub-commands
daemon Various daemon related sub-commands
doctor Check ROS setup and other potential issues
interface Show information about ROS interfaces
launch Run a launch file
lifecycle Various lifecycle related sub-commands
multicast Various multicast related sub-commands
node Various node related sub-commands
param Various param related sub-commands
pkg Various package related sub-commands
run Run a package specific executable
security Various security related sub-commands
service Various service related sub-commands
topic Various topic related sub-commands
wtf Use `wtf` as alias to `doctor`
Call `ros2 <command> -h` for more detailed usage.
查看节点信息
$ ros2 node
usage: ros2 node [-h] Call `ros2 node <command> -h` for more detailed usage. ...
Various node related sub-commands
options:
-h, --help show this help message and exit
Commands:
info Output information about a node
list Output a list of available nodes
Call `ros2 node <command> -h` for more detailed usage.
- 当前运行的ROS系统中都有哪些节点呢?
$ ros2 node list
/talker
- 如果对某一个节点感兴趣,加上一个info子命令,就可以知道它的详细信息啦:
$ ros2 node info /talker
/talker
Subscribers:
/parameter_events: rcl_interfaces/msg/ParameterEvent
Publishers:
/chatter: std_msgs/msg/String
/parameter_events: rcl_interfaces/msg/ParameterEvent
/rosout: rcl_interfaces/msg/Log
Service Servers:
/talker/describe_parameters: rcl_interfaces/srv/DescribeParameters
/talker/get_parameter_types: rcl_interfaces/srv/GetParameterTypes
/talker/get_parameters: rcl_interfaces/srv/GetParameters
/talker/list_parameters: rcl_interfaces/srv/ListParameters
/talker/set_parameters: rcl_interfaces/srv/SetParameters
/talker/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically
Service Clients:
Action Servers:
Action Clients:
运行节点程序
想要运行ROS2中某个节点,我们可以使用ros2 run命令进行操作,例如我们要运行海龟仿真节点和键盘控制节点:
$ ros2 run turtlesim turtlesim_node
$ ros2 run turtlesim turtle_teleop_key
查看话题信息
$ ros2 topic
usage: ros2 topic [-h] [--include-hidden-topics] Call `ros2 topic <command> -h` for more detailed usage. ...
Various topic related sub-commands
options:
-h, --help show this help message and exit
--include-hidden-topics
Consider hidden topics as well
Commands:
bw Display bandwidth used by topic
delay Display delay of topic from timestamp in header
echo Output messages from a topic
find Output a list of available topics of a given type
hz Print the average publishing rate to screen
info Print information about a topic
list Output a list of available topics
pub Publish a message to a topic
type Print a topic's type
Call `ros2 topic <command> -h` for more detailed usage.
- 当前系统中都有哪些话题
$ ros2 topic list
/parameter_events
/rosout
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose
- 某一个话题中的消息数据
$ ros2 topic echo /turtle1/pose
x: 5.544444561004639
y: 5.544444561004639
theta: 0.0
linear_velocity: 0.0
angular_velocity: 0.0
发布话题消息
- 想要控制海龟动起来,我们可以直接通过命令行发布话题指令:
$ ros2 topic pub --rate 1 /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"
发送服务请求
$ ros2 service
usage: ros2 service [-h] [--include-hidden-services]
Call `ros2 service <command> -h` for
more detailed usage. ...
Various service related sub-commands
options:
-h, --help show this help message and exit
--include-hidden-services
Consider hidden services as well
Commands:
call Call a service
find Output a list of available services of a given type
list Output a list of available services
type Output a service's type
Call `ros2 service <command> -h` for more detailed usage.
$ $ ros2 service list
/clear
/kill
/reset
/spawn
/teleop_turtle/describe_parameters
/teleop_turtle/get_parameter_types
/teleop_turtle/get_parameters
/teleop_turtle/list_parameters
/teleop_turtle/set_parameters
/teleop_turtle/set_parameters_atomically
/turtle1/set_pen
/turtle1/teleport_absolute
/turtle1/teleport_relative
/turtlesim/describe_parameters
/turtlesim/get_parameter_types
/turtlesim/get_parameters
/turtlesim/list_parameters
/turtlesim/set_parameters
/turtlesim/set_parameters_atomically
- 一只海龟太孤单,仿真器还提供改了一个服务——产生海龟,我们试一试服务调用,再来一只海龟:
$ ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}"
waiting for service to become available...
requester: making request: turtlesim.srv.Spawn_Request(x=2.0, y=2.0, theta=0.2, name='')
response:
turtlesim.srv.Spawn_Response(name='turtle2')
发送动作目标
$ ros2 action
usage: ros2 action [-h] Call `ros2 action <command> -h` for more detailed usage. ...
Various action related sub-commands
options:
-h, --help show this help message and exit
Commands:
info Print information about an action
list Output a list of action names
send_goal Send an action goal
Call `ros2 action <command> -h` for more detailed usage.
- 想要让海龟完成一个具体动作,比如转到指定角度,可以通过action发送目标动作
$ ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "theta: 3"
录制控制命令
$ ros2 bag
usage: ros2 bag [-h] Call `ros2 bag <command> -h` for more detailed usage. ...
Various rosbag related sub-commands
options:
-h, --help show this help message and exit
Commands:
convert Given an input bag, write out a new bag with different settings
info Print information about a bag to the screen
list Print information about available plugins to the screen
play Play back ROS data from a bag
record Record ROS data to a bag
reindex Reconstruct metadata file for a bag
Call `ros2 bag <command> -h` for more detailed usage.
- 系统运行中的数据有很多,如果想要把某段数据录制下来,回到实验室再复现这段数据如何?ROS2中的rosbag功能还是很好用的,轻松实现数据的录制与播放:
$ ros2 bag record /turtle1/cmd_vel
$ ros2 bag play rosbag2_2022_04_11-17_35_40/rosbag2_2022_04_11-17_35_40_0.db3