From 7f4e02c61ad31819cf94ba1e3b59473ce8d370d8 Mon Sep 17 00:00:00 2001 From: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com> Date: Wed, 12 Jan 2022 12:17:52 +0100 Subject: [PATCH 1/3] Add ESP32 support (#680) * Fix wifi example * Update ci and library properties * Add esp32 build step * Update readme * Add esp32 library to test CI * Fix CI * Fix build for Arduino nano * Fix esp32 CI compilation * Install pyserial for esp32 * Install pip3 on CI * Revert commit and add pip3 * Update library_generation.sh with changes check * Remove redundant code * Trigger build (cherry picked from commit a809407288ee79b7cd2d3e5384265a390fdf2df6) # Conflicts: # built_packages # extras/library_generation/library_generation.sh --- .github/workflows/ci.yml | 11 ++++-- README.md | 2 ++ built_packages | 11 ++++++ .../micro-ros_publisher_wifi.ino | 4 +-- .../library_generation/esp32_toolchain.cmake | 16 +++++++++ .../library_generation/library_generation.sh | 36 ++++++++++++++++--- library.properties | 2 +- src/micro_ros_arduino.h | 16 +++++---- src/wifi_transport.cpp | 6 ++-- 9 files changed, 84 insertions(+), 20 deletions(-) create mode 100644 extras/library_generation/esp32_toolchain.cmake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3fc8bd307..1f2c8d145 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,18 +19,21 @@ jobs: - name: Build run: | apt update - apt install -y git curl lib32z1 wget libfontconfig libxft2 xz-utils rsync + apt install -y git curl lib32z1 wget libfontconfig libxft2 xz-utils rsync python-is-python3 python3-pip + pip3 install pyserial curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh mkdir -p /github/home/Arduino/libraries/micro_ros_arduino/ cp -R checkout/* /github/home/Arduino/libraries/micro_ros_arduino/ echo '''board_manager: additional_urls: - - https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencr_release/package_opencr_index.json''' > arduino-cli.yaml + - https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencr_release/package_opencr_index.json + - https://github.com/espressif/arduino-esp32/releases/download/2.0.2/package_esp32_index.json''' > arduino-cli.yaml export PATH=$PATH:/github/workspace/bin:/__w/micro_ros_arduino/micro_ros_arduino/bin arduino-cli core install OpenCR:OpenCR -v arduino-cli core install arduino:samd -v arduino-cli core install arduino:sam -v arduino-cli core install arduino:mbed -v + arduino-cli core install esp32:esp32 -v # # INSTALLING TEENSY SUPPORT wget https://downloads.arduino.cc/arduino-1.8.13-linux64.tar.xz @@ -78,4 +81,6 @@ jobs: arduino-cli compile --fqbn arduino:sam:arduino_due_x /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v # arduino-cli compile --fqbn arduino:mbed:envie_m4 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v arduino-cli compile --fqbn arduino:mbed:envie_m7 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v - arduino-cli compile --fqbn arduino:mbed:envie_m7 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher_wifi -v \ No newline at end of file + arduino-cli compile --fqbn arduino:mbed:envie_m7 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher_wifi -v + arduino-cli compile --fqbn esp32:esp32:esp32 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v + arduino-cli compile --fqbn esp32:esp32:esp32 /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher_wifi -v \ No newline at end of file diff --git a/README.md b/README.md index 257fe414b..c17e2a464 100755 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Supported boards are: | [Teensy 3.2/3.1](https://www.pjrc.com/store/teensy32.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/teensy/td_download.html) | `colcon_lowmem.meta` | | [Teensy 3.5](https://www.pjrc.com/store/teensy35.html) | v1.8.5 | Not tested | [Based on Teensyduino](https://www.pjrc.com/teensy/td_download.html) | `colcon_lowmem.meta` | | [Teensy 3.6](https://www.pjrc.com/store/teensy36.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/teensy/td_download.html) | `colcon_lowmem.meta` | +| [ESP32 Dev Module](https://docs.espressif.com/projects/arduino-esp32/en/latest/boards/ESP32-DevKitC-1.html) | v1.8.5 | Supported | [Arduino core for the ESP32 (v2.0.2)](https://github.com/espressif/arduino-esp32/releases/tag/2.0.2) | `colcon.meta` | Community contributed boards are: @@ -135,3 +136,4 @@ see the file [3rd-party-licenses.txt](3rd-party-licenses.txt). - When using provided precompiled libraries, users should take into account the already configured static memory pools in middleware layers. [More info here](https://micro-ros.github.io/docs/tutorials/core/microxrcedds_rmw_configuration/). - micro-ROS transports should be refactored in order to provide a pluggable mechanims. Only USB serial transports are provided. - Teensyduino support files have to be patched in order to use precompiled libraries. +- To solve Python errors on ESP32 compilation: `apt install python-is-python3 && pip3 install pyserial` diff --git a/built_packages b/built_packages index 1c765b0d4..0e1c8ed41 100755 --- a/built_packages +++ b/built_packages @@ -25,6 +25,7 @@ https://github.com/ros2/rcl_interfaces.git 9c9f5935cff0eeeffe7e3eb31beba396cb22d https://github.com/ros-controls/control_msgs a555c37f1a3536bb452ea555c58fdd9344d87614 https://github.com/eProsima/Micro-XRCE-DDS-Client.git e61bfa0e0bfdb74f4a592b2efbf7acbfcfeb6c1f https://github.com/eProsima/Micro-CDR.git cb4403a8780095df94a7b1936b1e00153c90070d +<<<<<<< HEAD https://github.com/ament/googletest.git baf8569d2e1f5dd48df1328466d04eabf920e57d https://github.com/ament/ament_cmake.git b474e31a3fc46df99b8d164e8ad65a7336fdb3c1 https://github.com/ament/ament_package.git 37f9a1f5e19a2513051ece437c3ef14a0cbaf836 @@ -33,3 +34,13 @@ https://github.com/ament/uncrustify_vendor.git fd52d19c51190e6277b39706f728cedb8 https://github.com/ament/ament_index.git 5ce2eba781801154d93c6fd7d6f66b23e4a7182d https://github.com/uncrustify/uncrustify.git 1d3d8fa5e81bece0fac4b81316b0844f7cc35926 https://github.com/ros2/ament_cmake_ros.git add4d35a981fadef6ffc7f5180bcb19a84acc08d +======= +https://github.com/ament/googletest.git 79c4c9db1a7bc8bc5473a280499bf776173653d6 +https://github.com/ament/ament_cmake.git 852a7d8abe8a743938a9167aa3f1f7b0a40e631f +https://github.com/ament/ament_package.git 54ff09f9eb8d35ca914376ae872cc7e60093547b +https://github.com/ament/ament_lint.git 4bc68c815ce308b3443e3cb38fd71e2b03ffdc40 +https://github.com/ament/uncrustify_vendor.git 8945c291fbd36d7980f7e4fd641601c277c178ec +https://github.com/ament/ament_index.git 7c8a2762453bf928909cc3dd65d2164b2f67dbaf +https://github.com/ros2/ament_cmake_ros.git 7b6b599c3fc8023806db2a97b344e8610902adac + +>>>>>>> a809407 (Add ESP32 support (#680)) diff --git a/examples/micro-ros_publisher_wifi/micro-ros_publisher_wifi.ino b/examples/micro-ros_publisher_wifi/micro-ros_publisher_wifi.ino index 47ff87da8..36735cd05 100755 --- a/examples/micro-ros_publisher_wifi/micro-ros_publisher_wifi.ino +++ b/examples/micro-ros_publisher_wifi/micro-ros_publisher_wifi.ino @@ -8,8 +8,8 @@ #include -#if !defined(TARGET_PORTENTA_H7_M7) && !defined(ARDUINO_NANO_RP2040_CONNECT) -#error This example is only avaible for Arduino Portenta and Arduino Nano RP2040 Connect +#if !defined(ESP32) && !defined(TARGET_PORTENTA_H7_M7) && !defined(ARDUINO_NANO_RP2040_CONNECT) +#error This example is only avaible for Arduino Portenta, Arduino Nano RP2040 Connect and ESP32 Dev module #endif rcl_publisher_t publisher; diff --git a/extras/library_generation/esp32_toolchain.cmake b/extras/library_generation/esp32_toolchain.cmake new file mode 100644 index 000000000..03e5e7acc --- /dev/null +++ b/extras/library_generation/esp32_toolchain.cmake @@ -0,0 +1,16 @@ +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 "-Os -mlongcalls -ffunction-sections -fdata-sections -D'RCUTILS_LOG_MIN_SEVERITY=RCUTILS_LOG_MIN_SEVERITY_NONE'" CACHE STRING "" FORCE) + +set(CMAKE_C_FLAGS_INIT "-std=c11 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_INIT "-std=c++14 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE) + +set(__BIG_ENDIAN__ 0) diff --git a/extras/library_generation/library_generation.sh b/extras/library_generation/library_generation.sh index b524a6a22..7af70346c 100755 --- a/extras/library_generation/library_generation.sh +++ b/extras/library_generation/library_generation.sh @@ -21,6 +21,7 @@ if [ $OPTIND -eq 1 ]; then # PLATFORMS+=("portenta-m4") PLATFORMS+=("portenta-m7") PLATFORMS+=("kakutef7-m7") + PLATFORMS+=("esp32") fi shift $((OPTIND-1)) @@ -53,6 +54,23 @@ pushd firmware/mcu_ws > /dev/null popd > /dev/null +<<<<<<< HEAD +======= +cd firmware +echo "" > /project/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) >> /project/built_packages; popd > /dev/null; done; + +cd /project +if [[ `git diff-index --name-only HEAD | grep built_packages` ]]; then + echo "Changes detected" +else + echo "No changes detected" + exit 0 +fi + +cd /uros_ws + +>>>>>>> a809407 (Add ESP32 support (#680)) ######## Clean and source ######## find /project/src/ ! -name micro_ros_arduino.h ! -name *.c ! -name *.cpp ! -name *.c.in -delete @@ -215,13 +233,23 @@ if [[ " ${PLATFORMS[@]} " =~ " kakutef7-m7 " ]]; then cp -R firmware/build/libmicroros.a /project/src/cortex-m7/fpv5-sp-d16-hardfp/libmicroros.a fi +######## Build for ESP 32 ######## +if [[ " ${PLATFORMS[@]} " =~ " esp32 " ]]; then + rm -rf firmware/build + + export TOOLCHAIN_PREFIX=/uros_ws/xtensa-esp32-elf/bin/xtensa-esp32-elf- + ros2 run micro_ros_setup build_firmware.sh /project/extras/library_generation/esp32_toolchain.cmake /project/extras/library_generation/colcon.meta + + find firmware/build/include/ -name "*.c" -delete + cp -R firmware/build/include/* /project/src/ + + mkdir -p /project/src/esp32 + cp -R firmware/build/libmicroros.a /project/src/esp32/libmicroros.a +fi + ######## Generate extra files ######## find firmware/mcu_ws/ros2 \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' > /project/available_ros2_types find firmware/mcu_ws/extra_packages \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' >> /project/available_ros2_types -cd firmware -echo "" > /project/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) >> /project/built_packages; popd > /dev/null; done; - ######## Fix permissions ######## sudo chmod -R 777 . \ No newline at end of file diff --git a/library.properties b/library.properties index fbd43d0b7..9537d483d 100755 --- a/library.properties +++ b/library.properties @@ -7,4 +7,4 @@ paragraph=micro-ROS Arduino library url=https://github.com/micro-ROS precompiled=true category=Other -architectures=stm32,OpenCR,Teensyduino,samd,sam,mbed +architectures=stm32,OpenCR,Teensyduino,samd,sam,mbed, esp32 diff --git a/src/micro_ros_arduino.h b/src/micro_ros_arduino.h index fb241f32e..189d9a0d6 100755 --- a/src/micro_ros_arduino.h +++ b/src/micro_ros_arduino.h @@ -81,12 +81,12 @@ static inline void set_microros_native_ethernet_udp_transports(byte mac[], IPAdd #endif -#if defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT) +#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT) -#if defined(TARGET_PORTENTA_H7_M7) +#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) #include #include -#else defined(ARDUINO_NANO_RP2040_CONNECT) +#elif defined(ARDUINO_NANO_RP2040_CONNECT) #include #include #endif @@ -102,10 +102,12 @@ struct micro_ros_agent_locator { }; static inline void set_microros_wifi_transports(char * ssid, char * pass, char * agent_ip, uint agent_port){ - while (WiFi.begin(ssid, pass) != WL_CONNECTED) - { - delay(500); - } + + WiFi.begin(ssid, pass); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + } static struct micro_ros_agent_locator locator; locator.address.fromString(agent_ip); diff --git a/src/wifi_transport.cpp b/src/wifi_transport.cpp index 4ad8d68bb..7c7d9c42c 100755 --- a/src/wifi_transport.cpp +++ b/src/wifi_transport.cpp @@ -1,12 +1,12 @@ -#if defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT) +#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT) #include -#if defined(TARGET_PORTENTA_H7_M7) +#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) #include #include -#else defined(ARDUINO_NANO_RP2040_CONNECT) +#elif defined(ARDUINO_NANO_RP2040_CONNECT) #include #include #endif From dc51660e91af9cd36aa376ed18c928e2670d7672 Mon Sep 17 00:00:00 2001 From: acuadros95 Date: Wed, 12 Jan 2022 12:24:27 +0100 Subject: [PATCH 2/3] Fix conflicts --- extras/library_generation/library_generation.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/extras/library_generation/library_generation.sh b/extras/library_generation/library_generation.sh index 7af70346c..3b3a389d1 100755 --- a/extras/library_generation/library_generation.sh +++ b/extras/library_generation/library_generation.sh @@ -54,8 +54,6 @@ pushd firmware/mcu_ws > /dev/null popd > /dev/null -<<<<<<< HEAD -======= cd firmware echo "" > /project/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) >> /project/built_packages; popd > /dev/null; done; @@ -70,7 +68,6 @@ fi cd /uros_ws ->>>>>>> a809407 (Add ESP32 support (#680)) ######## Clean and source ######## find /project/src/ ! -name micro_ros_arduino.h ! -name *.c ! -name *.cpp ! -name *.c.in -delete From 83952b427a1e9b136a72e9993f3aa81d2a393f6d Mon Sep 17 00:00:00 2001 From: acuadros95 Date: Wed, 12 Jan 2022 12:25:44 +0100 Subject: [PATCH 3/3] Fix conflict --- built_packages | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/built_packages b/built_packages index 0e1c8ed41..1c765b0d4 100755 --- a/built_packages +++ b/built_packages @@ -25,7 +25,6 @@ https://github.com/ros2/rcl_interfaces.git 9c9f5935cff0eeeffe7e3eb31beba396cb22d https://github.com/ros-controls/control_msgs a555c37f1a3536bb452ea555c58fdd9344d87614 https://github.com/eProsima/Micro-XRCE-DDS-Client.git e61bfa0e0bfdb74f4a592b2efbf7acbfcfeb6c1f https://github.com/eProsima/Micro-CDR.git cb4403a8780095df94a7b1936b1e00153c90070d -<<<<<<< HEAD https://github.com/ament/googletest.git baf8569d2e1f5dd48df1328466d04eabf920e57d https://github.com/ament/ament_cmake.git b474e31a3fc46df99b8d164e8ad65a7336fdb3c1 https://github.com/ament/ament_package.git 37f9a1f5e19a2513051ece437c3ef14a0cbaf836 @@ -34,13 +33,3 @@ https://github.com/ament/uncrustify_vendor.git fd52d19c51190e6277b39706f728cedb8 https://github.com/ament/ament_index.git 5ce2eba781801154d93c6fd7d6f66b23e4a7182d https://github.com/uncrustify/uncrustify.git 1d3d8fa5e81bece0fac4b81316b0844f7cc35926 https://github.com/ros2/ament_cmake_ros.git add4d35a981fadef6ffc7f5180bcb19a84acc08d -======= -https://github.com/ament/googletest.git 79c4c9db1a7bc8bc5473a280499bf776173653d6 -https://github.com/ament/ament_cmake.git 852a7d8abe8a743938a9167aa3f1f7b0a40e631f -https://github.com/ament/ament_package.git 54ff09f9eb8d35ca914376ae872cc7e60093547b -https://github.com/ament/ament_lint.git 4bc68c815ce308b3443e3cb38fd71e2b03ffdc40 -https://github.com/ament/uncrustify_vendor.git 8945c291fbd36d7980f7e4fd641601c277c178ec -https://github.com/ament/ament_index.git 7c8a2762453bf928909cc3dd65d2164b2f67dbaf -https://github.com/ros2/ament_cmake_ros.git 7b6b599c3fc8023806db2a97b344e8610902adac - ->>>>>>> a809407 (Add ESP32 support (#680))