Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RT-Thread Support #581

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions config/rtthread/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# README

## Overview

This file is the entry point for building micro-ROS apps for [RT-thread](https://github.com/RT-Thread/rt-thread). RT-Thread was born in 2006, it is an open source, neutral, and community-based real-time operating system (RTOS). Now, it It already supports many architectures and boards.

This project comes from [Open Source Promotion Plan](https://summer-ospp.ac.cn/#/org/prodetail/22f330436) (OSPP) 2022. The goal is to hope that micrROS can support RT-Thread real-time system.

Now,The publisher and subscriber can be used normally in the RT-Thread system through serial transport. The publisher is ok hrough UDP transport and The publisher has a little [problem](https://github.com/micro-ROS/micro_ros_setup/issues/576).

## Support

* board:
* [STMH750-ART-Pi](https://github.com/RT-Thread-Studio/sdk-bsp-stm32h750-realthread-artpi)

* transport:
* serial
* UDP
* examples:
* publisher
* subscriber

## Test Environment

* ROS 2 : galactic

* boards: [STMH750-ART-Pi](https://github.com/RT-Thread-Studio/sdk-bsp-stm32h750-realthread-artpi).

* RT-thread: v4.1.1
* example: ping_pong

## Usage

### Creating micro-ROS firmware

```bash
ros2 run micro_ros_setup create_firmware_ws.sh rtthread art-pi
```

### Configuring micro-ROS firmware

```bash
ros2 run micro_ros_setup configure_firmware.sh [app name] [options]
```

Available apps:

- `micro_ros_pub_int32.c`
- `micro_ros_sub_int32.c`
- `micro_ros_pub_sub_int32.c`
- `micro_ros_ping_pong.c`

available options:

- `-d` : agent string descriptor in a serial-like transport ;
- `-i ` agent IP in a network-like transport `-p` agent port in a network-like transport ;

for example:

```bash
# serial
ros2 run micro_ros_setup configure_firmware.sh micro_ros_pub_int32.c -d vcom
# UDP
ros2 run micro_ros_setup configure_firmware.sh micro_ros_pub_int32.c -i 192.168.31.130 -p 9999
```

### Building micro-ROS

```
ros2 run micro_ros_setup build_firmware.sh
```

### Flashing micro-ROS

```
ros2 run micro_ros_setup flash_firmware.sh
```

## Feature

* fix udp bug transport in publisher;
* add service demo;

9 changes: 9 additions & 0 deletions config/rtthread/dev_ros2_packages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
keep:
ament/ament_cmake
ament/ament_index
ament/ament_lint
ament/ament_package
ament/googletest
ament/osrf_pycommon
ament/uncrustify_vendor
ros2/ament_cmake_ros
1 change: 1 addition & 0 deletions config/rtthread/dev_uros_packages.repos
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repositories:
83 changes: 83 additions & 0 deletions config/rtthread/generic/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
. $PREFIX/config/utils.sh

MICROROS_DIR=$FW_TARGETDIR/sdk-bsp-stm32h750-realthread-artpi/projects/art_pi_wifi/micro-ROS-rtthread-app/microros
BUILD_DIR=$MICROROS_DIR/build
RTTHREAD_DIR=$FW_TARGETDIR/sdk-bsp-stm32h750-realthread-artpi/projects/art_pi_wifi
COLCON_META=$FW_TARGETDIR/mcu_ws/colcon.meta

X_CC=$FW_TARGETDIR/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gcc
X_CXX=$FW_TARGETDIR/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-g++
CFLAGS_INTERNAL="-mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O2 -gdwarf-2 -g -std=c99"
CXXFLAGS_INTERNAL="-mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O2 -gdwarf-2 -g"

#Set up the cross-compilation chain
ESCAPED_CFLAGS_INTERNAL=$(echo $CFLAGS_INTERNAL | sed 's/\//\\\//g' | sed 's/"//g')
ESCAPED_CXXFLAGS_INTERNAL=$(echo $CXXFLAGS_INTERNAL | sed 's/\//\\\//g' | sed 's/"//g')
ESCAPED_X_CC=$(echo $X_CC | sed 's/\//\\\//g' | sed 's/"//g')
ESCAPED_X_CXX=$(echo $X_CXX | sed 's/\//\\\//g' | sed 's/"//g')

cat $MICROROS_DIR/toolchain.cmake.in | \
sed "s/@CMAKE_C_COMPILER@/$ESCAPED_X_CC/g" | \
sed "s/@CMAKE_CXX_COMPILER@/$ESCAPED_X_CXX/g" | \
sed "s/@CFLAGS@/$ESCAPED_CFLAGS_INTERNAL/g" | \
sed "s/@CXXFLAGS@/$ESCAPED_CXXFLAGS_INTERNAL/g" \
> $MICROROS_DIR/toolchain.cmake

#for rtthread
sed -i "27c EXEC_PATH =r'$FW_TARGETDIR\/gcc-arm-none-eabi-5_4-2016q3\/bin\/'" $RTTHREAD_DIR/rtconfig.py


pushd $FW_TARGETDIR/mcu_ws >/dev/null
rm -rf build install log

colcon build \
--merge-install \
--packages-ignore-regex=.*_cpp \
--metas ${COLCON_META} \
--cmake-args \
"--no-warn-unused-cli" \
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=OFF \
-DTHIRDPARTY=ON \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTING=OFF \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_TOOLCHAIN_FILE=$MICROROS_DIR/toolchain.cmake \
-DCMAKE_VERBOSE_MAKEFILE=ON \


mkdir -p $FW_TARGETDIR/libmicroros; cd $FW_TARGETDIR/libmicroros;

for file in $(find $FW_TARGETDIR/mcu_ws/install/lib/ -name '*.a'); do \
folder=$(echo $file | sed -E "s/(.+)\/(.+).a/\2/"); \
mkdir -p $folder; cd $folder; ar x $file; \
for f in *; do \
mv $f ../$folder-$f; \
done; \
cd ..; rm -rf $folder; \
done ; \
ar rc libmicroros.a $(ls *.o *.obj 2> /dev/null); mkdir -p $BUILD_DIR; cp libmicroros.a $BUILD_DIR; \
cp -R $FW_TARGETDIR/mcu_ws/install/include $BUILD_DIR/; \
cd ..; rm -rf libmicroros;
popd >/dev/null

# build for rtthread
# modify build/rmw/types.h
pushd $BUILD_DIR >/dev/null
if ([ -d include ]); then

sed -i 's/# define RMW_DECLARE_DEPRECATED(name, msg) name __attribute__((deprecated(msg)))/# define RMW_DECLARE_DEPRECATED(name, msg) name/g' include/rmw/types.h

fi
popd >/dev/null
# build for rtthread
pushd $RTTHREAD_DIR >/dev/null

scons --target=vsc
scons

echo "build successful."
echo "Using project: $RTTHREAD_DIR"

popd >/dev/null


47 changes: 47 additions & 0 deletions config/rtthread/generic/client-colcon.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"names": {
"tracetools": {
"cmake-args": [
"-DTRACETOOLS_DISABLED=ON",
"-DTRACETOOLS_STATUS_CHECKING_TOOL=OFF"
]
},
"rosidl_typesupport": {
"cmake-args": [
"-DROSIDL_TYPESUPPORT_SINGLE_TYPESUPPORT=ON"
]
},
"rcl": {
"cmake-args": [
"-DBUILD_TESTING=OFF",
"-DRCL_COMMAND_LINE_ENABLED=OFF",
"-DRCL_LOGGING_ENABLED=OFF"
]
},
"rcutils": {
"cmake-args": [
"-DENABLE_TESTING=OFF",
"-DRCUTILS_NO_FILESYSTEM=ON",
"-DRCUTILS_NO_THREAD_SUPPORT=ON",
"-DRCUTILS_AVOID_DYNAMIC_ALLOCATION=ON",
"-DRCUTILS_NO_64_ATOMIC=ON"
]
},
"microxrcedds_client": {
"cmake-args": [
"-DUCLIENT_PIC=OFF",
"-DUCLIENT_PROFILE_DISCOVERY=OFF"
]
},
"rmw_microxrcedds": {
"cmake-args": [
"-DRMW_UXRCE_MAX_NODES=1",
"-DRMW_UXRCE_MAX_PUBLISHERS=5",
"-DRMW_UXRCE_MAX_SUBSCRIPTIONS=5",
"-DRMW_UXRCE_MAX_SERVICES=1",
"-DRMW_UXRCE_MAX_CLIENTS=1",
"-DRMW_UXRCE_MAX_HISTORY=4"
]
}
}
}
47 changes: 47 additions & 0 deletions config/rtthread/generic/client_uros_packages.repos
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
repositories:
eProsima/Micro-CDR:
type: git
url: https://github.com/eProsima/Micro-CDR.git
version: foxy
eProsima/Micro-XRCE-DDS-Client:
type: git
url: https://github.com/eProsima/Micro-XRCE-DDS-Client.git
version: foxy

# MicroROS
uros/rcl:
type: git
url: https://github.com/micro-ROS/rcl
version: galactic
uros/rclc:
type: git
url: https://github.com/ros2/rclc
version: galactic
uros/micro_ros_utilities:
type: git
url: https://github.com/micro-ROS/micro_ros_utilities
version: galactic
uros/rcutils:
type: git
url: https://github.com/micro-ROS/rcutils
version: galactic
uros/micro_ros_msgs:
type: git
url: https://github.com/micro-ROS/micro_ros_msgs.git
version: galactic
uros/rmw_microxrcedds:
type: git
url: https://github.com/micro-ROS/rmw-microxrcedds.git
version: galactic
uros/rosidl_typesupport:
type: git
url: https://github.com/micro-ROS/rosidl_typesupport.git
version: galactic
uros/rosidl_typesupport_microxrcedds:
type: git
url: https://github.com/micro-ROS/rosidl_typesupport_microxrcedds.git
version: galactic
uros/tracetools:
type: git
url: https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing.git/
version: galactic
86 changes: 86 additions & 0 deletions config/rtthread/generic/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
. $PREFIX/config/utils.sh

function help {
echo "Configure script need an argument."
echo "app -d|--dev device"
echo "app -i|--ip IP -p|--port port"
}

# if [ "$UROS_AGENT_DEVICE" ]; then
# echo $UROS_AGENT_DEVICE

# elif [ "$UROS_AGENT_IP" ] && [ "$UROS_AGENT_PORT" ]; then
# echo $UROS_AGENT_IP
# echo $UROS_AGENT_PORT
# else
# help

# fi
# exit 1

update_meta "microxrcedds_client" "UCLIENT_PROFILE_CUSTOM_TRANSPORT=ON"
update_meta "microxrcedds_client" "UCLIENT_PROFILE_STREAM_FRAMING=ON"
update_meta "microxrcedds_client" "UCLIENT_PROFILE_SERIAL=OFF"
update_meta "microxrcedds_client" "UCLIENT_PROFILE_UDP=OFF"
update_meta "microxrcedds_client" "UCLIENT_PROFILE_TCP=OFF"

update_meta "rmw_microxrcedds" "RMW_UXRCE_TRANSPORT=custom"

# add macro definition for cconfig.h
RTT_PROJECT=$FW_TARGETDIR/sdk-bsp-stm32h750-realthread-artpi/projects/art_pi_wifi
RTCONIF=rtconfig.h

pushd $RTT_PROJECT >/dev/null



if [ "$UROS_AGENT_DEVICE" ]; then
# modify rtconfig.h
UROS_AGENT_DEVICE="${UROS_AGENT_DEVICE}"
cp micro-ROS-rtthread-app/rtconfig.h $RTCONIF
echo "Using serial device."
echo "add macro definition for rtconfig.h."
sed -i '$i #define USING_MICROROS ' $RTCONIF
sed -i '$i #define MICROROS_SERIAL ' $RTCONIF
sed -i '$i #define MICROROS_DEVIVE '\"${UROS_AGENT_DEVICE}\"'' $RTCONIF

echo "add macro: USING_MICROROS; MICROROS_SERIAL;"
echo "add macro: MICROROS_DEVIVE \"${UROS_AGENT_DEVICE}\" "

elif [ "$UROS_AGENT_IP" ] && [ "$UROS_AGENT_PORT" ]; then
cp micro-ROS-rtthread-app/rtconfig.h $RTCONIF
echo "Using udp device."
echo "add macro definition for cconfig.h."
sed -i '$i #define USING_MICROROS ' $RTCONIF
sed -i '$i #define MICROROS_UDP ' $RTCONIF
sed -i '$i #define MICROROS_IP '\"$UROS_AGENT_IP\"' ' $RTCONIF
sed -i '$i #define MICROROS_PORT '$UROS_AGENT_PORT' ' $RTCONIF

echo "add macro: USING_MICROROS; MICROROS_UDP; "
echo "add macro: MICROROS_IP \"$UROS_AGENT_IP\""
echo "add macro: MICROROS_PORT $UROS_AGENT_PORT"
else
help
exit 1
fi

if [ "$CONFIG_NAME" == "micro_ros_pub_int32.c" ]; then
sed -i '$i #define MICROS_EXAMPLE_PUB_INT32 ' $RTCONIF
echo "add macro: MICROS_EXAMPLE_PUB_INT32 "
elif [ "$CONFIG_NAME" == "micro_ros_sub_int32.c" ]; then
sed -i '$i #define MICROS_EXAMPLE_SUB_INT32 ' $RTCONIF
echo "add macro: define MICROS_EXAMPLE_SUB_INT32 "
elif [ "$CONFIG_NAME" == "micro_ros_pub_sub_int32.c" ]; then
sed -i '$i #define MICROS_EXAMPLE_PUB_SUB_INT32 ' $RTCONIF
echo "add macro:define MICROS_EXAMPLE_PUB_SUB_INT32 "
elif [ "$CONFIG_NAME" == "micro_ros_ping_pong.c" ]; then
sed -i '$i #define MICROS_EXAMPLE_PING_PONG ' $RTCONIF
echo "add macro:define MICROS_EXAMPLE_PING_PONG "
else
help
exit 1
fi

sed -i '21c source "micro-ROS-rtthread-app/Kconfig" ' Kconfig
echo 'add source : source "micro-ROS-rtthread-app/Kconfig" --> Kconfig'
popd >/dev/null
Loading