ros创建功能包和编译过程问题处理
文章目錄
- 1. 創(chuàng)建工作空間和功能包
- 2.新建cpp文件
- 3.修改CMakeLists.txt
- 4.編譯問(wèn)題
- 4.1 Could NOT find rospy (missing: rospy_DIR)
- 5. 運(yùn)行可執(zhí)行文件
- 5.1 運(yùn)行roscore的Resource not found: roslaunch的解決方法
- 5.2 Command 'rosrun' not found問(wèn)題
- 5.3 執(zhí)行可執(zhí)行文件
1. 創(chuàng)建工作空間和功能包
參考添加鏈接描述
2.新建cpp文件
在創(chuàng)建的功能包helloworld/src下創(chuàng)建helloworld.cpp文件,內(nèi)容如下:
//1.包含ros的頭文件 #include "ros/ros.h"//2.編寫main函數(shù) int main(int argc, char * argv[]){//3.初始化ros節(jié)點(diǎn)ros::init(argc,argv,"hello_node");//4.輸出日志ROS_INFO("hello wordld!");return 0; }3.修改CMakeLists.txt
修改helloworld/CMakeLists.txt文件,修改前后的對(duì)比圖如下
總結(jié)修改有幾點(diǎn),在build部分
(1) 找到add_executable()去掉前面的注釋,并把此函數(shù)第1個(gè)參數(shù)(節(jié)點(diǎn)名)改為hw(可根據(jù)需要修改),第2個(gè)參數(shù)改為新建的cpp文件,比如helloworld.cpp。
(2) 找到target_link_libraries(),并去掉注釋,并把此函數(shù)第1個(gè)參數(shù)改為hw,和add_executable()第1個(gè)參數(shù)名字保持一樣。
下面就開(kāi)始編譯
4.編譯問(wèn)題
在catkin_ws下用catkin_make命令編譯
4.1 Could NOT find rospy (missing: rospy_DIR)
解決方案:find_package()函數(shù)注釋掉第3個(gè)參數(shù)rospy的引用
5. 運(yùn)行可執(zhí)行文件
5.1 運(yùn)行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根據(jù)回憶,之前運(yùn)行roscore是沒(méi)問(wèn)題的,中間在處理編譯問(wèn)題的時(shí)候按照了下面的軟件:sudo apt-get install python3-roslaunch
解決方法:
sudo apt-get install ros-noetic-roslaunch
換成noetic對(duì)應(yīng)的版本即可。
5.2 Command ‘rosrun’ not found問(wèn)題
具體報(bào)錯(cuò)信息:
Command 'rosrun' not found, but can be installed with:sudo apt install rosbash解決方法:重新安裝ros版本
sudo apt install ros-noetic-desktop-full
5.3 執(zhí)行可執(zhí)行文件
命令行終端先運(yùn)行roscore啟動(dòng)master階段,再在另一個(gè)終端執(zhí)行可執(zhí)行文件,生成的可執(zhí)行文件在~/catkin_ws/devel/lib/helloworld目錄下
有兩種運(yùn)行方法,到可行性文件所在目錄:
(1) rosrun命令:rosrun helloworld hw,其中helloworld是功能包名,hw是節(jié)點(diǎn)名(也就是可執(zhí)行文件名)
(2) 直接執(zhí)行:./hw。
總結(jié)
以上是生活随笔為你收集整理的ros创建功能包和编译过程问题处理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: ROS坐标系
- 下一篇: ROS集成开发环境搭建