diff --git a/config/rtthread/README.md b/config/rtthread/README.md new file mode 100644 index 00000000..33e7a92a --- /dev/null +++ b/config/rtthread/README.md @@ -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; + diff --git a/config/rtthread/dev_ros2_packages.txt b/config/rtthread/dev_ros2_packages.txt new file mode 100644 index 00000000..c04d6a17 --- /dev/null +++ b/config/rtthread/dev_ros2_packages.txt @@ -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 diff --git a/config/rtthread/dev_uros_packages.repos b/config/rtthread/dev_uros_packages.repos new file mode 100644 index 00000000..56f46b6f --- /dev/null +++ b/config/rtthread/dev_uros_packages.repos @@ -0,0 +1 @@ +repositories: diff --git a/config/rtthread/generic/build.sh b/config/rtthread/generic/build.sh new file mode 100755 index 00000000..69b3120f --- /dev/null +++ b/config/rtthread/generic/build.sh @@ -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 + + diff --git a/config/rtthread/generic/client-colcon.meta b/config/rtthread/generic/client-colcon.meta new file mode 100644 index 00000000..92eed2c5 --- /dev/null +++ b/config/rtthread/generic/client-colcon.meta @@ -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" + ] + } + } +} diff --git a/config/rtthread/generic/client_uros_packages.repos b/config/rtthread/generic/client_uros_packages.repos new file mode 100644 index 00000000..c4ad7ff7 --- /dev/null +++ b/config/rtthread/generic/client_uros_packages.repos @@ -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 diff --git a/config/rtthread/generic/configure.sh b/config/rtthread/generic/configure.sh new file mode 100755 index 00000000..d844ee74 --- /dev/null +++ b/config/rtthread/generic/configure.sh @@ -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 diff --git a/config/rtthread/generic/create.sh b/config/rtthread/generic/create.sh new file mode 100755 index 00000000..494c2709 --- /dev/null +++ b/config/rtthread/generic/create.sh @@ -0,0 +1,38 @@ +pushd $FW_TARGETDIR >/dev/null + + if [ -e sdk-bsp-stm32h750-realthread ]; then + echo "sdk-bsp-stm32h750-realthread already created Please delete $FW_TARGETDIR/sdk-bsp-stm32h750-realthread folder if you want a fresh installation." + exit 1 + + else + echo "dowmload code " + git clone https://github.com/RT-Thread-Studio/sdk-bsp-stm32h750-realthread-artpi.git + + echo "dowmload gcc-arm-none-eabi-5_4" + wget -c https://armkeil.blob.core.windows.net/developer//sitecore/shell/-/media/Files/downloads/gnu-rm/5_4-2016q3/gcc-arm-none-eabi-5_4-2016q3-20160926-linux,-d-,tar.bz2 + tar -xvf gcc-arm-none-eabi-5_4-2016q3-20160926-linux,-d-,tar.bz2 + rm gcc-arm-none-eabi-5_4-2016q3-20160926-linux,-d-,tar.bz2 + fi + + if [ -e $FW_TARGETDIR/sdk-bsp-stm32h750-realthread-artpi/projects/art_pi_wifi ]; then + + pushd $FW_TARGETDIR/sdk-bsp-stm32h750-realthread-artpi/projects/art_pi_wifi >/dev/null + git clone https://github.com/navy-to-haijun/micro-ROS-rtthread-app.git + popd >/dev/null + # soft link + pushd $FW_TARGETDIR/sdk-bsp-stm32h750-realthread-artpi/projects/art_pi_wifi>/dev/null + ln -s ../../libraries/ libraries + ln -s ../../rt-thread/ rt-thread + popd >/dev/null + fi + + # ignore broken packages + touch mcu_ws/ros2/rcl_logging/rcl_logging_log4cxx/COLCON_IGNORE + touch mcu_ws/ros2/rcl_logging/rcl_logging_spdlog/COLCON_IGNORE + touch mcu_ws/ros2/rcl/COLCON_IGNORE + touch mcu_ws/ros2/rosidl/rosidl_typesupport_introspection_cpp/COLCON_IGNORE + touch mcu_ws/ros2/rcpputils/COLCON_IGNORE + touch mcu_ws/uros/rcl/rcl_yaml_param_parser/COLCON_IGNORE + touch mcu_ws/uros/rclc/rclc_examples/COLCON_IGNORE + +popd >/dev/null \ No newline at end of file diff --git a/config/rtthread/generic/flash.sh b/config/rtthread/generic/flash.sh new file mode 100755 index 00000000..a9ef0414 --- /dev/null +++ b/config/rtthread/generic/flash.sh @@ -0,0 +1,22 @@ +pushd $FW_TARGETDIR > /dev/null + +RTTHREAD_DIR=$FW_TARGETDIR/sdk-bsp-stm32h750-realthread-artpi/projects/art_pi_wifi +STLDR_DIR=$FW_TARGETDIR/sdk-bsp-stm32h750-realthread-artpi/debug/stldr/ART-Pi_W25Q64.stldr + +# check STM32CubeProgrammer +if [ -d "/usr/local/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin" ]; then + echo "add environment variable for STM32CubeProgrammer" + export PATH=/usr/local/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin:$PATH +else + echo "Please install STM32CubeProgrammer from https://www.st.com/en/development-tools/stm32cubeprog.html" + exit 1 +fi +# check executable file +if [ -f "$RTTHREAD_DIR/rtthread.bin" ]; then + + STM32_Programmer_CLI -c port=swd -w "$RTTHREAD_DIR/rtthread.bin" 0x90000000 -v -el $STLDR_DIR +else + echo "Error: $RTTHREAD_DIR/rtthread.bin not found. Please compile before flashing." + exit 1 +fi +popd > /dev/null diff --git a/config/rtthread/generic/supported_platforms b/config/rtthread/generic/supported_platforms new file mode 100644 index 00000000..e5d9d850 --- /dev/null +++ b/config/rtthread/generic/supported_platforms @@ -0,0 +1 @@ +art-pi diff --git a/config/rtthread/list_apps.sh b/config/rtthread/list_apps.sh new file mode 100644 index 00000000..5403b7db --- /dev/null +++ b/config/rtthread/list_apps.sh @@ -0,0 +1,34 @@ +EXAMPLE_DIR=$FW_TARGETDIR/sdk-bsp-stm32h750-realthread-artpi/projects/art_pi_wifi/micro-ROS-rtthread-app/examples/ +function print_available_apps { + echo "Available apps for rtthread and $PLATFORM:" + if [ -d $EXAMPLE_DIR ]; then + + UROS_APPS=$EXAMPLE_DIR + else + echo "$ EXAMPLE_DIR is not find!!!" + exit 1 + fi + + pushd $UROS_APPS >/dev/null + for app in $(ls -d *.c); do + echo "+-- $app" + done + popd >/dev/null +} + +function check_available_app { + if [ -d $EXAMPLE_DIR ]; then + + UROS_APPS=$EXAMPLE_DIR + else + echo "$ EXAMPLE_DIR is not find!!!" + exit 1 + fi + pushd $UROS_APPS >/dev/null + if [ ! -e $1 ]; then + echo "App $1 for not available" + print_available_apps + exit 1 + fi + popd >/dev/null +} \ No newline at end of file