網(wǎng)站建設(shè)模板型和定制型搜索引擎優(yōu)化seo專員招聘
?
博主跟隨古月居博客進(jìn)行ROS2學(xué)習(xí),對ROS2相關(guān)指令進(jìn)行了總結(jié),方便學(xué)習(xí)和回顧。
古月居ROS2博文鏈接:https://book.guyuehome.com/
本文會(huì)持續(xù)進(jìn)行更新,覺得有幫助的朋友可以點(diǎn)贊收藏。
1. ROS2安裝命令
$ sudo apt update && sudo apt install locales # 軟件源更新和安裝
$ sudo locale-gen en_US en_US.UTF-8 # 將ubuntu系統(tǒng)語言環(huán)境改為英文的UTF-8,防止出現(xiàn)中文亂碼
$ sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 # 更新Linux系統(tǒng)的本地化設(shè)置,特別是語言環(huán)境(locale)設(shè)置
$ export LANG=en_US.UTF-8 # 使當(dāng)前所使用的編碼格式生效
$ sudo apt update && sudo apt install curl gnupg lsb-release # 添加ROS2軟件源
$ sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg # 設(shè)置下載軟件源的密鑰
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null # 將軟件源添加到系統(tǒng)對應(yīng)的列表中
$ sudo apt update # 掃描ROS2對應(yīng)的軟件源位置
$ sudo apt upgrade # ubuntu軟件更新
$ sudo apt install ros-humble-desktop # 安裝ROS-humble桌面版
$ source /opt/ros/humble/setup.bash # ROS2安裝位置在終端中生效
$ echo " source /opt/ros/humble/setup.bash" >> ~/.bashrc # ROS2在所有終端中生效,到此步ROS2就安裝完成了
$ ros2 run demo_nodes_cpp talker # 開啟一個(gè)終端,打開talker節(jié)點(diǎn)
$ ros2 run demo_nodes_py listener # 開啟另一個(gè)終端,打開listener節(jié)點(diǎn),測試通信系統(tǒng)是否有問題
2. ROS2基本命令
$ ros2:彈出ROS2的相關(guān)指令
$ ros2 run turtlesim turtlesim_node:海龜仿真節(jié)點(diǎn)
$ ros2 run turtlesim turtle_teleop_key:海龜控制節(jié)點(diǎn)
$ ros2 node:彈出node相關(guān)指令
$ ros2 node list:查看當(dāng)前ROS2系統(tǒng)下的節(jié)點(diǎn)
$ ros2 node info /turtlesim :查看某個(gè)節(jié)點(diǎn)的具體信息
$ ros2 topic:彈出話題相關(guān)指令
$ ros2 topic list:查看當(dāng)前系統(tǒng)下的話題
$ ros2 topic echo /turtle1/pose :echo查看某個(gè)話題下的消息數(shù)據(jù)
$ 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}}":發(fā)布話題指令
$ ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}":發(fā)布服務(wù)請求,產(chǎn)生一只新海龜
$ ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "theta: 3":發(fā)布具體的動(dòng)作目標(biāo)
$ ros2 bag record /turtle1/cmd_vel:錄制動(dòng)作指令
$ ros2 bag play :復(fù)現(xiàn)動(dòng)作指令
$ ros2 run usb_cam usb_cam_node_exe # 相機(jī)驅(qū)動(dòng)節(jié)點(diǎn)
$ export ROS_DOMAIN_ID=<your_domain_id> # ROS2網(wǎng)絡(luò)分組指令
3. ROS2開發(fā)環(huán)境配置指令
$ sudo apt install git:Git下載
$ git clone https://gitee.com/guyuehome/ros2_21_tutorials.git:cloneROS2源碼
$ sudo dpkg -i code_1.95.1-1730355339_amd64.deb :vscode安裝(dpkg安裝.deb文件)
4. ROS2工作空間命令
$ mkdir -p ~/dev_ws/src # 新建文件夾
$ cd ~/dev_ws/src # 進(jìn)入src文件夾
$ git clone https://gitee.com/guyuehome/ros2_21_tutorials.git # 獲取ros2代碼包
$ sudo apt install -y python3-pip # 下載pip
$ sudo pip3 install rosdepc # 下載rosdepc工具
$ sudo rosdepc init # rosdepc初始化
$ rosdepc update # rosdepc更新
$ cd .. # 返回dev_ws目錄
$ rosdepc install -i --from-path src --rosdistro humble -y # 安裝代碼包依賴
$ sudo apt install python3-colcon-ros # 下載colcon編譯工具
$ cd ~/dev_ws/ # 進(jìn)入dev_ws目錄
$ colcon build # 編譯工作空間
$ source install/local_setup.sh # 僅在當(dāng)前終端生效
$ echo " source ~/dev_ws/install/local_setup.sh" >> ~/.bashrc # 所有終端均生效
5. ROS2功能包命令
$ ros2 pkg create --build-type <build-type> <package_name> # 創(chuàng)建一個(gè)功能包
$ ros2 pkg create --build-type ament_cmake learning_pkg_c # 創(chuàng)建C++版本的功能包
ros2 pkg create --build-type ament_python learning_pkg_python # 創(chuàng)建python版本功能包
$ colcon build # 編譯工作空間所有功能包
$ source install/local_setup.bash # 僅在當(dāng)前終端生效
$ echo " source ~/dev_ws/install/local_setup.sh" >> ~/.bashrc # 所有終端均生效注:install中的文件才是實(shí)際運(yùn)行的文件,所以在src中修改代碼后,必須通過編譯和配置環(huán)境變量,才能正常運(yùn)行修改后的代碼。
6. ROS2節(jié)點(diǎn)命令
$ ros2 node # 查看節(jié)點(diǎn)相關(guān)指令
$ ros2 node list # 查看節(jié)點(diǎn)列表
$ ros2 node info <node_name> # 查看節(jié)點(diǎn)信息
$ ros2 run learning_node node_helloworld # 運(yùn)行hello world節(jié)點(diǎn)
7. ROS2話題命令
$ ros2 ropic # 查看話題相關(guān)指令
$ ros2 topic list # 查看話題列表
$ ros2 topic info <topic_name> # 查看話題信息
$ ros2 topic hz <topic_name> # 查看話題發(fā)布頻率
$ ros2 topic bw <topic_name> # 查看話題傳輸帶寬
$ ros2 topic echo <topic_name> # 查看話題數(shù)據(jù)
$ ros2 topic pub <topic_name> <msg_type> <msg_data> # 發(fā)布話題消息
$ ros2 service find <type_name> # 查看某一個(gè)特殊類型的所有話題
8. ROS2服務(wù)命令
$ ros2 service # 查看服務(wù)相關(guān)指令
$ ros2 service list # 查看服務(wù)列表
$ ros2 service type <service_name> # 查看服務(wù)數(shù)據(jù)類型
$ ros2 service call <service_name> <service_type> <service_data> # 發(fā)送服務(wù)請求
$ ros2 service find <type_name> # 查看某一個(gè)特殊類型的所有服務(wù)
9. ROS2動(dòng)作命令
$ ros2 action # 查看話題相關(guān)指令
$ ros2 action list # 查看服務(wù)列表
$ ros2 action info <action_name> # 查看服務(wù)數(shù)據(jù)類型
$ ros2 action send_goal <action_name> <action_type> <action_data> # 發(fā)送服務(wù)請求
10. ROS2參數(shù)命令
$ ros2 param # 查看參數(shù)相關(guān)指令
$ ros2 param list # 查看參數(shù)列表
$ ros2 param get <node_name> <parameter_name> # 查看某個(gè)參數(shù)的數(shù)據(jù)類型和值
$ ros2 param set <node_name> <parameter_name> <value> # 設(shè)置對應(yīng)參數(shù)的值
$ ros2 param dump <node_name> # 查看節(jié)點(diǎn)中的所有參數(shù)的值
$ ros2 param load <node_name> <parameter_file> # 加載參數(shù)文件
$ ros2 param delete <node_name> <parameter_name> # 刪除節(jié)點(diǎn)的某個(gè)參數(shù)
$ ros2 param describe <node_name> <parameter_name> # 查看某個(gè)參數(shù)的描述性(具體)信息
?