Skip to content

Commit

Permalink
fix: bagtrans options bugs (AimRT#49)
Browse files Browse the repository at this point in the history
* CI: change build worlflow image tag from v20240927 to latest

* fix:  fix bagtrans tool support

- Add AIMRT_BUILD_BAGTRANS option in CMakeLists.txt
- Update build.bat, build.sh, test.bat and test.sh scripts to include bagtrans build option
- Modify CMakeLists.txt in bagtrans directory to simplify build logic
- Remove autopep8 dependency from bagtrans/requirements.txt

* format : format the code

* fix: Turn off the bagtrans compilation option on Windows

* feat(tools): Update bagtrans tool build method

- Change the build method of bagtrans tool from PyInstaller to using the build module to generate wheel files
- Update CMakeLists.txt and setup.py files to adapt to the new build method
- Update release notes, adding new information about the bagtrans tool

* fix: format

---------

Co-authored-by: yuguanlin <yuguanlin@agibot.com>
  • Loading branch information
yglsaltfish and yuguanlin authored Oct 24, 2024
1 parent 25c8b2e commit 42ba5be
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 20 deletions.
22 changes: 21 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ option(AIMRT_BUILD_EXAMPLES "AimRT build examples." OFF)
option(AIMRT_BUILD_DOCUMENT "AimRT build document." OFF)
option(AIMRT_BUILD_RUNTIME "AimRT build runtime." ON)
option(AIMRT_BUILD_CLI_TOOLS "AimRT build aimrt command line tools." OFF)
option(AIMRT_BUILD_BAGTRANS "AimRT build bagtrans tool." OFF)

option(AIMRT_BUILD_PYTHON_RUNTIME "AimRT build python runtime." OFF)

Expand Down Expand Up @@ -206,6 +207,21 @@ if(AIMRT_BUILD_RUNTIME)
endif()
endif()

if(AIMRT_BUILD_BAGTRANS)
include(CheckPythonPackage)
check_python_package(build BUILD_FOUND)
check_python_package(wheel WHEEL_FOUND)
check_python_package(setuptools SETUPTOOLS_FOUND)

if(NOT BUILD_FOUND
OR NOT WHEEL_FOUND
OR NOT SETUPTOOLS_FOUND)
set(AIMRT_BUILD_BAGTRANS OFF)
message(WARNING "Can not find build, wheel or setuptools in your python environment, will not compile bagtrans tool!")
message(WARNING "try to install build, wheel and setuptools by `pip3 install build wheel setuptools --upgrade`")
endif()
endif()

if(AIMRT_BUILD_NET_PLUGIN)
include(GetBoost)
endif()
Expand Down Expand Up @@ -287,7 +303,11 @@ if(AIMRT_INSTALL
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" --build \"${CMAKE_BINARY_DIR}\" --config ${CMAKE_BUILD_TYPE} --target create_python_pkg)")
endif()

if(AIMRT_BUILD_ROS2_PLUGIN AND AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN)
if(AIMRT_INSTALL
AND AIMRT_BUILD_WITH_ROS2
AND AIMRT_BUILD_ROS2_PLUGIN
AND AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN
AND AIMRT_BUILD_BAGTRANS)
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" --build \"${CMAKE_BINARY_DIR}\" --config ${CMAKE_BUILD_TYPE} --target bagtrans)")
endif()

Expand Down
1 change: 1 addition & 0 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cmake -B build ^
-DAIMRT_BUILD_DOCUMENT=ON ^
-DAIMRT_BUILD_RUNTIME=ON ^
-DAIMRT_BUILD_CLI_TOOLS=ON ^
-DAIMRT_BUILD_BAGTRANS=OFF ^
-DAIMRT_BUILD_PYTHON_RUNTIME=ON ^
-DAIMRT_USE_FMT_LIB=ON ^
-DAIMRT_BUILD_WITH_PROTOBUF=ON ^
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cmake -B build \
-DAIMRT_BUILD_DOCUMENT=ON \
-DAIMRT_BUILD_RUNTIME=ON \
-DAIMRT_BUILD_CLI_TOOLS=ON \
-DAIMRT_BUILD_BAGTRANS=ON \
-DAIMRT_BUILD_PYTHON_RUNTIME=ON \
-DAIMRT_USE_FMT_LIB=ON \
-DAIMRT_BUILD_WITH_PROTOBUF=ON \
Expand Down
1 change: 1 addition & 0 deletions document/sphinx-cn/release_notes/v0_9_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- 新增了第三方库 asio,runtime::core 不再引用 boost,改为引用独立的 asio 库,以减轻依赖;
- 修复 aimrt_py 多线程 rpc 调用 server 端概率性崩溃的问题;
- 为 aimrt_py 的 channel 功能提供了 Context 支持;
- 新增 bagtrans 命令行工具,用于将 使用 aimrt record_playback 插件录制的 bag 文件转换为 ros2 的 bag 文件;

**次要修改**
- 缩短了一些 examples 的文件路径长度;
Expand Down
20 changes: 11 additions & 9 deletions document/sphinx-cn/tutorials/cli_tool/bagtrans_tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@

## 简介

**bagtrans** 是一个 AimRT 官方提供的命令行工具,用于将 AimRT bag 文件转换为 ROS2 的 bag 文件,其中ros2 原生消息会直接转换,pb 消息会转换为 aimrt 提供的 ros2_plugin_proto 中的 RosMsgWrapper 消息类型。
**bagtrans** 是一个 AimRT 官方提供的命令行工具,目前可以将 AimRT **recordplayback** 插件记录的 bag 文件转换为 ROS2 的 bag 文件,其中ros2 原生消息会直接转换,pb 消息会转换为 aimrt 提供的 ros2_plugin_proto 中的 RosMsgWrapper 消息类型。

## 安装

**bagtrans** 工具是一个基于 Python 开发的小程序,并且依赖于 aimrt 提供的 ros2_plugin_protobuf 消息类型,通过以下步骤安装
**bagtrans** 工具是一个基于 Python 开发的小工具,并且依赖于 aimrt 提供的 ros2_plugin_protobuf 消息类型,需要按照以下步骤安装

1. 编译 aimrt 生成 ros2_plugin_proto

执行您 aimrt 源码库中的`build.sh`文件进行编译,可以在`build.sh`文件中关闭其他您不需要的 CMake 选项以加快编译,但是需要确保`AIMRT_BUILD_ROS2_PLUGIN``AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN` 选项为`ON`
1. 需要您的 python 环境中安装了 build、wheel 和 setuptools 包,如果未安装,可以使用以下命令安装:

```bash
pip3 install build wheel setuptools --upgrade
```

2. 在终端中执行以下命令:
2. 需要编译生成 aimrt 源码库中的 ros2_plugin_proto 消息类型,并且在 build.sh 文件中确保`AIMRT_BUILD_ROS2_PLUGIN``AIMRT_BUILD_RECORD_PLAYBACK_PLUGIN``AIMRT_BUILD_BAGTRANS` 选项为`ON`,执行您 aimrt 源码库中的`build.sh`文件进行编译,编译完成后,在 `<path_to_your_aimrt_src_code>/src/tools/bagtrans/build/dist` 文件夹下可找到编译生成的`whl`文件。

3. 在终端中执行以下命令:
```
cd <path_to_your_aimrt_src_code>/src/tools/bagtrans
python setup.py install
cd <path_to_your_aimrt_src_code>/src/tools/bagtrans/build/dist
pip3 install bagtrans-<version>-py3-none-any.whl
```

**bagtrans**工具将会自动安装到您的 python 环境中。使用 `pip list | grep bagtrans`可查看是否安装成功。可使用 `pip uninstall bagtrans`进行卸载。


## 使用说明

**bagtrans** 工具的使用方法如下:
Expand Down
2 changes: 1 addition & 1 deletion document/sphinx-cn/tutorials/cli_tool/cli_tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


## 安装
**aimrt_cli**工具是一个基于 Python 开发的小程序,有以下三种安装方式,请选择任意一种您喜欢的进行安装。
**aimrt_cli**工具是一个基于 Python 开发的小工具,有以下三种安装方式,请选择任意一种您喜欢的进行安装。


### 源码安装到 python 环境中
Expand Down
8 changes: 3 additions & 5 deletions src/tools/bagtrans/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ set(BAGTRANS_BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)

add_custom_target(
bagtrans
COMMAND ${PYTHON_EXECUTABLE} -m PyInstaller ${CMAKE_CURRENT_SOURCE_DIR}/bagtrans/bagtrans.spec
COMMAND ${Python3_EXECUTABLE} -m build --wheel --no-isolation -v
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "${PYTHON_EXECUTABLE} -m PyInstaller ${CMAKE_CURRENT_SOURCE_DIR}/bagtrans/bagtrans.spec"
COMMENT "${PYTHON_EXECUTABLE} -m build --wheel --no-isolation -v"
DEPENDS ${BAGTRANS_SRC_FILES})

add_custom_target(
Expand All @@ -24,9 +24,7 @@ add_custom_target(
COMMENT "Copying ROS2 files"
DEPENDS aimrt::plugins::ros2_plugin)

if(AIMRT_BUILD_WITH_ROS2 AND AIMRT_BUILD_ROS2_PLUGIN)
add_dependencies(bagtrans copy_ros2_plugin_proto_files_bagtrans)
endif()
add_dependencies(bagtrans copy_ros2_plugin_proto_files_bagtrans)

if(AIMRT_INSTALL)
install(
Expand Down
1 change: 0 additions & 1 deletion src/tools/bagtrans/bagtrans/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
# All rights reserved.

setuptools>=59.6.0
autopep8>=1.6.0
3 changes: 0 additions & 3 deletions src/tools/bagtrans/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
app='bagtrans',
version='0.0.1',
packages=find_packages(exclude=['test']),
install_requires=[
'pyinstaller>=6.1.0',
],
author='Yu Guanlin',
author_email='yuguanlin@agibot.com',
description='transfer aimrt bag file to ros2 bag file',
Expand Down
1 change: 1 addition & 0 deletions test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cmake -B build ^
-DAIMRT_BUILD_DOCUMENT=ON ^
-DAIMRT_BUILD_RUNTIME=ON ^
-DAIMRT_BUILD_CLI_TOOLS=ON ^
-DAIMRT_BUILD_BAGTRANS=OFF ^
-DAIMRT_BUILD_PYTHON_RUNTIME=ON ^
-DAIMRT_USE_FMT_LIB=ON ^
-DAIMRT_BUILD_WITH_PROTOBUF=ON ^
Expand Down
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cmake -B build \
-DAIMRT_BUILD_DOCUMENT=ON \
-DAIMRT_BUILD_RUNTIME=ON \
-DAIMRT_BUILD_CLI_TOOLS=ON \
-DAIMRT_BUILD_BAGTRANS=ON \
-DAIMRT_BUILD_PYTHON_RUNTIME=ON \
-DAIMRT_USE_FMT_LIB=ON \
-DAIMRT_BUILD_WITH_PROTOBUF=ON \
Expand Down

0 comments on commit 42ba5be

Please sign in to comment.