ros创建功能包和编译过程问题处理
文章目錄
- 1. 創建工作空間和功能包
- 2.新建cpp文件
- 3.修改CMakeLists.txt
- 4.編譯問題
- 4.1 Could NOT find rospy (missing: rospy_DIR)
- 5. 運行可執行文件
- 5.1 運行roscore的Resource not found: roslaunch的解決方法
- 5.2 Command 'rosrun' not found問題
- 5.3 執行可執行文件
1. 創建工作空間和功能包
參考添加鏈接描述
2.新建cpp文件
在創建的功能包helloworld/src下創建helloworld.cpp文件,內容如下:
//1.包含ros的頭文件 #include "ros/ros.h"//2.編寫main函數 int main(int argc, char * argv[]){//3.初始化ros節點ros::init(argc,argv,"hello_node");//4.輸出日志ROS_INFO("hello wordld!");return 0; }3.修改CMakeLists.txt
修改helloworld/CMakeLists.txt文件,修改前后的對比圖如下
總結修改有幾點,在build部分
(1) 找到add_executable()去掉前面的注釋,并把此函數第1個參數(節點名)改為hw(可根據需要修改),第2個參數改為新建的cpp文件,比如helloworld.cpp。
(2) 找到target_link_libraries(),并去掉注釋,并把此函數第1個參數改為hw,和add_executable()第1個參數名字保持一樣。
下面就開始編譯
4.編譯問題
在catkin_ws下用catkin_make命令編譯
4.1 Could NOT find rospy (missing: rospy_DIR)
解決方案:find_package()函數注釋掉第3個參數rospy的引用
5. 運行可執行文件
5.1 運行roscore的Resource not found: roslaunch的解決方法
具體信息:
... logging to /home/kandi/.ros/log/8e9b6ac4-b602-11ec-96b9-7fb5732bd610/roslaunch-ubuntu-2120.log Checking log directory for disk usage. This may take awhile. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB.Resource not found: roslaunch ROS path [0]=/opt/ros/noetic/share/ros ROS path [1]=/home/kandi/catkin_ws/src ROS path [2]=/opt/ros/noetic/share The traceback for the exception was written to the log file根據回憶,之前運行roscore是沒問題的,中間在處理編譯問題的時候按照了下面的軟件:sudo apt-get install python3-roslaunch
解決方法:
sudo apt-get install ros-noetic-roslaunch
換成noetic對應的版本即可。
5.2 Command ‘rosrun’ not found問題
具體報錯信息:
Command 'rosrun' not found, but can be installed with:sudo apt install rosbash解決方法:重新安裝ros版本
sudo apt install ros-noetic-desktop-full
5.3 執行可執行文件
命令行終端先運行roscore啟動master階段,再在另一個終端執行可執行文件,生成的可執行文件在~/catkin_ws/devel/lib/helloworld目錄下
有兩種運行方法,到可行性文件所在目錄:
(1) rosrun命令:rosrun helloworld hw,其中helloworld是功能包名,hw是節點名(也就是可執行文件名)
(2) 直接執行:./hw。
總結
以上是生活随笔為你收集整理的ros创建功能包和编译过程问题处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ROS坐标系
- 下一篇: ROS集成开发环境搭建