流程:
1.创建工作空间
mkdir catkin_ws
cd catkin_ws
mkdir src
cd src
catkin_init_workspace
2编译工作空间
cd ~/catkin_ws/
catkin_make
catkin_make install
首先对ROS进行创建一个元功能包
3.设置环境变量
source devel/setup.bash
source devel/setup.bash
4.创建功能包
cd ~/catkin_ws/src
catkin_create_pkg test_pkg std_msgs rospy roscpp
5将C++中的include lib src都复制到新创建的功能包下
最主要的是对CMakeLists.txt进行重新编辑
原来的CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(coffee_robot)
set(CMAKE_CXX_STANDARD 14)include_directories(${CMAKE_SOURCE_DIR} ./include)# 生成可执行文件add_executable(coffee_robot ./src/main.cpp./src/Robot.cpp./src/cJSON.c)
target_link_libraries(coffee_robot ${CMAKE_SOURCE_DIR}/lib/libFaAo.so ${CMAKE_SOURCE_DIR}/lib/libRobotContorl.so -lpthread)
${CMAKE_SOURCE_DIR}/lib/libFaAo.so ${CMAKE_SOURCE_DIR}/lib/libRobotContorl.so -lpthread)
新的CMakeLists.txt
include_directories(${CMAKE_SOURCE_DIR}/coffee_robot/include/coffee_robot)# # 生成可执行文件add_executable(coffee_robot ${CMAKE_SOURCE_DIR}/coffee_robot/src/main.cpp${CMAKE_SOURCE_DIR}/coffee_robot/src/Robot.cpp${CMAKE_SOURCE_DIR}/coffee_robot/src/cJSON.c)
target_link_libraries(coffee_robot ${CMAKE_SOURCE_DIR}/coffee_robot/lib/libFaAo.so${CMAKE_SOURCE_DIR}/coffee_robot/lib/libRobotContorl.so -lpthread)
注意
ROS中创建功能包的时候创建了CMakeLists.txt,所以这个路径是表示${CMAKE_SOURCE_DIR}功能包的CMakeLists.txt,所以要进到节点下的应该这么用
${CMAKE_SOURCE_DIR}/coffee_robot/src/main.cpp
所以你移动过来的CMakeLists.txt应该都加上你的目录
不知道大家看懂了麻 ,说白了是路径的问题