最近在写Ros的接口,接触了一段时间总结一下其中的心得。
Ros中publish或是subscriber多个Topic消息可以用一个RosHandle. subscriber的回调函数可以不是静态的!最后一个参数是实体的的指针, 如:
这句的效果,相当于iTest->FarkerMsgCallBack();所以可以不使用静态变量。如果是静态的,那后面不能再加参数了,否则编译不过(接口参数列表不匹配),现在看来这里有点像类成员函数指针。subscribe("VisionFace",1000,&CTest1::FarkerMsgCallback,&iTest1)
publish的时候也是一个情况,RosHandle可以用一个。pulbish一定得是通过设置频率,在while(ros::Ok())循环下执行。
如果不在这while循环里用频率的方式publish,在接收端会出现,半天收到一个情况。。。。(具体原因还有待观察)
如果想要偶尔发一次消息可以用service或是actionlib,用rosmake编译rospackage要注意cmakelist.txt文件是否包含了所有的cpp文件,下面是一个简单的cmakelist.txt文件:
Ros其实还是蛮简单的,官方的文档简介的也比较清楚。cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
# Set the build type. Options are:
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
# Debug : w/ debug symbols, w/o optimization
# Release : w/o debug symbols, w/ optimization
# RelWithDebInfo : w/ debug symbols, w/ optimization
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)
rosbuild_init()
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#uncomment if you have defined messages
#rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()
#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(example examples/example.cpp)
#target_link_libraries(example ${PROJECT_NAME})
rosbuild_add_executable(RosTestReceiver main.cpp)