# my_common **Repository Path**: robotics_top/my_common ## Basic Information - **Project Name**: my_common - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: wuxi - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-09-02 - **Last Updated**: 2024-09-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README moying_comm =================================================== # Prerequisites * Ubuntu 18.04 * ROS Melodic * catkin_tools * protobuf 3.0.0 * zmq 4.3.2(download form github,checkout v4.3.2 tag,then build) # Installation * Download as normal catkin package (TODO: test on flash installed machine) * Install missing catkin_packages (TODO: auto install from rosdep) * Catkin build (catkin_make is not suggested) * build zmq zmq编译步骤: ``` cd libzmq ./autogen.sh ./configure --enable-static --with-pic make sudo make install ``` # Examples & Tutorials * 以下讲解基本用法,大体上与ROS message类似,在各个package中创建一个proto文件夹,在其中创建.proto文件。 * 示例代码中有两个测试包(pk1: moying_comm_lib_test)和(pk2: moying_comm_lib_external_test) * 其中pk1中创建有.proto数据类型,pk2则没有创建新的proto数据类型,而是直接使用pk1中的proto数据 ## 1. Workspace Structure 使用Protobuf时请保证如下结构,可以把proto文件夹理解为ROS的msg文件夹: --ws  --src   --pk1    --include     --pk1      --your_header_files.h    --proto     --your_proto_files.proto    --src     --your_srouce_files.cpp   --pk2    --include     --pk2      --your_header_files.h    --src     --your_srouce_files.cpp ## 2. CMakeLists 在CMakeLists中当注意以下几点: ### pk1:``moying_comm_lib_test`` 需要创建新proto类型的包 1. ``catkin_create_pkg``时需依赖``moying_comm_lib``。 2. 在``add_library()``之前,添加以下代码,须确保proto文件夹置于正确位置并包含.proto文件,类似于ROS的msg文件夹,``add_library``中除了本身需要加入的cpp文件外还需要加入``${proto_cc_files}``,``target_link_libraries``中需额外添加``${Protobuf_LIBRARIES}``。 ``` include(${moying_comm_lib_INCLUDE_DIRS}/../cmake/GenerateProtoFiles.cmake) generate_cpp_pb_files() add_library(${PROJECT_NAME} ${proto_cc_files} ) target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${Protobuf_LIBRARIES}) ``` 3. 当前包的``add_executable``所对应的``target_link_libraries``需额外添加``${Protobuf_LIBRARIES}``和``${PROJECT_NAME}``。 ``` target_link_libraries(${PROJECT_NAME}_pub ${catkin_LIBRARIES} ${Protobuf_LIBRARIES} ${PROJECT_NAME} ) ``` ### pk2:``moying_comm_lib_external_test`` 不需要创建新proto类型的包 1. ``catkin_create_pkg``时需依赖proto所在的包pk1,在例子中为``moying_comm_lib_test``。 2. ``target_link_libraries``中添加``${Protobuf_LIBRARIES}``。 ``` target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${Protobuf_LIBRARIES} ) ``` ## 3. 头文件包含 - 包含moying_comm库文件 ``` #include ``` - 包含protobuf相关文件,其中第二行格式为``/.pb.h`` ``` #include "google/protobuf/text_format.h" #include "moying_comm_lib_test/packet.pb.h" ``` ## 4. 测试 1. 同一个package测试 ``` rosrun moying_comm_lib_test moying_comm_lib_test_pub rosrun moying_comm_lib_test moying_comm_lib_test_sub ``` 2. 不同packages测试 ``` rosrun moying_comm_lib_test moying_comm_lib_test_pub rosrun moying_comm_lib_external_test moying_comm_lib_test_sub ``` # 亲们,开始玩耍吧