ROS2极简总结-命令⾏接⼝基础
参考⽂献:ROS 2 CLI BASICS - A quick dive into ROS 2 Command Line Interface
之前,个⼈博客⼤量教程分节介绍过这些命令⾏,此⽂做⼀个总述,更⽅便了解全貌。
⼤纲
1. 安装和导⼊
2. 基本命令结构
3. 发布者和订阅者
4. 服务
5. ⾏动和参数
6. ⼯具
安装和导⼊
两种安装类型 - ⼆进制包(推荐)或源代码编译。(通常源代码编译为专业开发者喜爱)
Live USB 具有 ROS2 Foxy 功能 - 验证:
ll /opt/ros/foxy.
导⼊ ROS2 使⽤命令、库、包等:
source /opt/ros/foxy/setup.bash
根据需要获取本地⼯作空间(也可以导⼊ ROS):
source /path/to/ws/install/local_setup.bash
别名bady
如何快速导⼊这些环境呢?
别名是⾃定义定义的命令缩写。
只需输⼊ source_foxy(或希望的任何字符串)⽽不是 source /opt/ros/foxy/setup.bash (或希望的任何命令)有关语法,请参阅官⽅⽂档。
ROS_DOMAIN_ID
环境变量
每台机器的唯⼀标识符号
物理隔离⽹络
停⽌ROS2节点⼲扰
⼀劳永逸:echo "export ROS_DOMAIN_ID=<your_id>" >> ~/.bashrc
编译 ROS2(回顾)
colcon build --symlink-install
C:\ros_ws\webots_ros2>colcon build
[2.178s] root DEBUG Using proactor: IocpProactor Starting >>> control_msgs
Starting >>> controller_manager_msgs
Starting >>> vision_msgs
Starting >>> realtime_tools
Starting >>> ros2_control_test_assets
Starting >>> dynamixel_sdk
Starting >>> webots_ros2_ur_e_description
Starting >>> ackermann_msgs
Finished <<< webots_ros2_ur_e_description [5.11s] Starting >>> angles
Finished <<< ros2_control_test_assets [7.39s] Starting >>> turtlebot3_description
Finished <<< dynamixel_sdk [8.98s]
Starting >>> turtlebot3_node
Finished <<< angles [7.53s]
Starting >>> dynamixel_sdk_custom_interfaces Finished <<< turtlebot3_description [7.91s]
Starting >>> turtlebot3_cartographer
Finished <<< turtlebot3_cartographer [7.69s]
Starting >>> turtlebot3_example
Finished <<< realtime_tools [23.6s]
Starting >>> turtlebot3_navigation2
Finished <<< turtlebot3_example [5.89s]
Starting >>> turtlebot3_teleop
Finished <<< turtlebot3_node [20.3s]
Starting >>> webots_ros2_importer
Finished <<< turtlebot3_navigation2 [11.0s]
Starting >>> turtlebot3_bringup
Finished <<< ackermann_msgs [35.2s]
Finished <<< controller_manager_msgs [36.6s] Finished <<< turtlebot3_teleop [7.88s]
Finished <<< webots_ros2_importer [7.44s]
乱世佳人主题曲原唱《飘》Finished <<< vision_msgs [39.6s]
Starting >>> webots_ros2_msgs
Finished <<< turtlebot3_bringup [5.92s]
Starting >>> turtlebot3
Finished <<< dynamixel_sdk_custom_interfaces [28.8s] Starting >>> dynamixel_sdk_examples
Finished <<< control_msgs [43.3s]
Starting >>> hardware_interface
Finished <<< turtlebot3 [5.70s]
Finished <<< dynamixel_sdk_examples [8.50s] Finished <<< hardware_interface [15.6s]awk nf指的是
Starting >>> controller_interface
Starting >>> transmission_interface
Finished <<< webots_ros2_msgs [20.9s]
Starting >>> webots_ros2_core
Starting >>> webots_ros2_driver
Finished <<< webots_ros2_core [4.45s]
极简python快速入门教程Starting >>> webots_ros2_abb
Starting >>> webots_ros2_universal_robot
Starting >>> webots_ros2_epuck
Starting >>> webots_ros2_examples
Starting >>> webots_ros2_mavic
Finished <<< transmission_interface [15.8s]
Starting >>> webots_ros2_tesla
Finished <<< controller_interface [18.1s]
Starting >>> controller_manager
Finished <<< webots_ros2_abb [12.0s]
Finished <<< webots_ros2_universal_robot [11.9s] Starting >>> webots_ros2_tiago
Starting >>> webots_ros2_tiago
Starting >>> webots_ros2_tutorials
Finished <<< webots_ros2_examples [11.9s]
Finished <<< webots_ros2_epuck [12.2s]
Starting >>> webots_ros2_demos
Finished <<< webots_ros2_mavic [17.3s]
Finished <<< webots_ros2_driver [49.4s]
Finished <<< webots_ros2_tiago [34.5s]
Finished <<< webots_ros2_tesla [37.1s]
Finished <<< webots_ros2_tutorials [34.5s]
Finished <<< webots_ros2_demos [31.5s]
Finished <<< controller_manager [48.0s]
Starting >>> forward_command_controller
Starting >>> joint_state_broadcaster
Starting >>> diff_drive_controller
Starting >>> webots_ros2_control
Starting >>> force_torque_sensor_broadcaster
Starting >>> imu_sensor_broadcaster
Starting >>> joint_trajectory_controller
Starting >>> ros2controlcli
Finished <<< ros2controlcli [9.67s]
Starting >>> gripper_controllers
[143.592s] lcon_ake.build WARNING Could not run installation step for package 'gripper_controllers' because it has no 'install' target --- stderr: gripper_controllers
CMake Warning :5 (message):
gripper controllers are not available on OSX or Windows
---
Finished <<< gripper_controllers [5.92s]
Starting >>> ros2_control
阿迪达斯marqueeboost
Finished <<< joint_state_broadcaster [25.6s]
搭建web服务器实验报告Starting >>> joint_state_controller
Finished <<< forward_command_controller [26.8s]
Starting >>> effort_controllers
Finished <<< force_torque_sensor_broadcaster [26.9s]
Finished <<< ros2_control [10.9s]
Starting >>> position_controllers
Starting >>> velocity_controllers
Finished <<< imu_sensor_broadcaster [28.1s]
Finished <<< diff_drive_controller [29.3s]
Finished <<< webots_ros2_control [29.5s]
Starting >>> webots_ros2_turtlebot
Finished <<< joint_trajectory_controller [32.0s]
Finished <<< webots_ros2_turtlebot [11.7s]
Starting >>> webots_ros2
Finished <<< joint_state_controller [19.0s]
Finished <<< effort_controllers [21.8s]
Finished <<< position_controllers [21.2s]
Finished <<< velocity_controllers [21.2s]
Starting >>> ros2_controllers
Finished <<< webots_ros2 [11.6s]
Finished <<< ros2_controllers [5.81s]
Summary: 53 packages finished [3min 1s]
1 package had stderr output: gripper_controllers
C:\ros_ws\webots_ros2>
基本命令结构
为简单起见,只讲解⼆进制安装包附带的默认包。
所有 ROS2 命令都遵循以下语法:
ros2 <main_command> <sub_command> <<arguments>>实例 :
ros2 pkg list
ros2 pkg executables
使⽤ Tab 补全完成命令,或查看可⽤选项列表。
⽰例:
ros2 tab tab - 列出所有 ROS2 命令。
ros2 pkg tab tab - pkg 的⼦命令列表。
-h ⼏乎可以在任何时候获得简短的帮助说明。
ros2 -h
ros2 pkg -h
ros2 pkg executable -h
发布者和订阅者
这是最基础的ROS⽰例,必须掌握。
发布者
ROS 最基本的例⼦——发布者/订阅者
记得导⼊ROS2环境。
命令启动在包中的可执⾏⽂件(C++ 编译对象/Python 脚本):
ros2 run <package_name> <executable_name> <<optional_command_line_arguments>> *注意空格
尝试使⽤ ROS2 默认的⽰例启动发布者节点。
⾸先需要出包的名称。
使⽤过滤器运⾏包列表命令:
ros2 pkg list | grep demo
接下来通过运⾏到可以使⽤的可⽤可执⾏⽂件:
ros2 pkg executables demo_nodes_cpp
运⾏这些可执⾏⽂件之⼀ - 发布者:
ros2 run demo_nodes_cpp talker
观察 ROS 2 运⾏时系统到⽬前为⽌的状态...

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。