1.创建工作空间:
yyw@yyw-vpc:~ cd catkin_ws/
yyw@yyw-vpc:~/catkin_ws cd src/
yyw@yyw-vpc:~/catkin_ws/src$ catkin_init_workspace
2.创建功能包:包名是test_pkg,依赖库:roscpp rospy std_msgs
yyw@yyw-vpc:~/catkin_ws/src catkin_make install(生成install文件)
3.将代码放到/catkin_ws/src/learning_topic/src目录下;
4.同时在/catkin_ws/src/learning_topic/CMakeLists.txt中添加如下内容:
add_executable(velocity_publisher src/velocity_publisher.cpp)
target_link_libraries(velocity_publisher ${catkin_LIBRARIES})
5.编译工程
yyw@yyw-vpc:~/catkin_ws$ catkin_make
6.添加环境变量,让ROS系统找到相应文件(可以直接在home路径下的.bashrc添加环境变量路径:/home/yyw/catkin_ws/devel/setup.bash ,使用control+H显示隐藏文件)
yyw@yyw-vpc:~/catkin_ws echo $ROS_PACKAGE_PATH
/home/yyw/catkin_ws/src:/opt/ros/melodic/share