Ubuntu18.04系统, ROS(melodic)源码安装第三方包及入门例程测试
mkdir -p catkin_ws/src #创建工作区
cd catkin_ws/ #进入工作区
catkin_make #会报错
rm CMakeLists.txt #解决方法删除CMakeLists.txt
catkin_make #重新make
cd src #进入src目录
git clone https://github.com/andreasgustavsson/find_moving_objects #把源码放在src下
cd .. #进入上级目录
catkin_make #编译源码包, 这个包有个错误,需要将`find_moving_objects/bank.cpp`代码740行改为`abs(int(width_in_points - object_width_in_points))`,即增加一个强制转换
catkin_make #重新编译
source ~/catkin_ws/devel/setup.bash #激活环境
rospack list | grep find #可以看到编译好的包了
roslaunch find[tab]_moving_objects [tab][tab] rviz[tab] #可以运行例子了
# 再试一次
mkdir -p catkin_ws1/src #创建工作区
cd catkin_ws1/ #进入工作区
catkin_make #没有报错
source devel/setup.bash #激活环境
cd src #进入src目录
catkin_create_pkg agitr #创建一个包agitr
vim src/agitr/hello.cpp #新建cpp源码文件
vim src/agitr/CMakeLists.txt #修改脚本文件
vim src/agitr/package.xml #修改包文件
cd ~/catkin_ws1/ #进入工作区
roscore #运行核心
source devel/setup.bash #再开一个终端, 激活环境
rosrun agitr hello #运行程序 打印"[ INFO] [1726301588.898624806]: Hello,ROS!"
//hello.cpp内容
#include <ros/ros.h>
int main (int argc,char ** argv){
ros::init (argc, argv,"hello_ros"); //hello和ros之间是下划线,如果写成空格会报错
ros::NodeHandle nh;
ROS_INFO_STREAM("Hello,ROS!");
}
<!-- agitr/package.xml内容,已经删除注释 -->
<?xml version="1.0"?>
<package format="2">
<name>agitr</name>
<version>0.0.0</version>
<description>The agitr package</description>
<maintainer email="ruixiaoliang@nuctech.com">ruixiaoliang</maintainer>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>geometry_msgs</build_depend>
<exec_depend>geometry_msgs</exec_depend>
<build_depend>turtlesim </build_depend>
<exec_depend>turtlesim </exec_depend>
<export>
</export>
</package>
cmake_minimum_required(VERSION 3.0.2)
project(agitr)
find_package(catkin REQUIRED)
find_package(catkin REQUIRED COMPONENTS roscpp)
catkin_package(
)
include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(hello hello.cpp)
target_link_libraries(hello ${catkin_LIBRARIES})