1,使用C++编写需要安装serial包
serial工具包,下载完成后按照提示编译安装,默认使用
make install
会将ROS编译工程需要的serial.h头文件和serialConfig.cmake等全部必要的文件移动到/tmp/usr/local…的目录下,因此在make install后,我们需要手动将这些移动到/usr/local的根目录下,否则构建节点时,会提示以下错误信息:
- can not found serial/serial.h
- serialConfig.cmake is not found
等其他问题,解决办法就是
sudo cp -r /tmp/usr/local/* /usr/local
然后重新加载bash的环境,
source ~/.bashrc
在编译即可。
如果还是提示缺少,那就把,/usr/local的路径添加到cmake编译的路径中去,使用export指令。
2,创建一个ros pkg
$ catkin_create_pkg getserial_data std_msgs rospy roscpp
2.1 编辑CMakeList.txt
可以参考我的CMakeList.txt文件。其中msg部分,mobileRobot_velocity.msg是与此无关的,mobileRobot_msgs.msg是存放编码起信息的数据结构,如下所示:
cmake_minimum_required(VERSION 2.8.3)
project(getodomdata_serial)
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
nav_msgs
std_msgs
geometry_msgs
tf
message_generation
serial
)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()
################################################
## Declare ROS messages, services and actions ##
################################################
## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend tag for "message_generation"
## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
## but can be declared for certainty nonetheless:
## * add a exec_depend tag for "message_runtime"
## * In this fi