Skip to content

Commit

Permalink
ROS 2 Jazzyへの対応 (#61)
Browse files Browse the repository at this point in the history
* fix "ROS_DISTRO"  of CI for Jazzy

* Add authors

* Update README for Jazzy

* Modify CI to ensure compatibility with the act tool

* Add messages of compiler version message for debug

* add ccache setting

* Set log level "debug" for CI

* comment out env for debug

* Replace  "ROS_REPO: [ros]" with "ROS_REPO: [main]" for CI of "ROS 2"

* Fix undefined behavior by storing `std::string` objects instead of `const char*` pointers
Previously, the test code for the 9-axis IMU was storing `const char*` pointers obtained from temporary `std::string` objects into a vector. Since these temporary `std::string` objects are destroyed immediately after the expression, the stored pointers became invalid (dangling pointers), leading to undefined behavior and causing tests to fail.
This commit fixes the issue by changing the vector to store *std::string* objects directly instead of `const char*` pointers. By maintaining the `std::string` objects, we ensure that the data remains valid throughout its usage, and any `c_str()` calls on these strings return valid pointers.

This change resolves the test failures and prevents potential crashes or incorrect data processing due to invalid memory access.

* Update copyright year
  • Loading branch information
KuraZuzu authored Oct 31, 2024
1 parent 806ca07 commit 9138e0d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 46 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/industrial_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ jobs:
industrial_ci:
strategy:
matrix:
env:
- { ROS_DISTRO: humble, ROS_REPO: ros, AFTER_SETUP_TARGET_WORKSPACE: 'apt update && apt install -y git' }
ROS_DISTRO: [jazzy]
ROS_REPO: [main]
AFTER_SETUP_TARGET_WORKSPACE: [apt update && apt install -y git gcc-11 g++-11]
# env:
# CCACHE_DIR: "${{ github.workspace }}/.ccache" # ccache directory for debug

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: "ros-industrial/industrial_ci@master"
env: ${{ matrix.env }}
env:
ROS_DISTRO: ${{matrix.ROS_DISTRO}}
ROS_REPO: ${{matrix.ROS_REPO}}
AFTER_SETUP_TARGET_WORKSPACE: ${{matrix.AFTER_SETUP_TARGET_WORKSPACE}}
BUILD_TOOL_ARGS: "--event-handlers console_direct+"
COLCON_LOG_LEVEL: debug
VERBOSE_OUTPUT: true
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

message(STATUS "CMake Version: ${CMAKE_VERSION}")
message(STATUS "C++ Compiler: ${CMAKE_CXX_COMPILER}")
message(STATUS "C++ Compiler Version: ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")

# find dependencies
find_package(ament_cmake REQUIRED)
Expand Down
45 changes: 17 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,45 @@

# rt_usb_9axisimu_driver

株式会社アールティが販売しているUSB出力9軸IMUセンサモジュール用のROS 2パッケージです。
[![industrial_ci](https://github.com/rt-net/rt_usb_9axisimu_driver/workflows/industrial_ci/badge.svg?branch=ros2-devel)](https://github.com/rt-net/rt_usb_9axisimu_driver/actions?query=workflow%3Aindustrial_ci+branch%3Aros2-devel)

株式会社アールティが販売しているUSB出力9軸IMUセンサモジュール用のROS 2パッケージです。

![usb-9axisimu](https://rt-net.github.io/images/usb-9axisimu/usb-9axisimu.png)

現在、以下のROSのディストリビューションに対応しております。
- Melodic ([`melodic-devel`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/melodic-devel))
- Noetic ([`noetic-devel`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/noetic-devel))
- Foxy ([`foxy-devel`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/foxy-devel))
- Humble ([`humble-devel`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/humble-devel))

| | industrial_ci | source build | amd64 binary | arm64 binary |
|:---:|:---:|:---:|:---:|:---:|
| main develop<br>([`master`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/master)) | [![industrial_ci](https://github.com/rt-net/rt_usb_9axisimu_driver/workflows/industrial_ci/badge.svg?branch=master)](https://github.com/rt-net/rt_usb_9axisimu_driver/actions?query=workflow%3Aindustrial_ci+branch%3Amaster) | - | - | - | - |
| ROS 2 develop<br>([`ros2-devel`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/ros2-devel)) | [![industrial_ci](https://github.com/rt-net/rt_usb_9axisimu_driver/workflows/industrial_ci/badge.svg?branch=ros2-devel)](https://github.com/rt-net/rt_usb_9axisimu_driver/actions?query=workflow%3Aindustrial_ci+branch%3Aros2-devel) | - | - | - | - |
| Bionic + Melodic<br>([`melodic-devel`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/melodic-devel)) | [![industrial_ci](https://github.com/rt-net/rt_usb_9axisimu_driver/workflows/industrial_ci/badge.svg?branch=melodic-devel)](https://github.com/rt-net/rt_usb_9axisimu_driver/actions?query=workflow%3Aindustrial_ci+branch%3Amelodic-devel) | [![Build Status](http://build.ros.org/job/Msrc_uB__rt_usb_9axisimu_driver__ubuntu_bionic__source/badge/icon)](http://build.ros.org/job/Msrc_uB__rt_usb_9axisimu_driver__ubuntu_bionic__source/) | [![Build Status](http://build.ros.org/view/Mbin_uB64/job/Mbin_uB64__rt_usb_9axisimu_driver__ubuntu_bionic_amd64__binary/badge/icon)](http://build.ros.org/view/Mbin_uB64/job/Mbin_uB64__rt_usb_9axisimu_driver__ubuntu_bionic_amd64__binary/) | [![Build Status](http://build.ros.org/job/Mbin_ubv8_uBv8__rt_usb_9axisimu_driver__ubuntu_bionic_arm64__binary/badge/icon)](http://build.ros.org/job/Mbin_ubv8_uBv8__rt_usb_9axisimu_driver__ubuntu_bionic_arm64__binary/) |
| Focal + Noetic<br>([`noetic-devel`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/noetic-devel)) | [![industrial_ci](https://github.com/rt-net/rt_usb_9axisimu_driver/workflows/industrial_ci/badge.svg?branch=noetic-devel)](https://github.com/rt-net/rt_usb_9axisimu_driver/actions?query=workflow%3Aindustrial_ci+branch%3Anoetic-devel) | - | - | - | - |
| Focal + Foxy<br>([`foxy-devel`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/foxy-devel)) | [![industrial_ci](https://github.com/rt-net/rt_usb_9axisimu_driver/workflows/industrial_ci/badge.svg?branch=foxy-devel)](https://github.com/rt-net/rt_usb_9axisimu_driver/actions?query=workflow%3Aindustrial_ci+branch%3Afoxy-devel) | [![Build Status](https://build.ros2.org/view/Fsrc_uF/job/Fsrc_uF__rt_usb_9axisimu_driver__ubuntu_focal__source/badge/icon)](https://build.ros2.org/view/Fsrc_uF/job/Fsrc_uF__rt_usb_9axisimu_driver__ubuntu_focal__source/) |[![Build Status](https://build.ros2.org/view/Fsrc_uF/job/Fbin_uF64__rt_usb_9axisimu_driver__ubuntu_focal_amd64__binary/badge/icon)](https://build.ros2.org/view/Fsrc_uF/job/Fbin_uF64__rt_usb_9axisimu_driver__ubuntu_focal_amd64__binary/) | [![Build Status](https://build.ros2.org/view/Fbin_ubv8_uFv8/job/Fbin_ubv8_uFv8__rt_usb_9axisimu_driver__ubuntu_focal_arm64__binary/badge/icon)](https://build.ros2.org/view/Fbin_ubv8_uFv8/job/Fbin_ubv8_uFv8__rt_usb_9axisimu_driver__ubuntu_focal_arm64__binary/) |
**TODO: Add Jammy + Humble**

- ROS 2 Humble ([`humble`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/humble))
- ROS 2 Jazzy ([`jazzy`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/jazzy))

## 1. 概要

rt_usb_9axisimu_driverは株式会社アールティが販売している
[USB出力9軸IMUセンサモジュール](https://www.rt-net.jp/products/9axisimu2/)
のROS 2パッケージです。
のROS 2パッケージです。

株式会社アールティによって開発、メンテナンスがなされています。

- License: [The 3-Clause BSD License](https://github.com/rt-net/rt_usb_9axisimu_driver/blob/master/LICENSE)

### 1.1 座標軸について

USB出力9軸IMUセンサモジュールは、センサとしてInvenSense社のMPU9250を使用しております。
USB出力9軸IMUセンサモジュールは、センサとしてInvenSense社のMPU9250を使用しております。
このセンサの磁気センサの座標系はNED座標系(x-north, y-east, z-down)ですが、
モジュール内のマイコン(LPC1343)においてENU座標系(x-east, y-north, z-up)に変換され、
ジャイロセンサおよび加速度センサの座標系と揃えられております。
ジャイロセンサおよび加速度センサの座標系と揃えられております。
これはROSで使われる座標系のルールにも適合しています。詳しくは、[REP-0103](http://www.ros.org/reps/rep-0103.html#axis-orientation)をご覧ください。

### 1.2 ファームウェア開発について

USB出力9軸IMUセンサモジュールはオープンハード・オープンソースのため、モジュール内のマイコンのファームウェアの変更が可能です。
USB出力9軸IMUセンサモジュールはオープンハード・オープンソースのため、モジュール内のマイコンのファームウェアの変更が可能です。
このROSパッケージはデフォルトのファームウェアにのみ対応しております。ファームウェアを変更された場合、正常な動作ができなくなる恐れがございますので、ご了承ください。

### 1.3 ver2.0でのご利用について

2020年8月現在、販売されているUSB出力9軸IMUセンサモジュールはver2.0となります。
このバージョンのデフォルトのファームウェアには、ASCII出力とBinary出力の2つのデータ出力形式があります。
センサ出荷時点ではASCII出力に設定されています。出力形式の切り替え方法は、以下のリポジトリにあるマニュアルをご参照ください。
2020年8月現在、販売されているUSB出力9軸IMUセンサモジュールはver2.0となります。
このバージョンのデフォルトのファームウェアには、ASCII出力とBinary出力の2つのデータ出力形式があります。
センサ出荷時点ではASCII出力に設定されています。出力形式の切り替え方法は、以下のリポジトリにあるマニュアルをご参照ください。
https://github.com/rt-net/RT-USB-9AXIS-00

### [ERROR] Error opening sensor device, please re-check your devices. が発生する場合
Expand All @@ -61,24 +53,21 @@ $ sudo chmod 666 /dev/ttyACM0

## 2. インストール


ROS Melodic等ROS 1のパッケージについては[`master`](https://github.com/rt-net/rt_usb_9axisimu_driver/tree/master)ブランチのREADMEをご覧ください。

### 2.1 バイナリをインストールする場合

```sh
# ROS 2 Foxy
$ sudo apt install ros-foxy-rt-usb-9axisimu-driver
# ROS 2 Humble
# ROS 2 Humble
$ sudo apt install ros-humble-rt-usb-9axisimu-driver
# ROS 2 Jazzy (ToDo)
$
```

### 2.2 ソースからインストールする場合

```sh
$ cd ~/ros2_ws/src
# Clone package & checkout ROS 2 branch
$ git clone -b $ROS_DISTRO-devel https://github.com/rt-net/rt_usb_9axisimu_driver
$ git clone -b $ROS_DISTRO https://github.com/rt-net/rt_usb_9axisimu_driver

# Install dependencies
$ rosdep install -r -y -i --from-paths .
Expand Down
3 changes: 2 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<maintainer email="[email protected]">RT Corporation</maintainer>
<author email="[email protected]">RT Corporation</author>
<author email="[email protected]">Yusuke Kato</author>
<author email="[email protected]">Kazushi Kurasawa</author>

<license>BSD</license>

Expand All @@ -29,4 +31,3 @@
<build_type>ament_cmake</build_type>
</export>
</package>

29 changes: 15 additions & 14 deletions test/test_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* License: BSD-3-Clause
*
* Copyright (c) 2015-2023 RT Corporation <[email protected]>
* Copyright (c) 2015-2024 RT Corporation <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -198,29 +198,30 @@ unsigned int create_dummy_ascii_imu_data(unsigned char *buf, bool is_invalid) {
unsigned int create_dummy_ascii_imu_data(unsigned char *buf, bool is_invalid,
double *gyro, double *acc, double *mag, double temp) {
rt_usb_9axisimu::Consts consts;
std::vector<const char*> dummy_ascii_imu_data(consts.IMU_ASCII_DATA_SIZE);
std::vector<std::string> dummy_ascii_imu_data(consts.IMU_ASCII_DATA_SIZE);
if (is_invalid) {
dummy_ascii_imu_data[consts.IMU_ASCII_TIMESTAMP] = "0.0";
} else {
dummy_ascii_imu_data[consts.IMU_ASCII_TIMESTAMP] = "0";
}
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_X] = double_to_string(gyro[0]).c_str();
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_Y] = double_to_string(gyro[1]).c_str();
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_Z] = double_to_string(gyro[2]).c_str();
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_X] = double_to_string(acc[0]).c_str();
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_Y] = double_to_string(acc[1]).c_str();
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_Z] = double_to_string(acc[2]).c_str();
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_X] = double_to_string(mag[0]).c_str();
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_Y] = double_to_string(mag[1]).c_str();
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_Z] = double_to_string(mag[2]).c_str();
dummy_ascii_imu_data[consts.IMU_ASCII_TEMP] = double_to_string(temp).c_str();
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_X] = double_to_string(gyro[0]);
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_Y] = double_to_string(gyro[1]);
dummy_ascii_imu_data[consts.IMU_ASCII_GYRO_Z] = double_to_string(gyro[2]);
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_X] = double_to_string(acc[0]);
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_Y] = double_to_string(acc[1]);
dummy_ascii_imu_data[consts.IMU_ASCII_ACC_Z] = double_to_string(acc[2]);
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_X] = double_to_string(mag[0]);
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_Y] = double_to_string(mag[1]);
dummy_ascii_imu_data[consts.IMU_ASCII_MAG_Z] = double_to_string(mag[2]);
dummy_ascii_imu_data[consts.IMU_ASCII_TEMP] = double_to_string(temp);
const char split_char = ',';
const char newline_char = '\n';
buf[0] = (unsigned char)newline_char;
unsigned int char_count = 1;
for(int i = 0; i < consts.IMU_ASCII_DATA_SIZE; i++) {
for(int j = 0; j < (int)strlen(dummy_ascii_imu_data.at(i)); j++) {
buf[char_count] = (unsigned char)dummy_ascii_imu_data.at(i)[j];
const char* data_str = dummy_ascii_imu_data.at(i).c_str();
for(int j = 0; j < (int)strlen(data_str); j++) {
buf[char_count] = (unsigned char)data_str[j];
char_count++;
}
if(i != consts.IMU_ASCII_DATA_SIZE - 1) buf[char_count] = (unsigned char)split_char;
Expand Down

0 comments on commit 9138e0d

Please sign in to comment.