From 940501457eb059006a7f9256990cd27375ea3420 Mon Sep 17 00:00:00 2001 From: acuadros95 Date: Mon, 13 Mar 2023 16:57:57 +0100 Subject: [PATCH 1/3] Update Readme and build scripts Signed-off-by: acuadros95 --- README.md | 4 +- embeddedrtps.md | 2 +- .../library_generation/extract_flags.py | 2 +- .../library_generation/libmicroros.mk | 160 ++++++++++++++++++ .../library_generation/library_generation.sh | 95 ++++------- .../library_generation/toolchain.cmake | 17 -- .../library_generation/toolchain.cmake.in | 21 +++ 7 files changed, 215 insertions(+), 86 deletions(-) create mode 100644 microros_static_library_ide/library_generation/libmicroros.mk delete mode 100755 microros_static_library_ide/library_generation/toolchain.cmake create mode 100644 microros_static_library_ide/library_generation/toolchain.cmake.in diff --git a/README.md b/README.md index a61cfdf..317e18e 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ print_cflags: 6. Execute the static library generation tool. Compiler flags will retrieved automatically from your `Makefile` and user will be prompted to check if they are correct. - + ```bash docker pull microros/micro_ros_static_library_builder:humble docker run -it --rm -v $(pwd):/project --env MICROROS_LIBRARY_FOLDER=micro_ros_stm32cubemx_utils/microros_static_library microros/micro_ros_static_library_builder:humble @@ -76,7 +76,7 @@ micro-ROS can be used with SMT32CubeIDE following these steps: 2. Go to `Project -> Settings -> C/C++ Build -> Settings -> Build Steps Tab` and in `Pre-build steps` add: ```bash -docker pull microros/micro_ros_static_library_builder:humble && docker run --rm -v ${workspace_loc:/${ProjName}}:/project --env MICROROS_LIBRARY_FOLDER=micro_ros_stm32cubemx_utils/microros_static_library_ide microros/micro_ros_static_library_builder:humble +cd ../micro_ros_stm32cubemx_utils/microros_static_library_ide/library_generation && ./library_generation.sh ``` 3. Add micro-ROS include directory. In `Project -> Settings -> C/C++ Build -> Settings -> Tool Settings Tab -> MCU GCC Compiler -> Include paths` add `micro_ros_stm32cubemx_utils/microros_static_library_ide/libmicroros/include` diff --git a/embeddedrtps.md b/embeddedrtps.md index bfef068..8077495 100644 --- a/embeddedrtps.md +++ b/embeddedrtps.md @@ -42,7 +42,7 @@ This instructions are an approach to a [STMCubeIDE v1.7.0](https://www.st.com/en 10. Go to `Project -> Settings -> C/C++ Build -> Settings -> Build Steps Tab` and in `Pre-build steps` add: ```bash -docker pull microros/micro_ros_static_library_builder:humble && docker run --rm -v ${workspace_loc:/${ProjName}}:/project --env MICROROS_USE_EMBEDDEDRTPS=ON --env MICROROS_LIBRARY_FOLDER=micro_ros_stm32cubemx_utils/microros_static_library_ide microros/micro_ros_static_library_builder:humble +export MICROROS_USE_EMBEDDEDRTPS=ON && cd ../micro_ros_stm32cubemx_utils/microros_static_library_ide/library_generation && ./library_generation.sh ``` 12. Add the following source code files to your project, dragging them to source folder: diff --git a/microros_static_library_ide/library_generation/extract_flags.py b/microros_static_library_ide/library_generation/extract_flags.py index 328c283..1bba013 100644 --- a/microros_static_library_ide/library_generation/extract_flags.py +++ b/microros_static_library_ide/library_generation/extract_flags.py @@ -14,7 +14,7 @@ includes = [x for x in text if x.startswith("-I")] includes = list(set(includes)) -includes = [x.replace("../", "/project/") for x in includes] +includes = [x.replace("../", "../../../") for x in includes] out = "-ffunction-sections -fdata-sections -DSTM32CUBEIDE" diff --git a/microros_static_library_ide/library_generation/libmicroros.mk b/microros_static_library_ide/library_generation/libmicroros.mk new file mode 100644 index 0000000..bd7782a --- /dev/null +++ b/microros_static_library_ide/library_generation/libmicroros.mk @@ -0,0 +1,160 @@ +COMPONENT_DIR = $(shell pwd) +INSTALL_DIR = $(COMPONENT_DIR)/../libmicroros + +DEBUG ?= 0 + +ifeq ($(DEBUG), 1) + BUILD_TYPE = Debug +else + BUILD_TYPE = Release +endif + +ifeq ($(MICROROS_USE_EMBEDDEDRTPS), "ON") +META_FILE = $(COMPONENT_DIR)/colcon-embeddedrtps.meta; +else +META_FILE = $(COMPONENT_DIR)/colcon.meta; +endif + +X_CC := arm-none-eabi-gcc +X_CXX := arm-none-eabi-g++ +X_AR := arm-none-eabi-ar +X_STRIP := arm-none-eabi-strip +CFLAGS_INTERNAL := $(RET_CFLAGS) -w -DCLOCK_MONOTONIC=0 -D'__attribute__(x)=' +CXXFLAGS_INTERNAL := $(RET_CFLAGS) -w -DCLOCK_MONOTONIC=0 -D'__attribute__(x)=' + +all: $(INSTALL_DIR)/libmicroros.a + +clean: + rm -rf $(INSTALL_DIR) + +$(INSTALL_DIR)/toolchain.cmake: $(COMPONENT_DIR)/toolchain.cmake.in + rm -f $(INSTALL_DIR)/toolchain.cmake; \ + mkdir -p $(INSTALL_DIR); \ + cat $(COMPONENT_DIR)/toolchain.cmake.in | \ + sed "s/@CMAKE_C_COMPILER@/$(subst /,\/,$(X_CC))/g" | \ + sed "s/@CMAKE_CXX_COMPILER@/$(subst /,\/,$(X_CXX))/g" | \ + sed "s/@CFLAGS@/$(subst /,\/,$(CFLAGS_INTERNAL))/g" | \ + sed "s/@CXXFLAGS@/$(subst /,\/,$(CXXFLAGS_INTERNAL))/g" \ + > $(INSTALL_DIR)/toolchain.cmake + +$(INSTALL_DIR)/micro_ros_dev/install: + rm -rf $(INSTALL_DIR)/micro_ros_dev; \ + mkdir $(INSTALL_DIR)/micro_ros_dev; cd $(INSTALL_DIR)/micro_ros_dev; \ + git clone -b humble https://github.com/ament/ament_cmake src/ament_cmake; \ + git clone -b humble https://github.com/ament/ament_lint src/ament_lint; \ + git clone -b humble https://github.com/ament/ament_package src/ament_package; \ + git clone -b humble https://github.com/ament/googletest src/googletest; \ + git clone -b humble https://github.com/ros2/ament_cmake_ros src/ament_cmake_ros; \ + git clone -b humble https://github.com/ament/ament_index src/ament_index; \ + colcon build --cmake-args -DBUILD_TESTING=OFF; + +# TODO(acuadros95): Add EmbeddedRTPS conditional +$(INSTALL_DIR)/micro_ros_src/src: + rm -rf $(INSTALL_DIR)/micro_ros_src; \ + mkdir $(INSTALL_DIR)/micro_ros_src; cd $(INSTALL_DIR)/micro_ros_src; \ + if [ "$(MICROROS_USE_EMBEDDEDRTPS)" = "ON" ]; then \ + git clone -b humble https://github.com/micro-ROS/embeddedRTPS src/embeddedRTPS; \ + git clone -b humble https://github.com/micro-ROS/rmw_embeddedrtps src/rmw_embeddedrtps; \ + else \ + git clone -b ros2 https://github.com/eProsima/Micro-XRCE-DDS-Client src/Micro-XRCE-DDS-Client; \ + git clone -b humble https://github.com/micro-ROS/rmw_microxrcedds src/rmw_microxrcedds; \ + fi; \ + git clone -b ros2 https://github.com/eProsima/micro-CDR src/micro-CDR; \ + git clone -b humble https://github.com/micro-ROS/rcl src/rcl; \ + git clone -b humble https://github.com/ros2/rclc src/rclc; \ + git clone -b humble https://github.com/micro-ROS/rcutils src/rcutils; \ + git clone -b humble https://github.com/micro-ROS/micro_ros_msgs src/micro_ros_msgs; \ + git clone -b humble https://github.com/micro-ROS/rosidl_typesupport src/rosidl_typesupport; \ + git clone -b humble https://github.com/micro-ROS/rosidl_typesupport_microxrcedds src/rosidl_typesupport_microxrcedds; \ + git clone -b humble https://github.com/ros2/rosidl src/rosidl; \ + git clone -b humble https://github.com/ros2/rmw src/rmw; \ + git clone -b humble https://github.com/ros2/rcl_interfaces src/rcl_interfaces; \ + git clone -b humble https://github.com/ros2/rosidl_defaults src/rosidl_defaults; \ + git clone -b humble https://github.com/ros2/unique_identifier_msgs src/unique_identifier_msgs; \ + git clone -b humble https://github.com/ros2/common_interfaces src/common_interfaces; \ + git clone -b humble https://github.com/ros2/test_interface_files src/test_interface_files; \ + git clone -b humble https://github.com/ros2/rmw_implementation src/rmw_implementation; \ + git clone -b humble https://github.com/ros2/rcl_logging src/rcl_logging; \ + git clone -b humble https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing src/ros2_tracing; \ + git clone -b humble https://github.com/micro-ROS/micro_ros_utilities src/micro_ros_utilities; \ + git clone -b humble https://github.com/ros2/example_interfaces src/example_interfaces; \ + touch src/rosidl/rosidl_typesupport_introspection_cpp/COLCON_IGNORE; \ + touch src/rcl_logging/rcl_logging_log4cxx/COLCON_IGNORE; \ + touch src/rcl_logging/rcl_logging_spdlog/COLCON_IGNORE; \ + touch src/rclc/rclc_examples/COLCON_IGNORE; \ + touch src/rcl/rcl_yaml_param_parser/COLCON_IGNORE; \ + cp -rf $(COMPONENT_DIR)/extra_packages src/extra_packages || :; + +$(INSTALL_DIR)/micro_ros_src/install: $(INSTALL_DIR)/toolchain.cmake $(INSTALL_DIR)/micro_ros_dev/install $(INSTALL_DIR)/micro_ros_src/src + cd $(INSTALL_DIR)/micro_ros_src; \ + unset AMENT_PREFIX_PATH; \ + unset RMW_IMPLEMENTATION; \ + PATH=$(subst /opt/ros/$(ROS_DISTRO)/bin,,$(PATH)); \ + . ../micro_ros_dev/install/local_setup.sh; \ + colcon build \ + --merge-install \ + --packages-ignore-regex=.*_cpp \ + --metas $(META_FILE) $(COMPONENT_DIR)/../../app_colcon.meta $(USER_COLCON_META) \ + --cmake-force-configure \ + --cmake-clean-cache \ + --cmake-args \ + "--no-warn-unused-cli" \ + --log-level=ERROR \ + -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=OFF \ + -DTHIRDPARTY=ON \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_TESTING=OFF \ + -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ + -DCMAKE_TOOLCHAIN_FILE=$(INSTALL_DIR)/toolchain.cmake \ + -DCMAKE_VERBOSE_MAKEFILE=OFF; + +$(INSTALL_DIR)/libmicroros.a: $(INSTALL_DIR)/micro_ros_src/install + mkdir -p $(INSTALL_DIR)/micro_ros_src/aux; cd $(INSTALL_DIR)/micro_ros_src/aux; \ + for file in $$(find $(INSTALL_DIR)/micro_ros_src/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 -s libmicroros.a *.obj; cp libmicroros.a $(INSTALL_DIR); \ + cd ..; rm -rf aux; \ + cp -R $(INSTALL_DIR)/micro_ros_src/install/include $(INSTALL_DIR)/include; + +rebuild_metas: + export META_PACKAGES=$$(python3 $(COMPONENT_DIR)/get_metas_packages.py $(USER_COLCON_META)); \ + cd $(INSTALL_DIR)/micro_ros_src; \ + unset AMENT_PREFIX_PATH; \ + PATH=$(subst /opt/ros/$(ROS_DISTRO)/bin,,$(PATH)); \ + . ../micro_ros_dev/install/local_setup.sh; \ + colcon build \ + --merge-install \ + --packages-ignore-regex=.*_cpp \ + --packages-select $$META_PACKAGES \ + --metas $(COMPONENT_DIR)/colcon.meta $(COMPONENT_DIR)/../../app_colcon.meta $(USER_COLCON_META) \ + --cmake-force-configure \ + --cmake-clean-cache \ + --cmake-args \ + "--no-warn-unused-cli" \ + --log-level=ERROR \ + -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=OFF \ + -DTHIRDPARTY=ON \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_TESTING=OFF \ + -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ + -DCMAKE_TOOLCHAIN_FILE=$(INSTALL_DIR)/toolchain.cmake \ + -DCMAKE_VERBOSE_MAKEFILE=OFF;\ + mkdir -p $(INSTALL_DIR)/micro_ros_src/aux; cd $(INSTALL_DIR)/micro_ros_src/aux; \ + for file in $$(find $(INSTALL_DIR)/micro_ros_src/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 -s libmicroros.a *.obj; cp libmicroros.a $(INSTALL_DIR); \ + cd ..; rm -rf aux; \ + rm -rf $(INSTALL_DIR)/include; \ + cp -R $(INSTALL_DIR)/micro_ros_src/install/include $(INSTALL_DIR)/include; diff --git a/microros_static_library_ide/library_generation/library_generation.sh b/microros_static_library_ide/library_generation/library_generation.sh index f7ade0b..20eb67b 100755 --- a/microros_static_library_ide/library_generation/library_generation.sh +++ b/microros_static_library_ide/library_generation/library_generation.sh @@ -1,16 +1,22 @@ #!/bin/bash set -e -export BASE_PATH=/project/$MICROROS_LIBRARY_FOLDER +export BASE_PATH=$(pwd)/.. +export PROJECT_PATH=../../../ ######## Check existing library ######## -if [ -f "$BASE_PATH/libmicroros/libmicroros.a" ]; then +if [[ -f "$BASE_PATH/libmicroros/libmicroros.a" && ! -f "$USER_COLCON_META" ]]; then echo "micro-ROS library found. Skipping..." - echo "Delete $MICROROS_LIBRARY_FOLDER/libmicroros/ for rebuild." + echo "Delete microros_static_library_ide/libmicroros/ for rebuild." exit 0 fi + +if [ ! -f "$USER_COLCON_META" ]; then + rm -rf $BASE_PATH/libmicroros +fi + ######## Trying to retrieve CFLAGS ######## -export RET_CFLAGS=$(find /project -type f -name *.mk -exec cat {} \; | python3 $BASE_PATH/library_generation/extract_flags.py) +export RET_CFLAGS=$(find $PROJECT_PATH -type f -name subdir.mk -exec cat {} \; | python3 $BASE_PATH/library_generation/extract_flags.py) RET_CODE=$? if [ $RET_CODE = "0" ]; then @@ -23,66 +29,38 @@ else exit 1; fi -######## Init ######## -apt-get update -apt-get install -y gcc-arm-none-eabi - -cd /uros_ws +echo "Using:" +echo "-------------" +echo $(which arm-none-eabi-gcc) +echo Version: $(arm-none-eabi-gcc -dumpversion) +echo "-------------" -source /opt/ros/$ROS_DISTRO/setup.bash -source install/local_setup.bash - -ros2 run micro_ros_setup create_firmware_ws.sh generate_lib +######## Build ######## -######## Adding extra packages ######## -pushd firmware/mcu_ws > /dev/null +if [ ! -f "$BASE_PATH/libmicroros/libmicroros.a" ]; then + # If library does not exist build it - # Workaround: Copy just tf2_msgs - git clone -b ros2 https://github.com/ros2/geometry2 - cp -R geometry2/tf2_msgs ros2/tf2_msgs - rm -rf geometry2 + ######## Add extra packages ######## + pushd extra_packages + # Workaround: Copy just tf2_msgs + git clone -b ros2 https://github.com/ros2/geometry2 + cp -R geometry2/tf2_msgs tf2_msgs + rm -rf geometry2 - # Import user defined packages - mkdir extra_packages - pushd extra_packages > /dev/null - USER_CUSTOM_PACKAGES_DIR=$BASE_PATH/../../microros_component/extra_packages - if [ -d "$USER_CUSTOM_PACKAGES_DIR" ]; then - cp -R $USER_CUSTOM_PACKAGES_DIR/* . - fi - if [ -f $USER_CUSTOM_PACKAGES_DIR/extra_packages.repos ]; then - vcs import --input $USER_CUSTOM_PACKAGES_DIR/extra_packages.repos + if [ -f $extra_packages.repos ]; then + vcs import --input extra_packages.repos fi - cp -R $BASE_PATH/library_generation/extra_packages/* . - vcs import --input extra_packages.repos popd > /dev/null - if [ ! -z ${MICROROS_USE_EMBEDDEDRTPS+x} ]; then - rm -rf eProsima/Micro-XRCE-DDS-Client - rm -rf uros/rmw_microxrcedds - - git clone -b main https://github.com/micro-ROS/rmw_embeddedrtps uros/rmw_embeddedrtps - git clone -b main https://github.com/micro-ROS/embeddedRTPS uros/embeddedRTPS - fi - -popd > /dev/null - -######## Build ######## -export TOOLCHAIN_PREFIX=/usr/bin/arm-none-eabi- -if [ ! -z ${MICROROS_USE_EMBEDDEDRTPS+x} ]; then - ros2 run micro_ros_setup build_firmware.sh $BASE_PATH/library_generation/toolchain.cmake $BASE_PATH/library_generation/colcon-embeddedrtps.meta + make -f libmicroros.mk else - ros2 run micro_ros_setup build_firmware.sh $BASE_PATH/library_generation/toolchain.cmake $BASE_PATH/library_generation/colcon.meta + # If exists just rebuild + make -f libmicroros.mk rebuild_metas fi -find firmware/build/include/ -name "*.c" -delete -rm -rf $BASE_PATH/libmicroros -mkdir -p $BASE_PATH/libmicroros/include -cp -R firmware/build/include/* $BASE_PATH/libmicroros/include/ -cp -R firmware/build/libmicroros.a $BASE_PATH/libmicroros/libmicroros.a - ######## Fix include paths ######## -pushd firmware/mcu_ws > /dev/null +pushd $BASE_PATH/libmicroros/micro_ros_src > /dev/null INCLUDE_ROS2_PACKAGES=$(colcon list | awk '{print $1}' | awk -v d=" " '{s=(NR==1?s:s d)$0}END{print s}') popd > /dev/null @@ -92,16 +70,3 @@ for var in ${INCLUDE_ROS2_PACKAGES}; do rm -rf $BASE_PATH/libmicroros/include/${var}/${var} fi done - -######## Generate extra files ######## -find firmware/mcu_ws/ros2 \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' > $BASE_PATH/libmicroros/available_ros2_types -find firmware/mcu_ws/extra_packages \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' >> $BASE_PATH/libmicroros/available_ros2_types - -cd firmware -echo "" > $BASE_PATH/libmicroros/built_packages -for f in $(find $(pwd) -name .git -type d); do pushd $f > /dev/null; echo $(git config --get remote.origin.url) $(git rev-parse HEAD) >> $BASE_PATH/libmicroros/built_packages; popd > /dev/null; done; - -######## Fix permissions ######## -sudo chmod -R 777 $BASE_PATH/libmicroros/ -sudo chmod -R 777 $BASE_PATH/libmicroros/include/ -sudo chmod -R 777 $BASE_PATH/libmicroros/libmicroros.a diff --git a/microros_static_library_ide/library_generation/toolchain.cmake b/microros_static_library_ide/library_generation/toolchain.cmake deleted file mode 100755 index 731fe18..0000000 --- a/microros_static_library_ide/library_generation/toolchain.cmake +++ /dev/null @@ -1,17 +0,0 @@ -SET(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_CROSSCOMPILING 1) -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) - -set(CMAKE_C_COMPILER $ENV{TOOLCHAIN_PREFIX}gcc) -set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_PREFIX}g++) - -SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "") -SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "") - -set(FLAGS $ENV{RET_CFLAGS} CACHE STRING "" FORCE) -set(MICROROSFLAGS "-DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE) - -set(CMAKE_C_FLAGS_INIT "-std=c11 ${FLAGS} ${MICROROSFLAGS} " CACHE STRING "" FORCE) -set(CMAKE_CXX_FLAGS_INIT "-std=c++14 ${FLAGS} -fno-rtti ${MICROROSFLAGS} " CACHE STRING "" FORCE) - -set(__BIG_ENDIAN__ 0) diff --git a/microros_static_library_ide/library_generation/toolchain.cmake.in b/microros_static_library_ide/library_generation/toolchain.cmake.in new file mode 100644 index 0000000..5cdcaf7 --- /dev/null +++ b/microros_static_library_ide/library_generation/toolchain.cmake.in @@ -0,0 +1,21 @@ +include(CMakeForceCompiler) + +set(CMAKE_SYSTEM_NAME Generic) + +set(CMAKE_CROSSCOMPILING 1) +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +SET (CMAKE_C_COMPILER_WORKS 1) +SET (CMAKE_CXX_COMPILER_WORKS 1) + +set(CMAKE_C_COMPILER @CMAKE_C_COMPILER@) +set(CMAKE_CXX_COMPILER @CMAKE_CXX_COMPILER@) + +set(CMAKE_C_FLAGS_INIT "-std=c11 @CFLAGS@" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_INIT "-std=c++14 @CXXFLAGS@" CACHE STRING "" FORCE) + +set(__BIG_ENDIAN__ 0) From 99b52b51295ff8f90c14c65d13ef7fa02f6e2e98 Mon Sep 17 00:00:00 2001 From: acuadros95 Date: Tue, 14 Mar 2023 15:44:24 +0100 Subject: [PATCH 2/3] Unify CubeIDE and CubeMX approaches Signed-off-by: acuadros95 --- .../colcon-embeddedrtps.meta | 0 .../colcon.meta | 0 .../extra_packages/extra_packages.repos | 0 .../extract_flags.py | 0 .../libmicroros.mk | 4 +- .../library_generation.sh | 19 +++- .../toolchain.cmake.in | 0 .../library_generation/colcon.meta | 53 ---------- .../library_generation/library_generation.sh | 100 ------------------ .../library_generation/toolchain.cmake | 17 --- .../extra_packages/extra_packages.repos | 5 - 11 files changed, 16 insertions(+), 182 deletions(-) rename {microros_static_library_ide/library_generation => library_generation}/colcon-embeddedrtps.meta (100%) rename {microros_static_library_ide/library_generation => library_generation}/colcon.meta (100%) rename {microros_static_library/library_generation => library_generation}/extra_packages/extra_packages.repos (100%) rename {microros_static_library_ide/library_generation => library_generation}/extract_flags.py (100%) rename {microros_static_library_ide/library_generation => library_generation}/libmicroros.mk (98%) rename {microros_static_library_ide/library_generation => library_generation}/library_generation.sh (79%) rename {microros_static_library_ide/library_generation => library_generation}/toolchain.cmake.in (100%) delete mode 100755 microros_static_library/library_generation/colcon.meta delete mode 100755 microros_static_library/library_generation/library_generation.sh delete mode 100755 microros_static_library/library_generation/toolchain.cmake delete mode 100755 microros_static_library_ide/library_generation/extra_packages/extra_packages.repos diff --git a/microros_static_library_ide/library_generation/colcon-embeddedrtps.meta b/library_generation/colcon-embeddedrtps.meta similarity index 100% rename from microros_static_library_ide/library_generation/colcon-embeddedrtps.meta rename to library_generation/colcon-embeddedrtps.meta diff --git a/microros_static_library_ide/library_generation/colcon.meta b/library_generation/colcon.meta similarity index 100% rename from microros_static_library_ide/library_generation/colcon.meta rename to library_generation/colcon.meta diff --git a/microros_static_library/library_generation/extra_packages/extra_packages.repos b/library_generation/extra_packages/extra_packages.repos similarity index 100% rename from microros_static_library/library_generation/extra_packages/extra_packages.repos rename to library_generation/extra_packages/extra_packages.repos diff --git a/microros_static_library_ide/library_generation/extract_flags.py b/library_generation/extract_flags.py similarity index 100% rename from microros_static_library_ide/library_generation/extract_flags.py rename to library_generation/extract_flags.py diff --git a/microros_static_library_ide/library_generation/libmicroros.mk b/library_generation/libmicroros.mk similarity index 98% rename from microros_static_library_ide/library_generation/libmicroros.mk rename to library_generation/libmicroros.mk index bd7782a..773029b 100644 --- a/microros_static_library_ide/library_generation/libmicroros.mk +++ b/library_generation/libmicroros.mk @@ -10,9 +10,9 @@ else endif ifeq ($(MICROROS_USE_EMBEDDEDRTPS), "ON") -META_FILE = $(COMPONENT_DIR)/colcon-embeddedrtps.meta; +META_FILE = $(COMPONENT_DIR)/colcon-embeddedrtps.meta else -META_FILE = $(COMPONENT_DIR)/colcon.meta; +META_FILE = $(COMPONENT_DIR)/colcon.meta endif X_CC := arm-none-eabi-gcc diff --git a/microros_static_library_ide/library_generation/library_generation.sh b/library_generation/library_generation.sh similarity index 79% rename from microros_static_library_ide/library_generation/library_generation.sh rename to library_generation/library_generation.sh index 20eb67b..3e3f83f 100755 --- a/microros_static_library_ide/library_generation/library_generation.sh +++ b/library_generation/library_generation.sh @@ -2,12 +2,12 @@ set -e export BASE_PATH=$(pwd)/.. -export PROJECT_PATH=../../../ +export PROJECT_PATH=../../ ######## Check existing library ######## if [[ -f "$BASE_PATH/libmicroros/libmicroros.a" && ! -f "$USER_COLCON_META" ]]; then echo "micro-ROS library found. Skipping..." - echo "Delete microros_static_library_ide/libmicroros/ for rebuild." + echo "Delete libmicroros/ for rebuild." exit 0 fi @@ -15,11 +15,20 @@ if [ ! -f "$USER_COLCON_META" ]; then rm -rf $BASE_PATH/libmicroros fi +if [ "$USER_COLCON_META" ]; then + rm -rf $BASE_PATH/libmicroros +fi + ######## Trying to retrieve CFLAGS ######## -export RET_CFLAGS=$(find $PROJECT_PATH -type f -name subdir.mk -exec cat {} \; | python3 $BASE_PATH/library_generation/extract_flags.py) -RET_CODE=$? -if [ $RET_CODE = "0" ]; then +if [ $(MICROROS_USE_CUBEIDE) ]; then + export RET_CFLAGS=$(find $PROJECT_PATH -type f -name subdir.mk -exec cat {} \; | python3 $BASE_PATH/library_generation/extract_flags.py) +else + # Use CubeMX approach + export RET_CFLAGS=$(cd $PROJECT_PATH && make print_cflags) +fi + +if [ $RET_CFLAGS != "" ]; then echo "Found CFLAGS:" echo "-------------" echo $RET_CFLAGS diff --git a/microros_static_library_ide/library_generation/toolchain.cmake.in b/library_generation/toolchain.cmake.in similarity index 100% rename from microros_static_library_ide/library_generation/toolchain.cmake.in rename to library_generation/toolchain.cmake.in diff --git a/microros_static_library/library_generation/colcon.meta b/microros_static_library/library_generation/colcon.meta deleted file mode 100755 index 5bb8eff..0000000 --- a/microros_static_library/library_generation/colcon.meta +++ /dev/null @@ -1,53 +0,0 @@ -{ - "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_NO_64_ATOMIC=ON", - "-DRCUTILS_AVOID_DYNAMIC_ALLOCATION=ON" - ] - }, - "microxrcedds_client": { - "cmake-args": [ - "-DUCLIENT_PIC=OFF", - "-DUCLIENT_PROFILE_UDP=OFF", - "-DUCLIENT_PROFILE_TCP=OFF", - "-DUCLIENT_PROFILE_DISCOVERY=OFF", - "-DUCLIENT_PROFILE_SERIAL=OFF", - "-UCLIENT_PROFILE_STREAM_FRAMING=ON", - "-DUCLIENT_PROFILE_CUSTOM_TRANSPORT=ON" - ] - }, - "rmw_microxrcedds": { - "cmake-args": [ - "-DRMW_UXRCE_MAX_NODES=1", - "-DRMW_UXRCE_MAX_PUBLISHERS=10", - "-DRMW_UXRCE_MAX_SUBSCRIPTIONS=5", - "-DRMW_UXRCE_MAX_SERVICES=1", - "-DRMW_UXRCE_MAX_CLIENTS=1", - "-DRMW_UXRCE_MAX_HISTORY=4", - "-DRMW_UXRCE_TRANSPORT=custom" - ] - } - } -} diff --git a/microros_static_library/library_generation/library_generation.sh b/microros_static_library/library_generation/library_generation.sh deleted file mode 100755 index 13f4ad4..0000000 --- a/microros_static_library/library_generation/library_generation.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/bash -set -e - -export BASE_PATH=/project/$MICROROS_LIBRARY_FOLDER - -######## Init ######## - -apt update -apt install -y gcc-arm-none-eabi - -cd /uros_ws - -source /opt/ros/$ROS_DISTRO/setup.bash -source install/local_setup.bash - -ros2 run micro_ros_setup create_firmware_ws.sh generate_lib - -######## Adding extra packages ######## -pushd firmware/mcu_ws > /dev/null - - # Workaround: Copy just tf2_msgs - git clone -b humble https://github.com/ros2/geometry2 - cp -R geometry2/tf2_msgs ros2/tf2_msgs - rm -rf geometry2 - - # Import user defined packages - mkdir extra_packages - pushd extra_packages > /dev/null - USER_CUSTOM_PACKAGES_DIR=$BASE_PATH/../../microros_component/extra_packages - if [ -d "$USER_CUSTOM_PACKAGES_DIR" ]; then - cp -R $USER_CUSTOM_PACKAGES_DIR/* . - fi - if [ -f $USER_CUSTOM_PACKAGES_DIR/extra_packages.repos ]; then - vcs import --input $USER_CUSTOM_PACKAGES_DIR/extra_packages.repos - fi - cp -R $BASE_PATH/library_generation/extra_packages/* . - vcs import --input extra_packages.repos - popd > /dev/null - -popd > /dev/null - -######## Trying to retrieve CFLAGS ######## -pushd /project > /dev/null -export RET_CFLAGS=$(make print_cflags) -RET_CODE=$? - -if [ $RET_CODE = "0" ]; then - echo "Found CFLAGS:" - echo "-------------" - echo $RET_CFLAGS - echo "-------------" - read -p "Do you want to continue with them? (y/n)" -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]] - then - echo "Continuing..." - else - echo "Aborting" - exit 0; - fi -else - echo "Please read README.md to update your Makefile" - exit 1; -fi -popd > /dev/null - -######## Build ######## -export TOOLCHAIN_PREFIX=/usr/bin/arm-none-eabi- -ros2 run micro_ros_setup build_firmware.sh $BASE_PATH/library_generation/toolchain.cmake $BASE_PATH/library_generation/colcon.meta - -find firmware/build/include/ -name "*.c" -delete -rm -rf $BASE_PATH/libmicroros -mkdir -p $BASE_PATH/libmicroros/microros_include -cp -R firmware/build/include/* $BASE_PATH/libmicroros/microros_include/ -cp -R firmware/build/libmicroros.a $BASE_PATH/libmicroros/libmicroros.a - -######## Fix include paths ######## -pushd firmware/mcu_ws > /dev/null - INCLUDE_ROS2_PACKAGES=$(colcon list | awk '{print $1}' | awk -v d=" " '{s=(NR==1?s:s d)$0}END{print s}') -popd > /dev/null - -for var in ${INCLUDE_ROS2_PACKAGES}; do - if [ -d "$BASE_PATH/libmicroros/microros_include/${var}/${var}" ]; then - rsync -r $BASE_PATH/libmicroros/microros_include/${var}/${var}/* $BASE_PATH/libmicroros/microros_include/${var} - rm -rf $BASE_PATH/libmicroros/microros_include/${var}/${var} - fi -done - -######## Generate extra files ######## -find firmware/mcu_ws/ros2 \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' > $BASE_PATH/libmicroros/available_ros2_types -find firmware/mcu_ws/extra_packages \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' >> $BASE_PATH/libmicroros/available_ros2_types - -cd firmware -echo "" > $BASE_PATH/libmicroros/built_packages -for f in $(find $(pwd) -name .git -type d); do pushd $f > /dev/null; echo $(git config --get remote.origin.url) $(git rev-parse HEAD) >> $BASE_PATH/libmicroros/built_packages; popd > /dev/null; done; - -######## Fix permissions ######## -sudo chmod -R 777 $BASE_PATH/libmicroros/ -sudo chmod -R 777 $BASE_PATH/libmicroros/microros_include/ -sudo chmod -R 777 $BASE_PATH/libmicroros/libmicroros.a diff --git a/microros_static_library/library_generation/toolchain.cmake b/microros_static_library/library_generation/toolchain.cmake deleted file mode 100755 index 731fe18..0000000 --- a/microros_static_library/library_generation/toolchain.cmake +++ /dev/null @@ -1,17 +0,0 @@ -SET(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_CROSSCOMPILING 1) -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) - -set(CMAKE_C_COMPILER $ENV{TOOLCHAIN_PREFIX}gcc) -set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_PREFIX}g++) - -SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "") -SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "") - -set(FLAGS $ENV{RET_CFLAGS} CACHE STRING "" FORCE) -set(MICROROSFLAGS "-DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE) - -set(CMAKE_C_FLAGS_INIT "-std=c11 ${FLAGS} ${MICROROSFLAGS} " CACHE STRING "" FORCE) -set(CMAKE_CXX_FLAGS_INIT "-std=c++14 ${FLAGS} -fno-rtti ${MICROROSFLAGS} " CACHE STRING "" FORCE) - -set(__BIG_ENDIAN__ 0) diff --git a/microros_static_library_ide/library_generation/extra_packages/extra_packages.repos b/microros_static_library_ide/library_generation/extra_packages/extra_packages.repos deleted file mode 100755 index 7ce2b93..0000000 --- a/microros_static_library_ide/library_generation/extra_packages/extra_packages.repos +++ /dev/null @@ -1,5 +0,0 @@ -repositories: - control_msgs: - type: git - url: https://github.com/ros-controls/control_msgs - version: foxy-devel \ No newline at end of file From 63926c47f971cb04fe1f999f839bace259f185de Mon Sep 17 00:00:00 2001 From: acuadros95 Date: Tue, 14 Mar 2023 15:44:42 +0100 Subject: [PATCH 3/3] Update Readme Signed-off-by: acuadros95 --- README.md | 71 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 317e18e..77503be 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ This tool aims to ease the micro-ROS integration in a STM32CubeMX/IDE project. - [micro-ROS for STM32CubeMX/IDE](#micro-ros-for-stm32cubemxide) + - [Requirements](#requirements) - [Middlewares available](#middlewares-available) - [Using this package with STM32CubeMX](#using-this-package-with-stm32cubemx) - [Using this package with STM32CubeIDE](#using-this-package-with-stm32cubeide) @@ -17,6 +18,16 @@ This tool aims to ease the micro-ROS integration in a STM32CubeMX/IDE project. - [Purpose of the Project](#purpose-of-the-project) - [License](#license) - [Known Issues/Limitations](#known-issueslimitations) + +## Requirements + +- Install `rsync`: `apt -y install rsync` +- [Install colcon](https://colcon.readthedocs.io/en/released/user/installation.html) and dependencies, for example with: + + ```bash + pip3 install colcon-common-extensions catkin_pkg lark-parser empy + ``` + ## Middlewares available This package support the usage of micro-ROS on top of two different middlewares: @@ -31,43 +42,44 @@ This package support the usage of micro-ROS on top of two different middlewares: 4. Configure the transport interface on the STM32CubeMX project, check the [Transport configuration](#Transport-configuration) section for instructions on the custom transports provided. 5. Modify the generated `Makefile` to include the following code **before the `build the application` section**: - + -```makefile -####################################### -# micro-ROS addons -####################################### -LDFLAGS += micro_ros_stm32cubemx_utils/microros_static_library/libmicroros/libmicroros.a -C_INCLUDES += -Imicro_ros_stm32cubemx_utils/microros_static_library/libmicroros/microros_include + -# Add micro-ROS utils -C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/custom_memory_manager.c -C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/microros_allocators.c -C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/microros_time.c + ```makefile + ####################################### + # micro-ROS addons + ####################################### + LDFLAGS += micro_ros_stm32cubemx_utils/libmicroros/libmicroros.a + C_INCLUDES += -Imicro_ros_stm32cubemx_utils/libmicroros/include -# Set here the custom transport implementation -C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/microros_transports/dma_transport.c + # Add micro-ROS utils + C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/custom_memory_manager.c + C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/microros_allocators.c + C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/microros_time.c -print_cflags: - @echo $(CFLAGS) -``` + # Set here the custom transport implementation + C_SOURCES += micro_ros_stm32cubemx_utils/extra_sources/microros_transports/usb_transport.c + + print_cflags: + @echo $(CFLAGS) + ``` 6. Execute the static library generation tool. Compiler flags will retrieved automatically from your `Makefile` and user will be prompted to check if they are correct. - -```bash -docker pull microros/micro_ros_static_library_builder:humble -docker run -it --rm -v $(pwd):/project --env MICROROS_LIBRARY_FOLDER=micro_ros_stm32cubemx_utils/microros_static_library microros/micro_ros_static_library_builder:humble -``` + ```bash + ./micro_ros_stm32cubemx_utils/library_generation//library_generation.sh + ``` 1. Modify your `main.c` to use micro-ROS. An example application can be found in `sample_main.c`. 2. Continue your usual workflow building your project and flashing the binary: -```bash -make -j$(nproc) -``` + ```bash + make -j$(nproc) + ``` + ## Using this package with STM32CubeIDE micro-ROS can be used with SMT32CubeIDE following these steps: @@ -75,9 +87,9 @@ micro-ROS can be used with SMT32CubeIDE following these steps: 1. Clone this repository in your STM32CubeIDE project folder 2. Go to `Project -> Settings -> C/C++ Build -> Settings -> Build Steps Tab` and in `Pre-build steps` add: -```bash -cd ../micro_ros_stm32cubemx_utils/microros_static_library_ide/library_generation && ./library_generation.sh -``` + ```bash + ./micro_ros_stm32cubemx_utils/library_generation//library_generation.sh + ``` 3. Add micro-ROS include directory. In `Project -> Settings -> C/C++ Build -> Settings -> Tool Settings Tab -> MCU GCC Compiler -> Include paths` add `micro_ros_stm32cubemx_utils/microros_static_library_ide/libmicroros/include` 4. Add the micro-ROS precompiled library. In `Project -> Settings -> C/C++ Build -> Settings -> MCU GCC Linker -> Libraries` @@ -91,6 +103,7 @@ cd ../micro_ros_stm32cubemx_utils/microros_static_library_ide/library_generation 6. Make sure that if you are using FreeRTOS, the micro-ROS task **has more than 10 kB of stack**: [Detail](.images/Set_freertos_stack.jpg) 7. Configure the transport interface on the STM32CubeMX project, check the [Transport configuration](#Transport-configuration) section for instructions on the custom transports provided. 8. Build and run your project + ## Transport configuration Available transport for this platform are: