Skip to content

Commit 47b991e

Browse files
authored
Merge pull request #8 from AimRT/add_ros2_rpc_demo
Add ros2 rpc demo
2 parents 1ad7828 + 2d92ebd commit 47b991e

56 files changed

Lines changed: 1788 additions & 11 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ English | [中文](README.zh_CN.md)
88

99
## Sample List
1010

11-
| Sample | Description | Level |
12-
| :------------------------------- | :------------------------------------------------------------------------------------------------------------- | :----- |
13-
| [helloworld](./helloworld) | A simple example demonstrating how to use AimRT framework | :star: |
14-
| [my_pb_channel](./my_pb_channel) | A simple example demonstrating publisher-subscriber communication using the Channel API with Protobuf messages | :star: |
15-
| [my_pb_rpc](./my_pb_rpc) | A simple example demonstrating client-server communication using the Rpc API with Protobuf messages | :star: |
11+
| Sample | Description | Level |
12+
| :----------------------------------- | :------------------------------------------------------------------------------------------------------------- | :----- |
13+
| [helloworld](./helloworld) | A simple example demonstrating how to use AimRT framework | :star: |
14+
| [my_pb_channel](./my_pb_channel) | A simple example demonstrating publisher-subscriber communication using the Channel API with Protobuf messages | :star: |
15+
| [my_ros2_channel](./my_ros2_channel) | A simple example demonstrating publisher-subscriber communication using the Channel API with ROS2 messages | :star: |
16+
| [my_pb_rpc](./my_pb_rpc) | A simple example demonstrating publisher-subscriber communication using the Rpc API with Protobuf messages | :star: |

README.zh_CN.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88

99
## 示例列表
1010

11-
| 示例 | 描述 | 难度 |
12-
| :------------ | :------------------------------------------------------------------------- | :----- |
13-
| helloworld | 一个简单的示例,展示如何使用 AimRT 框架 | :star: |
14-
| my_pb_channel | 一个简单的示例,展示如何使用 Channel API 和 Protobuf 消息进行发布-订阅通信 | :star: |
15-
| my_pb_rpc | 一个简单的示例,展示如何使用 RPC API 和 Protobuf 消息进行客户端-服务器通信 | :star: |
11+
| 示例 | 描述 | 级别 |
12+
| :----------------------------------- | :----------------------------------------------------------------------- | :----- |
13+
| [helloworld](./helloworld) | 演示如何使用 AimRT 框架的 app 模式的简单示例 | :star: |
14+
| [helloworld_pkg](./helloworld_pkg) | 演示如何使用 AimRT 框架的 pkg 模式的简单示例 | :star: |
15+
| [my_pb_channel](./my_pb_channel) | 演示使用 Channel API 进行发布者-订阅者通信的简单示例,使用 Protobuf 消息 | :star: |
16+
| [my_ros2_channel](./my_ros2_channel) | 演示使用 Channel API 进行发布者-订阅者通信的简单示例,使用 ROS2 消息 | :star: |
17+
| [my_pb_rpc](./my_pb_rpc) | 演示使用 Rpc API 进行发布者-订阅者通信的简单示例,使用 Protobuf 消息 | :star: |
18+
| [my_ros2_rpc](./my_ros2_rpc) | 演示使用 Rpc API 进行发布者-订阅者通信的简单示例,使用 ROS2 消息 | :star: |
19+
20+
## 贡献

helloworld_pkg/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (c) 2023, AgiBot Inc.
2+
# All rights reserved.
3+
4+
cmake_minimum_required(VERSION 3.24)
5+
6+
project(helloworld LANGUAGES C CXX)
7+
8+
# Set cmake path
9+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
10+
11+
# Some necessary settings
12+
set(CMAKE_CXX_STANDARD 20)
13+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
14+
set(CMAKE_CXX_EXTENSIONS OFF)
15+
16+
# Set default build type as Release
17+
if(NOT CMAKE_BUILD_TYPE)
18+
set(CMAKE_BUILD_TYPE Release)
19+
endif()
20+
21+
set(INSTALL_CONFIG_NAME ${PROJECT_NAME}-config)
22+
23+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
24+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
25+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
26+
27+
set(FETCHCONTENT_BASE_DIR ${CMAKE_SOURCE_DIR}/_deps)
28+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
29+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
30+
31+
# Include cmake module
32+
include(GetAimRT)
33+
34+
add_subdirectory(src)
35+
36+
if(AIMRT_SAMPLES_INSTALL)
37+
# Install
38+
install(
39+
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake
40+
DESTINATION ./
41+
FILES_MATCHING
42+
PATTERN "*.cmake")
43+
endif()

helloworld_pkg/README.md

Whitespace-only changes.

helloworld_pkg/build.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# exit on error and print each command
4+
set -e
5+
6+
if [ -d ./build/install ]; then
7+
rm -rf ./build/install
8+
fi
9+
10+
# cmake
11+
cmake -B build \
12+
-DCMAKE_BUILD_TYPE=Release \
13+
-DAIMRT_SAMPLES_INSTALL=ON \
14+
-DCMAKE_INSTALL_PREFIX=./build/install \
15+
$@
16+
17+
cmake --build build --config Release --target install --parallel $(nproc)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2023, AgiBot Inc.
2+
# All rights reserved.
3+
4+
include(FetchContent)
5+
6+
message(STATUS "get aimrt ...")
7+
8+
set(aimrt_DOWNLOAD_URL
9+
"https://github.com/AimRT/AimRT/archive/refs/tags/v1.0.0.tar.gz"
10+
CACHE STRING "")
11+
12+
if(aimrt_LOCAL_SOURCE)
13+
FetchContent_Declare(
14+
aimrt
15+
SOURCE_DIR ${aimrt_LOCAL_SOURCE}
16+
OVERRIDE_FIND_PACKAGE)
17+
else()
18+
FetchContent_Declare(
19+
aimrt
20+
URL ${aimrt_DOWNLOAD_URL}
21+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
22+
OVERRIDE_FIND_PACKAGE)
23+
endif()
24+
25+
# Wrap it in a function to restrict the scope of the variables
26+
function(get_aimrt)
27+
FetchContent_GetProperties(aimrt)
28+
if(NOT aimrt_POPULATED)
29+
set(AIMRT_BUILD_RUNTIME ON)
30+
31+
FetchContent_MakeAvailable(aimrt)
32+
endif()
33+
endfunction()
34+
35+
get_aimrt()

helloworld_pkg/src/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2023, AgiBot Inc.
2+
# All rights reserved.
3+
4+
add_subdirectory(module/helloworld_module)
5+
6+
add_subdirectory(pkg/helloworld_pkg)
7+
8+
add_custom_target(
9+
${PROJECT_NAME}_build_all ALL
10+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/install/bin ${CMAKE_BINARY_DIR}
11+
DEPENDS aimrt::runtime::main
12+
helloworld::helloworld_pkg)
13+
14+
# Install
15+
if(AIMRT_SAMPLES_INSTALL)
16+
install(
17+
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/install/bin
18+
DESTINATION .
19+
USE_SOURCE_PERMISSIONS)
20+
endif()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# AimRT core configuration
2+
aimrt:
3+
log: # log configuration
4+
core_lvl: INFO # core log level, options: Trace/Debug/Info/Warn/Error/Fatal/Off, case-insensitive
5+
backends: # log backends
6+
- type: console # print to console
7+
options:
8+
color: true # colored print
9+
- type: rotate_file # print to file and rotate
10+
options:
11+
path: ./log # log file path
12+
filename: helloworld.log # log file name
13+
max_file_size_m: 4 # log file max size, unit: MB
14+
max_file_num: 10 # max log file num, 0 means unlimited
15+
module:
16+
pkgs:
17+
- path: ./libhelloworld_pkg.so
18+
enable_modules: [HelloWorldModule]
19+
modules:
20+
- name: HelloWorldModule
21+
log_lvl: INFO
22+
23+
# Custom module configuration
24+
# the framework will generate a temporary configuration file for each module,
25+
# and the developer can get the configuration file path through the Configurator interface.
26+
HelloWorldModule:
27+
key1: val1
28+
key2: val2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
./aimrt_main --cfg_file_path=./cfg/helloworld_cfg.yaml
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Set target name
2+
set(CUR_TARGET_NAME "helloworld_module")
3+
4+
# Set file collection
5+
file(GLOB_RECURSE src ${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
6+
7+
# Add target
8+
add_library(${CUR_TARGET_NAME} STATIC)
9+
add_library(helloworld::${CUR_TARGET_NAME} ALIAS ${CUR_TARGET_NAME})
10+
11+
# Set source file of target
12+
target_sources(${CUR_TARGET_NAME} PRIVATE ${src})
13+
14+
# Set include path of target
15+
target_include_directories(
16+
${CUR_TARGET_NAME}
17+
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)
18+
19+
# Set link libraries of target
20+
target_link_libraries(
21+
${CUR_TARGET_NAME}
22+
PRIVATE yaml-cpp::yaml-cpp
23+
PUBLIC aimrt::interface::aimrt_module_cpp_interface)

0 commit comments

Comments
 (0)