ROS自身话题也挺好的,不过暂时还不知道如何判断网络,因此,还是想换回tcp/udp通信。

但是发现通信时数据比较多,调查一下,发现ROS支持google的protoBuf。

先建立一个ROS的项目,方便后面我们测试。 然后建立两个包,一个用作tcp发送数据,一个用作接收。然后在解析protoBuf的内容,看看是否一致。

目录结构如下:

proto目录下只有一个文件,test.proto,名字可以随意起,但是后缀不能错。

文件内容如下:

syntax = "proto3";
package Ott;message  Oddometry{double p_x = 1;double p_y = 2;double p_z = 3;double o_x = 4;double o_y = 5;double o_z = 6;double o_w = 7;int32 flag = 8;
}

src目录下有一个CMakeLists.txt,内容如下:


# toplevel CMakeLists.txt for a catkin workspace
# catkin/cmake/toplevel.cmakecmake_minimum_required(VERSION 3.0.2)
project(testRosPB VERSION 0.0.1.1118)set(CATKIN_TOPLEVEL TRUE)# search for catkin within the workspace
set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")
execute_process(COMMAND ${_cmd}RESULT_VARIABLE _resOUTPUT_VARIABLE _outERROR_VARIABLE _errOUTPUT_STRIP_TRAILING_WHITESPACEERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _res EQUAL 0 AND NOT _res EQUAL 2)# searching fot catkin resulted in an errorstring(REPLACE ";" " " _cmd_str "${_cmd}")message(FATAL_ERROR "Search for 'catkin' in workspace failed (${_cmd_str}): ${_err}")
endif()# include catkin from workspace or via find_package()
if(_res EQUAL 0)set(catkin_EXTRAS_DIR "${CMAKE_SOURCE_DIR}/${_out}/cmake")# include all.cmake without add_subdirectory to let it operate in same scopeinclude(${catkin_EXTRAS_DIR}/all.cmake NO_POLICY_SCOPE)add_subdirectory("${_out}")
else()# use either CMAKE_PREFIX_PATH explicitly passed to CMake as a command line argument# or CMAKE_PREFIX_PATH from the environmentif(NOT DEFINED CMAKE_PREFIX_PATH)if(NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")if(NOT WIN32)string(REPLACE ":" ";" CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})else()set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})endif()endif()endif()# list of catkin workspacesset(catkin_search_path "")foreach(path ${CMAKE_PREFIX_PATH})if(EXISTS "${path}/.catkin")list(FIND catkin_search_path ${path} _index)if(_index EQUAL -1)list(APPEND catkin_search_path ${path})endif()endif()endforeach()# search for catkin in all workspacesset(CATKIN_TOPLEVEL_FIND_PACKAGE TRUE)find_package(catkin QUIETNO_POLICY_SCOPEPATHS ${catkin_search_path}NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)unset(CATKIN_TOPLEVEL_FIND_PACKAGE)if(NOT catkin_FOUND)message(FATAL_ERROR "find_package(catkin) failed. catkin was neither found in the workspace nor in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was sourced before.")endif()
endif()---------------------------------------------要去掉此行,下面是加入protobuf的支持--------------------------------------------
# use protobuf
include(FindProtobuf)
find_package(Protobuf REQUIRED COMPONENTS roscpp)
set(proto_dir ${PROJECT_SOURCE_DIR}/proto)
file(GLOB proto_files "${proto_dir}/*.proto")
catkin_destinations()
set(proto_gen_dir ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_INCLUDE_DESTINATION}/${PROJECT_NAME})
set(proto_gen_cpp_dir ${proto_gen_dir})
file(MAKE_DIRECTORY ${proto_gen_dir})
file(MAKE_DIRECTORY ${proto_gen_cpp_dir})
set(protogen_include_dirs ${proto_gen_cpp_dir}/../ ${proto_gen_python_dir})
# Create lists of files to be generated
set(proto_gen_cpp_files "")
foreach(proto_file ${proto_files})get_filename_component(proto_name ${proto_file} NAME_WE)list(APPEND proto_gen_cpp_files${proto_gen_cpp_dir}/${proto_name}.pb.h${proto_gen_cpp_dir}/${proto_name}.pb.cc)
endforeach(proto_file ${proto_files})# Run protoc and generate language-specific headers.
add_custom_command(OUTPUT ${proto_gen_cpp_files}COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --proto_path=${proto_dir} --cpp_out=${proto_gen_cpp_dir} ${proto_files}DEPENDS ${PROTOBUF_PROTOC_EXECUTABLE} ${proto_files}WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
set_source_files_properties(${proto_gen_cpp_files} PROPERTIES GENERATED TRUE)add_custom_target(${PROJECT_NAME}_generate_headersDEPENDS ${proto_gen_cpp_files}
)
# Create proto library for lining.
include_directories(${PROTOBUF_INCLUDE_DIR} ${PROTOBUF_INCLUDE_DIR}/../../)
add_library(${PROJECT_NAME}_proto ${proto_gen_cpp_files})
target_link_libraries(${PROJECT_NAME}_proto ${PROTOBUF_LIBRARY})
add_dependencies(${PROJECT_NAME}_proto ${PROJECT_NAME}_generate_headers)
---------------------------------------------要去掉此行,上面是加入protobuf的支持--------------------------------------------include_directories(include${catkin_INCLUDE_DIRS}${CATKIN_DEVEL_PREFIX}   #忘记是不是新加的了
)
catkin_workspace()

这样就可以把protobuf封装成一个动态库,后面的包都能利用上。

新建的两个包目录下都各只有一个cpp文件,先看main_sub.cpp,一看名字大家就都知道,这是订阅示例改的。不多说,先看代码。

#include "ros/ros.h"
#include "std_msgs/String.h"#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;   //用string带来后果,在pub中编译带来了问题。#include<sys/types.h>
#include<stdlib.h>
#include<winsock2.h>
#pragma comment(lib,"ws2_32.lib")#include "include/testRosPB/test.pb.h"   //注意,protobuf编译test.proto
,生成的文件int main(int argc, char **argv)
{if(argc != 3){printf("Usage:%s [ip] [port]\n",argv[0]);//return 0;   //简单测试不要了。}WSADATA ws;WSAStartup(MAKEWORD(2,2),&ws);//创建一个用来通讯的socketint sock = socket(AF_INET,SOCK_STREAM, 0);if(sock < 0){perror("socket");return 1;}//需要connect的是对端的地址,因此这里定义服务器端的地址结构体struct sockaddr_in server;server.sin_family = AF_INET;server.sin_port = htons(atoi("9962"));server.sin_addr.s_addr = inet_addr("127.0.0.1");   //本机测试int len = sizeof(struct sockaddr_in);if(connect(sock, (struct sockaddr*)&server, len) < 0 ){perror("connect");return 2;}//连接成功进行收数据
//开始准备,发送pb数据
char buf[80];Ott::Oddometry  ommm;
ommm.set_p_x(111);
ommm.set_p_y(222);
ommm.set_p_z(333);ommm.set_o_x(1);
ommm.set_o_y(2);
ommm.set_o_z(3);
ommm.set_o_w(4);
ommm.set_flag(5);//while(1)   //不用循环发送了,发一次就好。{string data;
ommm.SerializeToString(&data);
char *bts = new char[data.length()];
printf("data:  \n");
for(int i = 0; i < data.length(); i++)
{printf("%d ",data[i]);
}
printf("\n%d  %s",sizeof(Ott::Oddometry), data);
printf("\n%f  %f", ommm.p_x(), ommm.p_y());
strcpy(bts, data.c_str());int _s = send(sock, data.c_str(), sizeof(Ott::Oddometry ), 0);   //发送数据出去
printf("\nsend###");Ott::Oddometry  aa;
aa.ParseFromString(data);printf("\n%d  %s",sizeof(Ott::Oddometry), data);
printf("\n%f  %f\n", aa.p_x(), aa.p_y());}closesocket(sock);;return 0;
}

仅有cpp还不行,还要修改main_sub目录下的CMakeLists.txt文件

cmake_minimum_required(VERSION 3.0.2)
project(main_sub VERSION 0.0.1.1118)## 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)## 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 file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )## Generate added messages and services with any dependencies listed here
# generate_messages(
#   DEPENDENCIES
#   std_msgs  # Or other packages containing msgs
# )################################################
## Declare ROS dynamic reconfigure parameters ##
################################################## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
##   * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below
##     and list every .cfg file to be processed## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2.cfg
# )###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES main_sub
#  CATKIN_DEPENDS other_catkin_pkg
#  DEPENDS system_lib
)###########
## Build ##
############# Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(include${catkin_INCLUDE_DIRS}${CATKIN_DEVEL_PREFIX}                  #新加内容
)## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/main_sub.cpp
# )## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/main_sub_node.cpp)
add_executable(${PROJECT_NAME} main_sub.cpp)## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
#   ${catkin_LIBRARIES}
# )target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${PROTOBUF_LIBRARY} testRosPB_proto)
#链接库,新加内容,${PROTOBUF_LIBRARY} testRosPB_proto#############
## Install ##
############## all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# catkin_install_python(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# )## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
#   FILES_MATCHING PATTERN "*.h"
#   PATTERN ".svn" EXCLUDE
# )## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
#   # myfile1
#   # myfile2
#   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )#############
## Testing ##
############### Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_main_sub.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()## Add folders to be run by python nosetests
# catkin_add_nosetests(test)

文件修改内容都标出来了

再看main_pub.cpp

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "std_msgs/Bool.h"
#include "include/testRosPB/test.pb.h"    //前面编译的#include <winsock2.h>
#include <windows.h>
#pragma comment(lib,"ws2_32.lib")#include <string.h>
#include <iostream>
//using namespace std;int startup(int _port,const char* _ip)
{WSADATA ws;WSAStartup(MAKEWORD(2,2),&ws);int sock = socket(AF_INET, SOCK_STREAM, 0);if(sock < 0){perror("socket");exit(1);}struct sockaddr_in local;local.sin_family = AF_INET;local.sin_port = htons( _port);local.sin_addr.s_addr = inet_addr(_ip);int len = sizeof(local);if(bind(sock,(struct sockaddr*)&local , len) < 0){perror("bind");exit(2);}if(listen(sock, 5) < 0) //允许连接的最大数量为5{perror("listen");exit(3);}return sock;
}int main(int argc, char **argv)
{int listen_sock = startup(atoi("9962"),"127.0.0.1");//初始化
//用来接收客户端的socket地址结构体struct sockaddr_in remote;int len = sizeof(struct sockaddr_in);while(1){int sock = accept(listen_sock, (struct sockaddr*)&remote, &len);if(sock < 0){perror("accept");continue;}printf("get a client, ip:%s, port:%d\n",inet_ntoa(remote.sin_addr),ntohs(remote.sin_port));char buf[81];while(1){int _s = recv(sock, buf, sizeof(buf)-1,0);if(_s > 0){buf[_s] = 0;
//                printf("client:%s\n",buf);
printf("data:  %d\n", _s);
for(int i = 0; i < _s; i++)
{printf("%d ",buf[i]);
}buf[_s] = '\0';
printf("\n");
std::string data(buf, _s);
Ott::Oddometry  ommm;
ommm.ParseFromString(data);printf("\n%d  %s",sizeof(Ott::Oddometry), data);
printf("\n%f  %f\n", ommm.p_x(), ommm.p_y());}else{printf("client is quit!\n");break;}}}// 设置编码setlocale(LC_ALL,"");ros::init(argc, argv, "topic_pub_cpp");ros::NodeHandle n;// chatter 是我们要发布到的话题,也就是交换数据的缓冲池//ros::Publisher pubA = n.advertise<Ott::Oddometry>("aaaa", 1000);ros::Publisher pub = n.advertise<std_msgs::String>("chatter", 1000);std::string content = "Hello World!";std_msgs::String msgs;ros::Rate loop_rate(0.5);   // 0.5s执行一次循环int count = 0;while (ros::ok()){count ++;msgs.data = content + std::to_string(count);// ROS_INFO("Publish Topic [chatter]: %s", msgs.data.c_str());pub.publish(msgs);loop_rate.sleep();ros::spinOnce();        // 一个好习惯}return 0;
}

同样也要修改CMakeLists.txt

cmake_minimum_required(VERSION 3.0.2)
project(main_pub VERSION 0.0.1.1118)## 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)include(FindProtobuf)           #新加内容
find_package(Protobuf REQUIRED)  #新加内容## 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 file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )## Generate added messages and services with any dependencies listed here
# generate_messages(
#   DEPENDENCIES
#   std_msgs  # Or other packages containing msgs
# )################################################
## Declare ROS dynamic reconfigure parameters ##
################################################## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
##   * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below
##     and list every .cfg file to be processed## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2.cfg
# )###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES main_pub
#  CATKIN_DEPENDS other_catkin_pkg
#  DEPENDS system_lib
)###########
## Build ##
############# Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(include${catkin_INCLUDE_DIRS}${PROTOBUF_INCLUDE_DIR}   #新加内容${CATKIN_DEVEL_PREFIX}    #新加内容
)## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/main_pub.cpp
# )## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/main_pub_node.cpp)
add_executable(${PROJECT_NAME} main_pub.cpp)## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
#   ${catkin_LIBRARIES}
# )target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${PROTOBUF_LIBRARIES} testRosPB_proto)
#新加内容   ${PROTOBUF_LIBRARIES} testRosPB_proto
#############
## Install ##
############## all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# catkin_install_python(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# )## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
#   FILES_MATCHING PATTERN "*.h"
#   PATTERN ".svn" EXCLUDE
# )## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
#   # myfile1
#   # myfile2
#   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )#############
## Testing ##
############### Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_main_pub.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()## Add folders to be run by python nosetests
# catkin_add_nosetests(test)

都处理好之后,回到主目录下,执行cakin_make

成功后就可以测试了

注意生成了动态库 testRosPB_proto.dll 如果不想用roslaunch的方式启动,可以把它拷贝到exe文件的同级目录下,然后再运行exe

参考文献:

1 https://www.pudn.com/news/628f8317bf399b7f351e69d3.html

2 ros中使用protobuf的组织形式_heroacool的博客-CSDN博客

3 Ubuntu18下ROS使用Protobuf 共享内存实现节点通信 - 知乎

ROS中使用protoBuf通信相关推荐

  1. ROS中的分布式通信

    ROS是一个分布式的计算框架,一个运行中的ROS系统可以包含分布在多台计算机上多个节点.根据系统的配置方式,任何节点可能随时需要与任何其他节点进行通信. 要进行局域网通信首先我们需要通过路由器来进行组 ...

  2. ROS-CAN通信解析程序分析(ROS中进行CAN通信)

    CANALYST-II的linux版本通信解析程序 我们解析程序的先后顺便为: open,打开can卡: initcan,对can卡进行初始化: start,启动can通道: 就可以接收recive和 ...

  3. C#使用Protocol Buffer(ProtoBuf)进行Unity中的Socket通信

    From: http://www.jb51.net/article/82795.htm 这篇文章主要介绍了C#使用Protocol Buffer(ProtoBuf)进行Unity的Socket通信的实 ...

  4. ros中使用serial包实现串口通信

    一.Ubuntu下的串口助手cutecom 1.安装cutecom并打开: sudo apt-get install cutecom sudo cutecom 2.查看电脑链接的串口信息(名称): d ...

  5. 在网络通讯中应用Protobuf

    Protobuf的设计非常适用于在网络通讯中的数据载体,它序列化出来的数据量少再加上以K-V的方式来存储数据,对消息的版本兼容性非常强:还有一个比较大的优点就是有着很多的语言平台支持.下面讲解一下如何 ...

  6. Netty中集成Protobuf实现Java对象数据传递

    场景 Netty的Socket编程详解-搭建服务端与客户端并进行数据传输: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1086 ...

  7. ROS与Android的通信

    通过ROS-Bridge,建立起ROS与Android的通信. 代码为: sudo apt-get install ros-<rosdistro>-rosbridge-suite//下载R ...

  8. ROS基本概念 文件系统 创建ROS软件包 ROS中的一些命令

    ROS基本概念 文件系统 创建ROS软件包 ROS中的一些命令 ROS是什么 ROS文件系统 文件系统工具:rospack.roscd.rosls 创建ROS 软件包 catkin是什么 创建和构建一 ...

  9. ROS中阶笔记(十):ROS机器人综合应用

    ROS中阶笔记(十):ROS机器人综合应用 文章目录 1 ROS机器人综合应用 1.1 PR2 1.2 PR2实践 1.3 TurtleBot 1.3.1 TurtleBot2实践 1.3.2 Tur ...

最新文章

  1. 针对 AlloyFinger 中 currentTarget为空的解决方案
  2. 面试:说说你对 Java 中 final 的理解?
  3. 【Android 插件化】Hook 插件化框架 ( 从 Hook 应用角度分析 Activity 启动流程 一 | Activity 进程相关源码 )
  4. 【opencv系列01】OpenCV4.X介绍与安装
  5. 注意System.currentTimeMillis()潜在的性能问题
  6. 如何识别媒体偏见_描述性语言理解,以识别文本中的潜在偏见
  7. 快速构建网站或移动端页面:关于Bootstrap的学习笔记
  8. java mllib 算法_朴素贝叶斯算法原理及Spark MLlib实例(Scala/Java/Python)
  9. DB2的ErrorCode
  10. python高阶函数心得体会_Python高阶函数总结
  11. 26章 OOP:宏伟蓝图
  12. Directx11学习笔记【七】 游戏定时器的实现
  13. JavaWeb如何学?
  14. DICOM医学图像处理:基于DCMTK工具包学习和分析worklist
  15. 110KV/35KV/10KV富源变电站一次系统设计
  16. Microsoft.NET离线运行库合集
  17. Twitterrific for Mac(Twitter客户端)
  18. 使用google的jib, 发布Docker镜像到阿里云
  19. 用P、V操作解决进程同步问题的解题步骤
  20. 七年之痒,从小米6看小米公司的善与罪

热门文章

  1. 使用jQuery快速高效制作网页交互特效 第五章 上机练习四 制作广告图片轮播切换效果
  2. ospf(开放式最短路径优先协议)
  3. IT信息考证人,证书记得要延续 ITSS CISAW CISP PMP CISSP 证书延续 有效期
  4. JavaScript object移除
  5. zstuoj 4246 萌新吃果果
  6. 【干货】Markdown编辑博文,公式图片轻松搞定
  7. 2020年最好用的几个PHP开发工具推荐
  8. 快速排序与冒泡排序的效率对比
  9. ubuntu 下的开机启动项管理命令
  10. windows server2012R2 apache+mod_wsgi+django