diff --git a/document/sphinx-cn/tutorials/plugins/echo_plugin.md b/document/sphinx-cn/tutorials/plugins/echo_plugin.md index 05362d276..91a01ae86 100644 --- a/document/sphinx-cn/tutorials/plugins/echo_plugin.md +++ b/document/sphinx-cn/tutorials/plugins/echo_plugin.md @@ -8,7 +8,7 @@ ## 插件概述 -**echo_plugin**用于对 Channel 中的消息进行回显,插件支持独立的 type_support_pkg,并支持指定执行器。 +**echo_plugin**用于对 Channel 中的消息进行回显,插件支持独立的 type_support_pkg,并支持指定执行器, 必须设定 log_lvl 为 Trace,Debug,Info 之一才能正常工作。 插件的配置项如下: @@ -44,6 +44,10 @@ aimrt: - topic_name: test_topic msg_type: pb:aimrt.protocols.example.ExampleEventMsg echo_type: json + log: + core_lvl: Info # Trace/Debug/Info + backends: + - type: console executor: executors: - name: echo_executor @@ -67,6 +71,10 @@ aimrt: - topic_name: test_topic msg_type: pb:aimrt.protocols.example.ExampleEventMsg echo_type: json + log: + core_lvl: Info # Trace/Debug/Info + backends: + - type: console executor: executors: - name: echo_executor diff --git a/src/examples/plugins/CMakeLists.txt b/src/examples/plugins/CMakeLists.txt index c1efe166d..50280bf7d 100644 --- a/src/examples/plugins/CMakeLists.txt +++ b/src/examples/plugins/CMakeLists.txt @@ -24,12 +24,15 @@ if(AIMRT_BUILD_ICEORYX_PLUGIN) endif() if(AIMRT_BUILD_WITH_PROTOBUF + AND AIMRT_BUILD_WITH_ROS2 AND AIMRT_BUILD_NET_PLUGIN AND AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN) add_subdirectory(record_playback_plugin) endif() -if(AIMRT_BUILD_ECHO_PLUGIN) +if(AIMRT_BUILD_WITH_PROTOBUF + AND AIMRT_BUILD_WITH_ROS2 + AND AIMRT_BUILD_ECHO_PLUGIN) add_subdirectory(echo_plugin) endif() diff --git a/src/examples/plugins/echo_plugin/CMakeLists.txt b/src/examples/plugins/echo_plugin/CMakeLists.txt index d8bd8ef4e..524c75327 100644 --- a/src/examples/plugins/echo_plugin/CMakeLists.txt +++ b/src/examples/plugins/echo_plugin/CMakeLists.txt @@ -27,4 +27,4 @@ add_custom_target( COMMAND ${CMAKE_COMMAND} -E copy_directory ${CUR_INSTALL_SOURCE_DIR}/bin ${CMAKE_BINARY_DIR} DEPENDS aimrt::runtime::main # aimrt::examples::cpp::pb_chn::pb_chn_pub_pkg # - aimrt::examples::cpp::pb_chn::pb_chn_sub_pkg) + aimrt::examples::cpp::ros2_chn::ros2_chn_pub_pkg) diff --git a/src/examples/plugins/echo_plugin/README.md b/src/examples/plugins/echo_plugin/README.md index f330e4a84..f6dc8ba2e 100644 --- a/src/examples/plugins/echo_plugin/README.md +++ b/src/examples/plugins/echo_plugin/README.md @@ -15,19 +15,19 @@ 配置文件: -- [examples_plugins_echo_plugin_executor_cfg.yaml](./install/linux/bin/cfg/examples_plugins_echo_plugin_executor_cfg.yaml) +- [examples_plugins_echo_plugin_pb_executor_cfg.yaml](./install/linux/bin/cfg/examples_plugins_echo_plugin_pb_executor_cfg.yaml) 运行方式(linux): -- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_ECHO_PLUGIN` 选项编译 AimRT; -- 直接运行 build 目录下`start_examples_plugins_echo_plugin_executor_cfg.sh`脚本启动进程; +- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_WITH_ROS2` 、`AIMRT_BUILD_WITH_ECHO_PLUGIN` 选项编译 AimRT; +- 直接运行 build 目录下`start_examples_plugins_echo_plugin_pb_executor.sh`脚本启动进程; - 键入`ctrl-c`停止进程; 说明: - 此示例创建了以下模块: - `NormalPublisherModule`:会基于 `work_thread_pool` 执行器,以配置的频率、向配置的 topic 中发布 `ExampleEventMsg` 类型的消息; -- 此示例加载了 `example_event_ts_pkg`,其中提供了 `ExampleEventMsg` 类型的 type support 工具,作为回显时的序列化工具; +- 此示例加载了 `example_event_ts_pkg`,其中提供了 `ExampleEventMsg` 和 `RosTestMsg` 类型的 type support 工具,作为回显时的序列化工具; - 请注意,echo 插件的原理是向 AimRT 订阅指定的 Topic,因此需要在 channel 配置中为该 topic 设置合适的后端,以保证插件能接收到数据; @@ -35,7 +35,7 @@ 一个基于 **echo_plugin** 的回显消息示例,演示内容包括: - 如何在启动时加载 **echo_plugin**; -- 如何通过 curl 命令触发式回显指定 topic、msg 类型的数据; +- 如何回显指定 topic、msg 类型的数据; 核心代码: @@ -45,17 +45,48 @@ 配置文件: -- [examples_plugins_echo_plugin_cfg.yaml](./install/linux/bin/cfg/examples_plugins_echo_plugin_cfg.yaml) +- [examples_plugins_echo_plugin_pb_cfg.yaml](./install/linux/bin/cfg/examples_plugins_echo_plugin_pb_cfg.yaml) 运行方式(linux): -- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_NET_PLUGIN` 选项编译 AimRT; -- 直接运行 build 目录下`start_examples_plugins_echo_plugin_cfg.sh`脚本启动进程; +- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF` 、`AIMRT_BUILD_WITH_ROS2` 、`AIMRT_BUILD_WITH_ECHO_PLUGIN` 选项编译 AimRT; +- 直接运行 build 目录下`start_examples_plugins_echo_plugin_pb.sh`脚本启动进程; - 键入`ctrl-c`停止进程; 说明: - 此示例创建了以下模块: - `NormalPublisherModule`:会基于 `work_thread_pool` 执行器,以配置的频率、向配置的 topic 中发布 `ExampleEventMsg` 类型的消息; -- 此示例加载了 `example_event_ts_pkg`,其中提供了 `ExampleEventMsg` 类型的 type support 工具,作为回显时的序列化工具; +- 此示例加载了 `example_event_ts_pkg`,其中提供了 `ExampleEventMsg` 和 `RosTestMsg` 类型的 type support 工具,作为回显时的序列化工具; +- 请注意,echo 插件的原理是向 AimRT 订阅指定的 Topic,因此需要在 channel 配置中为该 topic 设置合适的后端,以保证插件能接收到数据; + + +## echo with ros2 msg + +一个基于 **echo_plugin** 的回显消息示例,演示内容包括: +- 如何在启动时加载 **echo_plugin**; +- 如何回显指定 topic、msg 类型的数据; +- 如何配置回显 ROS2 消息; + + +核心代码: +- [RosTestMsg.msg](../../../protocols/example_ros2/msg/RosTestMsg.msg) +- [normal_publisher_module.cc](../../cpp/ros2_chn/module/normal_publisher_module/normal_publisher_module.cc) +- [type_support_pkg_main.cc](./example_event_ts_pkg/type_support_pkg_main.cc) + + +配置文件: +- [examples_plugins_echo_plugin_ros2_cfg.yaml](./install/linux/bin/cfg/examples_plugins_echo_plugin_ros2_cfg.yaml) + + +运行方式(linux): +- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_WITH_ROS2` 、`AIMRT_BUILD_WITH_ECHO_PLUGIN` 选项编译 AimRT; +- 直接运行 build 目录下`start_examples_plugins_echo_plugin_ros2.sh`脚本启动进程; +- 键入`ctrl-c`停止进程; + + +说明: +- 此示例创建了以下模块: + - `NormalPublisherModule`:会基于 `work_thread_pool` 执行器,以配置的频率、向配置的 topic 中发布 `RosTestMsg` 类型的消息; +- 此示例加载了 `example_event_ts_pkg`,其中提供了 `ExampleEventMsg` 和 `RosTestMsg` 类型的 type support 工具,作为回显时的序列化工具; - 请注意,echo 插件的原理是向 AimRT 订阅指定的 Topic,因此需要在 channel 配置中为该 topic 设置合适的后端,以保证插件能接收到数据; diff --git a/src/examples/plugins/echo_plugin/example_event_ts_pkg/CMakeLists.txt b/src/examples/plugins/echo_plugin/example_event_ts_pkg/CMakeLists.txt index efd0a0e4f..928bb3094 100644 --- a/src/examples/plugins/echo_plugin/example_event_ts_pkg/CMakeLists.txt +++ b/src/examples/plugins/echo_plugin/example_event_ts_pkg/CMakeLists.txt @@ -30,9 +30,6 @@ target_link_libraries( aimrt::protocols::example_pb_gencode aimrt::interface::aimrt_module_ros2_interface example_ros2::example_ros2__rosidl_generator_cpp - example_ros2::example_ros2__rosidl_typesupport_cpp - example_ros2::example_ros2__rosidl_typesupport_fastrtps_cpp - example_ros2::example_ros2__rosidl_typesupport_introspection_cpp) - + example_ros2::example_ros2__rosidl_typesupport_cpp) # Set misc of target set_target_properties(${CUR_TARGET_NAME} PROPERTIES OUTPUT_NAME ${CUR_DIR}) diff --git a/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_pb_cfg.yaml b/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_pb_cfg.yaml index 90d2d6850..0cd0afca3 100644 --- a/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_pb_cfg.yaml +++ b/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_pb_cfg.yaml @@ -14,7 +14,7 @@ aimrt: msg_type: pb:aimrt.protocols.example.ExampleEventMsg echo_type: json log: - core_lvl: Info # Trace/Debug/Info/Warn/Error/Fatal/Off + core_lvl: Info # Trace/Debug/Info backends: - type: console executor: diff --git a/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_pb_executor_cfg.yaml b/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_pb_executor_cfg.yaml index 287102691..44650c221 100644 --- a/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_pb_executor_cfg.yaml +++ b/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_pb_executor_cfg.yaml @@ -15,7 +15,7 @@ aimrt: msg_type: pb:aimrt.protocols.example.ExampleEventMsg echo_type: json log: - core_lvl: Info # Trace/Debug/Info/Warn/Error/Fatal/Off + core_lvl: Info # Trace/Debug/Info backends: - type: console executor: diff --git a/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_ros2_cfg.yaml b/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_ros2_cfg.yaml index 67f6ccc0a..b4b70310b 100644 --- a/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_ros2_cfg.yaml +++ b/src/examples/plugins/echo_plugin/install/linux/bin/cfg/examples_plugins_echo_plugin_ros2_cfg.yaml @@ -20,7 +20,7 @@ aimrt: msg_type: ros2:example_ros2/msg/RosTestMsg echo_type: yaml log: - core_lvl: Info # Trace/Debug/Info/Warn/Error/Fatal/Off + core_lvl: Info # Trace/Debug/Info backends: - type: console executor: diff --git a/src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_pb_cfg.sh b/src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_pb.sh similarity index 100% rename from src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_pb_cfg.sh rename to src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_pb.sh diff --git a/src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_pb_executor_cfg.sh b/src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_pb_executor.sh similarity index 100% rename from src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_pb_executor_cfg.sh rename to src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_pb_executor.sh diff --git a/src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_ros2_cfg.sh b/src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_ros2.sh similarity index 100% rename from src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_ros2_cfg.sh rename to src/examples/plugins/echo_plugin/install/linux/bin/start_examples_plugins_echo_plugin_ros2.sh diff --git a/src/examples/plugins/record_playback_plugin/CMakeLists.txt b/src/examples/plugins/record_playback_plugin/CMakeLists.txt index d8bd8ef4e..9b0996a29 100644 --- a/src/examples/plugins/record_playback_plugin/CMakeLists.txt +++ b/src/examples/plugins/record_playback_plugin/CMakeLists.txt @@ -27,4 +27,6 @@ add_custom_target( COMMAND ${CMAKE_COMMAND} -E copy_directory ${CUR_INSTALL_SOURCE_DIR}/bin ${CMAKE_BINARY_DIR} DEPENDS aimrt::runtime::main # aimrt::examples::cpp::pb_chn::pb_chn_pub_pkg # - aimrt::examples::cpp::pb_chn::pb_chn_sub_pkg) + aimrt::examples::cpp::pb_chn::pb_chn_sub_pkg # + aimrt::examples::cpp::ros2_chn::ros2_chn_pub_pkg # + aimrt::examples::cpp::ros2_chn::ros2_chn_sub_pkg) diff --git a/src/examples/plugins/record_playback_plugin/README.md b/src/examples/plugins/record_playback_plugin/README.md index becadb31f..50da4fc4d 100644 --- a/src/examples/plugins/record_playback_plugin/README.md +++ b/src/examples/plugins/record_playback_plugin/README.md @@ -3,6 +3,7 @@ ## imd record +### pb 录包 一个基于 **record_playback_plugin** 的录包示例,演示内容包括: - 如何在启动时加载 **record_playback_plugin**; - 如何录制指定 topic、msg 类型的数据; @@ -21,7 +22,7 @@ 运行方式(linux): -- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_NET_PLUGIN`、`AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN` 选项编译 AimRT; +- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_WITH_ROS2`、`AIMRT_BUILD_NET_PLUGIN`、`AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN` 选项编译 AimRT; - 直接运行 build 目录下`start_examples_plugins_record_playback_plugin_record_imd.sh`脚本启动进程; - 键入`ctrl-c`停止进程; @@ -34,11 +35,39 @@ - 此示例创建了一个 `my_imd_record` 的录包 action,会在进程启动时立即开始录制指定的 topic 下的 msg,录制下来的包存放在进程同目录下的 `bag` 路径下; - 请注意,录包的原理是向 AimRT 订阅指定的 Topic,因此需要在 channel 配置中为该 topic 设置合适的后端,以保证录包插件能接收到数据; +### ros2 录包 +一个基于 **record_playback_plugin** 的录包示例,演示内容包括: +- 如何在启动时加载 **record_playback_plugin**; +- 如何录制 ROS2 消息; + +核心代码: +- [RosTestMsg.msg](../../../protocols/example_ros2/msg/RosTestMsg.msg) +- [normal_publisher_module.cc](../../cpp/ros2_chn/module/normal_publisher_module/normal_publisher_module.cc) +- [normal_subscriber_module.cc](../../cpp/ros2_chn/module/normal_subscriber_module/normal_subscriber_module.cc) +- [type_support_pkg_main.cc](./example_event_ts_pkg/type_support_pkg_main.cc) + + +配置文件: +- [examples_plugins_record_playback_plugin_record_ros2_imd_cfg.yaml](./install/linux/bin/cfg/examples_plugins_record_playback_plugin_record_ros2_imd_cfg.yaml) + + +运行方式(linux): +- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_WITH_ROS2`、`AIMRT_BUILD_NET_PLUGIN`、`AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN` 选项编译 AimRT; +- 直接运行 build 目录下`start_examples_plugins_record_playback_plugin_record_ros2_imd.sh`脚本启动进程; +- 键入`ctrl-c`停止进程; + + +说明: +- 此示例创建了以下两个模块: + - `NormalPublisherModule`:会基于 `work_thread_pool` 执行器,以配置的频率、向配置的 topic 中发布 `RosTestMsg` 类型的消息; + - `NormalSubscriberModule`:会订阅配置的 topic 下的 `RosTestMsg` 类型的消息; +- 此示例加载了 `example_event_ts_pkg`,其中提供了 `RosTestMsg` 类型的 type support 工具,作为录包时的序列化工具; +- 此示例创建了一个 `my_imd_record` 的录包 action,会在进程启动时立即开始录制指定的 topic 下的 msg,录制下来的包存放在进程同目录下的 `bag` 路径下; +- 请注意,录包的原理是向 AimRT 订阅指定的 Topic,因此需要在 channel 配置中为该 topic 设置合适的后端,以保证录包插件能接收到数据; ## signal record - 一个基于 **record_playback_plugin** 和 **net_plugin** 中 http 后端的通过信号触发录包的示例,演示内容包括: - 如何在启动时加载 **record_playback_plugin**; - 如何为 **record_playback_plugin** 提供的控制服务配置 http 后端; @@ -58,7 +87,7 @@ 运行方式(linux): -- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_NET_PLUGIN`、`AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN` 选项编译 AimRT; +- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_WITH_ROS2`、`AIMRT_BUILD_NET_PLUGIN`、`AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN` 选项编译 AimRT; - 直接运行 build 目录下`start_examples_plugins_record_playback_plugin_record_signal.sh`脚本启动进程; - 启动[tools](./install/linux/bin/tools)下的脚本并观察进程打印出来的日志: - 运行[record_playback_plugin_start_record.sh](./install/linux/bin/tools/record_playback_plugin_start_record.sh)脚本开始录制; @@ -95,7 +124,7 @@ 运行方式(linux): -- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_NET_PLUGIN`、`AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN` 选项编译 AimRT; +- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_WITH_ROS2`、`AIMRT_BUILD_NET_PLUGIN`、`AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN` 选项编译 AimRT; - 修改配置文件中 `bag_path` 项,改为希望播放的包的地址; - 直接运行 build 目录下`start_examples_plugins_record_playback_plugin_playback_imd.sh`脚本启动进程; - 键入`ctrl-c`停止进程; @@ -131,7 +160,7 @@ 运行方式(linux): -- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_NET_PLUGIN`、`AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN` 选项编译 AimRT; +- 开启 `AIMRT_BUILD_EXAMPLES`、`AIMRT_BUILD_WITH_PROTOBUF`、`AIMRT_BUILD_WITH_ROS2`、`AIMRT_BUILD_NET_PLUGIN`、`AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN` 选项编译 AimRT; - 修改配置文件中 `bag_path` 项,改为希望播放的包的地址; - 直接运行 build 目录下`start_examples_plugins_record_playback_plugin_playback_signal.sh`脚本启动进程; - 启动[tools](./install/linux/bin/tools)下的脚本并观察进程打印出来的日志: diff --git a/src/examples/plugins/record_playback_plugin/example_event_ts_pkg/CMakeLists.txt b/src/examples/plugins/record_playback_plugin/example_event_ts_pkg/CMakeLists.txt index 9ea547625..1b434408c 100644 --- a/src/examples/plugins/record_playback_plugin/example_event_ts_pkg/CMakeLists.txt +++ b/src/examples/plugins/record_playback_plugin/example_event_ts_pkg/CMakeLists.txt @@ -27,7 +27,10 @@ target_link_libraries( ${CUR_TARGET_NAME} PRIVATE aimrt::interface::aimrt_type_support_pkg_c_interface aimrt::interface::aimrt_module_protobuf_interface - aimrt::protocols::example_pb_gencode) + aimrt::protocols::example_pb_gencode + aimrt::interface::aimrt_module_ros2_interface + example_ros2::example_ros2__rosidl_generator_cpp + example_ros2::example_ros2__rosidl_typesupport_cpp) # Set misc of target set_target_properties(${CUR_TARGET_NAME} PROPERTIES OUTPUT_NAME ${CUR_DIR}) diff --git a/src/examples/plugins/record_playback_plugin/example_event_ts_pkg/type_support_pkg_main.cc b/src/examples/plugins/record_playback_plugin/example_event_ts_pkg/type_support_pkg_main.cc index 5ef39dffb..1eca903ec 100644 --- a/src/examples/plugins/record_playback_plugin/example_event_ts_pkg/type_support_pkg_main.cc +++ b/src/examples/plugins/record_playback_plugin/example_event_ts_pkg/type_support_pkg_main.cc @@ -5,10 +5,15 @@ #include "aimrt_module_protobuf_interface/util/protobuf_type_support.h" +#include "aimrt_module_ros2_interface/util/ros2_type_support.h" + +#include "example_ros2/msg/ros_test_msg.hpp" + #include "event.pb.h" static const aimrt_type_support_base_t* type_support_array[]{ - aimrt::GetProtobufMessageTypeSupport()}; + aimrt::GetProtobufMessageTypeSupport(), + aimrt::GetRos2MessageTypeSupport()}; extern "C" { diff --git a/src/examples/plugins/record_playback_plugin/install/linux/bin/cfg/examples_plugins_record_playback_plugin_record_ros2_imd_cfg.yaml b/src/examples/plugins/record_playback_plugin/install/linux/bin/cfg/examples_plugins_record_playback_plugin_record_ros2_imd_cfg.yaml new file mode 100644 index 000000000..3b9769cd8 --- /dev/null +++ b/src/examples/plugins/record_playback_plugin/install/linux/bin/cfg/examples_plugins_record_playback_plugin_record_ros2_imd_cfg.yaml @@ -0,0 +1,69 @@ +# Copyright (c) 2023, AgiBot Inc. +# All rights reserved. + +aimrt: + plugin: + plugins: + - name: ros2_plugin + path: ./libaimrt_ros2_plugin.so + options: + node_name: example_ros2msg_echo_plugin + executor_type: MultiThreaded # SingleThreaded/StaticSingleThreaded/MultiThreaded + executor_thread_num: 2 + - name: record_playback_plugin + path: ./libaimrt_record_playback_plugin.so + options: + type_support_pkgs: + - path: ./libexample_event_ts_pkg.so + record_actions: + - name: my_imd_record + options: + bag_path: ./bag + max_bag_size_m: 2048 + max_bag_num: 10 + mode: imd # imd/signal + executor: record_thread # require thread safe! + topic_meta_list: + - topic_name: test_topic + msg_type: ros2:example_ros2/msg/RosTestMsg + serialization_type: ros2 # optional + log: + core_lvl: INFO # Trace/Debug/Info/Warn/Error/Fatal/Off + backends: + - type: console + executor: + executors: + - name: work_thread_pool + type: asio_thread + options: + thread_num: 4 + - name: record_thread + type: simple_thread + channel: + backends: + - type: ros2 + pub_topics_options: + - topic_name: "(.*)" + enable_backends: [ros2] + sub_topics_options: + - topic_name: "(.*)" + enable_backends: [ros2] + module: + pkgs: + - path: ./libros2_chn_pub_pkg.so + enable_modules: [NormalPublisherModule] + - path: ./libros2_chn_sub_pkg.so + enable_modules: [NormalSubscriberModule] + modules: + - name: NormalPublisherModule + log_lvl: INFO + - name: NormalSubscriberModule + log_lvl: INFO + +# Module custom configuration +NormalPublisherModule: + topic_name: test_topic + channel_frq: 0.5 + +NormalSubscriberModule: + topic_name: test_topic diff --git a/src/examples/plugins/record_playback_plugin/install/linux/bin/start_examples_plugins_record_playback_plugin_record_imd.sh b/src/examples/plugins/record_playback_plugin/install/linux/bin/start_examples_plugins_record_playback_plugin_record_ros2_imd.sh similarity index 68% rename from src/examples/plugins/record_playback_plugin/install/linux/bin/start_examples_plugins_record_playback_plugin_record_imd.sh rename to src/examples/plugins/record_playback_plugin/install/linux/bin/start_examples_plugins_record_playback_plugin_record_ros2_imd.sh index d8cba5ae6..f336e1725 100755 --- a/src/examples/plugins/record_playback_plugin/install/linux/bin/start_examples_plugins_record_playback_plugin_record_imd.sh +++ b/src/examples/plugins/record_playback_plugin/install/linux/bin/start_examples_plugins_record_playback_plugin_record_ros2_imd.sh @@ -1,3 +1,3 @@ #!/bin/bash -./aimrt_main --cfg_file_path=./cfg/examples_plugins_record_playback_plugin_record_imd_cfg.yaml +./aimrt_main --cfg_file_path=./cfg/examples_plugins_record_playback_plugin_record_ros2_imd_cfg.yaml diff --git a/src/plugins/echo_plugin/echo_plugin.cc b/src/plugins/echo_plugin/echo_plugin.cc index 9d714a7e3..cfb20c9dd 100644 --- a/src/plugins/echo_plugin/echo_plugin.cc +++ b/src/plugins/echo_plugin/echo_plugin.cc @@ -23,9 +23,7 @@ struct convert { node["type_support_pkgs"].push_back(type_support_pkg_node); } - if (!rhs.executor.empty()) { - node["executor"] = rhs.executor; - } + node["executor"] = rhs.executor; node["topic_meta_list"] = Node(NodeType::Sequence); for (const auto& topic_meta : rhs.topic_meta_list) { @@ -173,7 +171,6 @@ bool EchoPlugin::Initialize(runtime::core::AimRTCore* core_ptr) noexcept { core_ptr_->RegisterHookFunc( runtime::core::AimRTCore::State::kPreShutdown, [this] { - Shutdown(); SetLogger(aimrt::logger::GetSimpleLoggerRef()); }); plugin_options_node = options_; @@ -218,14 +215,7 @@ void EchoPlugin::InitTypeSupport(Options::TypeSupportPkg& options) { void EchoPlugin::RegisterEchoChannel() { using namespace aimrt::runtime::core::channel; - using EchoFunc = std::function; - - struct Wrapper { - std::unordered_set require_cache_serialization_types; - std::vector echo_func_vec; - }; - - std::unordered_map echo_func_map; + using EchoFunc = std::function; const auto& topic_meta_list = topic_meta_map_; AIMRT_TRACE("Echo plugin has {} topics.", topic_meta_list.size()); @@ -235,52 +225,38 @@ void EchoPlugin::RegisterEchoChannel() { EchoFunc echo_func; if (options_.executor.empty()) { echo_func = [this, echo_type{topic_meta.echo_type}]( - uint64_t cur_timestamp, MsgWrapper& msg_wrapper) { + MsgWrapper& msg_wrapper) { Echo(msg_wrapper, echo_type); }; } else { echo_func = [this, echo_type{topic_meta.echo_type}]( - uint64_t cur_timestamp, MsgWrapper& msg_wrapper) { + MsgWrapper& msg_wrapper) { executor_.Execute([this, msg_wrapper{std::move(msg_wrapper)}, echo_type]() mutable { Echo(msg_wrapper, echo_type); }); }; } - auto& item = echo_func_map[topic_meta_itr.first]; - item.require_cache_serialization_types.emplace(topic_meta.serialization_type); - item.echo_func_vec.emplace_back(std::move(echo_func)); - } - AIMRT_TRACE("Register {} echo functions.", echo_func_map.size()); - - // subscribe - for (auto& echo_func_itr : echo_func_map) { - const auto& key = echo_func_itr.first; - auto& wrapper = echo_func_itr.second; - auto finditr = type_support_map_.find(key.msg_type); + auto finditr = type_support_map_.find(topic_meta.msg_type); + AIMRT_CHECK_ERROR_THROW(finditr != type_support_map_.end(), + "Can not find type '{}' in any type support pkg!", topic_meta.msg_type); const auto& type_support_ref = finditr->second; SubscribeWrapper sub_wrapper; sub_wrapper.info = TopicInfo{ - .msg_type = key.msg_type, - .topic_name = key.topic_name, + .msg_type = topic_meta.msg_type, + .topic_name = topic_meta.topic_name, .pkg_path = type_support_ref.options.path, .module_name = "core", .msg_type_support_ref = type_support_ref.type_support_ref}; - sub_wrapper.require_cache_serialization_types = wrapper.require_cache_serialization_types; - - sub_wrapper.callback = [echo_func_vec{std::move(wrapper.echo_func_vec)}]( + sub_wrapper.require_cache_serialization_types.emplace(topic_meta.serialization_type); + sub_wrapper.callback = [echo_func{std::move(echo_func)}]( MsgWrapper& msg_wrapper, std::function&& release_callback) { - auto cur_timestamp = aimrt::common::util::GetCurTimestampNs(); - - for (const auto& echo_func : echo_func_vec) - echo_func(cur_timestamp, msg_wrapper); - + echo_func(msg_wrapper); release_callback(); }; - bool ret = core_ptr_->GetChannelManager().Subscribe(std::move(sub_wrapper)); AIMRT_CHECK_ERROR_THROW(ret, "Subscribe failed!"); } @@ -301,9 +277,11 @@ void EchoPlugin::Echo(runtime::core::channel::MsgWrapper& msg_wrapper, std::stri msg_wrapper.info.msg_type, echo_type); return; } - if (buffer_view_ptr && buffer_view_ptr->Data() && buffer_view_ptr->Size() > 0) { + if (buffer_view_ptr->Size() == 1) { const char* data = static_cast(buffer_view_ptr->Data()[0].data); - AIMRT_INFO("\n{}\n---------------\n", std::string_view(data)); + AIMRT_INFO("\n{}\n---------------\n", std::string_view(data, buffer_view_ptr->Data()[0].len)); + } else if (buffer_view_ptr->Size() > 1) { + AIMRT_INFO("\n{}\n---------------\n", buffer_view_ptr->JoinToString()); } else { AIMRT_ERROR("Invalid buffer, topic_name: {}, msg_type: {}", msg_wrapper.info.topic_name, msg_wrapper.info.msg_type); } diff --git a/src/plugins/echo_plugin/topic_meta_key.h b/src/plugins/echo_plugin/topic_meta_key.h index 061414d54..0c748b4e6 100644 --- a/src/plugins/echo_plugin/topic_meta_key.h +++ b/src/plugins/echo_plugin/topic_meta_key.h @@ -25,7 +25,6 @@ struct TopicMetaKey { }; struct TopicMeta { - uint64_t id; std::string topic_name; std::string msg_type; std::string echo_type;