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

WiFiEspAT Support #1425

Merged
merged 13 commits into from
Jun 28, 2023
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
arduino-cli lib install WiFiNINA
arduino-cli lib install "STM32duino X-NUCLEO-IKS01A3"
arduino-cli lib install "Seeed Arduino rpcWiFi" # Dependent libraries(e.g. "Seeed Arduino rpcUnified") will be installed together. See https://wiki.seeedstudio.com/Wio-Terminal-Network-Overview/#needed-libraries-for-wi-fi for more details.
arduino-cli lib install WiFiEspAT
# Build all demos
arduino-cli compile --fqbn OpenCR:OpenCR:OpenCR /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher -v
arduino-cli compile --fqbn OpenCR:OpenCR:OpenCR /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_addtwoints_service -v
Expand Down Expand Up @@ -81,3 +82,5 @@ jobs:
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
arduino-cli compile --fqbn Seeeduino:samd:seeed_wio_terminal /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher_wifi -v
# Build micro-ros_publisher-wifi_at for WiFi non-native board with ESP-AT
arduino-cli compile --fqbn arduino:mbed:pico /github/home/Arduino/libraries/micro_ros_arduino/examples/micro-ros_publisher_wifi_at -v
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,30 @@ As the build process for ROS 2 and micro-ROS is based on custom meta-build syste

Supported boards are:

| Board | Min version | State | Details | .meta file |
| ----------------------------------------------------------------------------------- | ----------- | ---------- | --------------------------------------------------------------------------------------------------- | ------------------------ |
| [Arduino Portenta H7 M7 Core](https://store.arduino.cc/portenta-h7) | v1.8.5 | Supported | Official Arduino support | `colcon.meta` |
| [Arduino Nano RP2040 Connect](https://docs.arduino.cc/hardware/nano-rp2040-connect) | v1.8.5 | Supported | Official Arduino support | `colcon_verylowmem.meta` |
| [OpenCR](https://emanual.robotis.com/docs/en/parts/controller/opencr10/) | v1.4.16 | Supported | [Based on custom board](https://emanual.robotis.com/docs/en/parts/controller/opencr10/#arduino-ide) | `colcon.meta` |
| [Teensy 4.0](https://www.pjrc.com/store/teensy40.html) | v1.8.5 | Not tested | [Based on Teensyduino](https://www.pjrc.com/arduino-ide-2-0-0-teensy-support/) | `colcon.meta` |
| [Teensy 4.1](https://www.pjrc.com/store/teensy41.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/arduino-ide-2-0-0-teensy-support/) | `colcon.meta` |
| [Teensy 3.2/3.1](https://www.pjrc.com/store/teensy32.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/arduino-ide-2-0-0-teensy-support/) | `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/arduino-ide-2-0-0-teensy-support/) | `colcon_lowmem.meta` |
| [Teensy 3.6](https://www.pjrc.com/store/teensy36.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/arduino-ide-2-0-0-teensy-support/) | `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` |
| Board | Min version | State | Details | .meta file |
| ----------------------------------------------------------------------------------------------------------- | ----------- | ---------- | ---------------------------------------------------------------------------------------------------- | ------------------------ |
| [Arduino Portenta H7 M7 Core](https://store.arduino.cc/portenta-h7) | v1.8.5 | Supported | Official Arduino support | `colcon.meta` |
| [Arduino Nano RP2040 Connect](https://docs.arduino.cc/hardware/nano-rp2040-connect) | v1.8.5 | Supported | Official Arduino support | `colcon_verylowmem.meta` |
| [OpenCR](https://emanual.robotis.com/docs/en/parts/controller/opencr10/) | v1.4.16 | Supported | [Based on custom board](https://emanual.robotis.com/docs/en/parts/controller/opencr10/#arduino-ide) | `colcon.meta` |
| [Teensy 4.0](https://www.pjrc.com/store/teensy40.html) | v1.8.5 | Not tested | [Based on Teensyduino](https://www.pjrc.com/arduino-ide-2-0-0-teensy-support/) | `colcon.meta` |
| [Teensy 4.1](https://www.pjrc.com/store/teensy41.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/arduino-ide-2-0-0-teensy-support/) | `colcon.meta` |
| [Teensy 3.2/3.1](https://www.pjrc.com/store/teensy32.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/arduino-ide-2-0-0-teensy-support/) | `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/arduino-ide-2-0-0-teensy-support/) | `colcon_lowmem.meta` |
| [Teensy 3.6](https://www.pjrc.com/store/teensy36.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/arduino-ide-2-0-0-teensy-support/) | `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:

| Board | Min version | Contributor | Details | .meta file |
| ---------------------------------------------------------------------------------------- | ----------- | ---------------------------------------------- | ------- | ------------------------ |
| [Arduino Due](https://store.arduino.cc/arduino-due) | - | [@lukicdarkoo](https://github.com/lukicdarkoo) | | `colcon_verylowmem.meta` |
| [Arduino Zero](https://store.arduino.cc/arduino-zero) | - | [@lukicdarkoo](https://github.com/lukicdarkoo) | | `colcon_verylowmem.meta` |
| [Kakute F7](http://www.holybro.com/product/kakute-f7-aio-v1-5/) | - | [@amfern](https://github.com/amfern) | | `colcon.meta` |
| [STM32-E407](https://www.olimex.com/Products/ARM/ST/STM32-E407/resources/STM32-E407.pdf) | - | [@dominikn](https://github.com/dominikn) | | `colcon.meta` |
| [Wio Terminal](https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/) | - | [@maehara-keisuke](https://github.com/maehara-keisuke) | | `colcon.meta` |
| Board | Min version | Contributor | Details | .meta file |
| ---------------------------------------------------------------------------------------- | ----------- | ------------------------------------------------------ | ------------------------------------------------------------------------- | ------------------------ |
| [Arduino Due](https://store.arduino.cc/arduino-due) | - | [@lukicdarkoo](https://github.com/lukicdarkoo) | | `colcon_verylowmem.meta` |
| [Arduino Zero](https://store.arduino.cc/arduino-zero) | - | [@lukicdarkoo](https://github.com/lukicdarkoo) | | `colcon_verylowmem.meta` |
| [Kakute F7](http://www.holybro.com/product/kakute-f7-aio-v1-5/) | - | [@amfern](https://github.com/amfern) | | `colcon.meta` |
| [STM32-E407](https://www.olimex.com/Products/ARM/ST/STM32-E407/resources/STM32-E407.pdf) | - | [@dominikn](https://github.com/dominikn) | | `colcon.meta` |
| [Wio Terminal](https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/) | - | [@maehara-keisuke](https://github.com/maehara-keisuke) | | `colcon.meta` |
| [Raspberry Pi Pico](https://www.raspberrypi.com/documentation/microcontrollers/) | - | [@maehara-keisuke](https://github.com/maehara-keisuke) | with [ESP-AT](https://www.espressif.com/en/products/sdks/esp-at/overview) | `colcon_verylowmem.meta` |
| [Seeed Studio XIAO SAMD21](https://wiki.seeedstudio.com/Seeeduino-XIAO/) | - | [@maehara-keisuke](https://github.com/maehara-keisuke) | with [ESP-AT](https://www.espressif.com/en/products/sdks/esp-at/overview) | `colcon_verylowmem.meta` |
| [Seeed Studio XIAO RP2040](https://wiki.seeedstudio.com/XIAO-RP2040/) | - | [@maehara-keisuke](https://github.com/maehara-keisuke) | with [ESP-AT](https://www.espressif.com/en/products/sdks/esp-at/overview) | `colcon_verylowmem.meta` |

You can find the available precompiled ROS 2 types for messages and services in [available_ros2_types](available_ros2_types).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <std_msgs/msg/int32.h>

#if !defined(ESP32) && !defined(TARGET_PORTENTA_H7_M7) && !defined(ARDUINO_NANO_RP2040_CONNECT) && !defined(ARDUINO_WIO_TERMINAL)
#error This example is only avaible for Arduino Portenta, Arduino Nano RP2040 Connect, ESP32 Dev module and Wio Terminal
#error This example is only available for Arduino Portenta, Arduino Nano RP2040 Connect, ESP32 Dev module and Wio Terminal
#endif

rcl_publisher_t publisher;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// To use "ESP-AT External WiFi module"(hereinafter called "ESP-AT") with your board, install "WiFiEspAT" from Library Manager.
// See https://www.espressif.com/en/products/sdks/esp-at/overview for more details about ESP-AT.

#define BOARD_WITH_ESP_AT
// Configurations about communication between Host MCU and ESP-AT.
// In most cases, you would burn ESP-AT firmware v2 or later. And you should uncomment "#define WIFIESPAT1" in EspAtDrvTypes.h
// See https://github.com/JAndrassy/WiFiEspAT/tree/7f398e14f331fc845c4af671f1946fe3f29a744f#getting-started for more details.
#define ESP_AT_SERIAL_PORT Serial1 // Serial port object to ESP-AT
#define ESP_AT_BAUDRATE 115200 // Baudrate setting in ESP-AT firmware(default is 115200)
#define ESP_AT_RESET_PIN -1 // GPIO_PIN connected to ESP-AT's reset pin(-1 means not to use hardware reset)

#include <micro_ros_arduino.h>

#include <wifi_transport.cpp>

#include <stdio.h>
#include <rcl/rcl.h>
#include <rcl/error_handling.h>
#include <rclc/rclc.h>
#include <rclc/executor.h>

#include <std_msgs/msg/int32.h>

#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_WIO_TERMINAL)
#define BOARD_HAS_NATIVE_WIFI
#endif

#if defined(BOARD_HAS_NATIVE_WIFI)
#error This example is not available for boards that have native WiFi.
#endif

rcl_publisher_t publisher;
std_msgs__msg__Int32 msg;
rclc_support_t support;
rcl_allocator_t allocator;
rcl_node_t node;

#define LED_PIN 13

#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}}
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}


void error_loop(){
while(1){
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
delay(100);
}
}

void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
{
RCLC_UNUSED(last_call_time);
if (timer != NULL) {
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
msg.data++;
}
}

void setup() {
set_microros_wifi_transports("WIFI SSID", "WIFI PASS", "192.168.1.57", 8888);

pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);

delay(2000);

allocator = rcl_get_default_allocator();

//create init_options
RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));

// create node
RCCHECK(rclc_node_init_default(&node, "micro_ros_arduino_wifi_node", "", &support));

// create publisher
RCCHECK(rclc_publisher_init_best_effort(
&publisher,
&node,
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
"topic_name"));

msg.data = 0;
}

void loop() {
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
msg.data++;
}
13 changes: 12 additions & 1 deletion src/micro_ros_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static inline void set_microros_native_ethernet_udp_transports(byte mac[], IPAdd

#endif

#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_WIO_TERMINAL)
#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_WIO_TERMINAL) || defined(BOARD_WITH_ESP_AT)

#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7)
#include <WiFi.h>
Expand All @@ -106,6 +106,8 @@ static inline void set_microros_native_ethernet_udp_transports(byte mac[], IPAdd
#elif defined(ARDUINO_WIO_TERMINAL)
#include <rpcWiFi.h>
#include <WiFiUdp.h>
#elif defined(BOARD_WITH_ESP_AT)
#include <WiFiEspAT.h>
#endif

extern "C" bool arduino_wifi_transport_open(struct uxrCustomTransport * transport);
Expand All @@ -121,6 +123,15 @@ struct micro_ros_agent_locator {

static inline void set_microros_wifi_transports(char * ssid, char * pass, char * agent_ip, uint agent_port){

#if defined(BOARD_WITH_ESP_AT)
ESP_AT_SERIAL_PORT.begin(ESP_AT_BAUDRATE);
while (!ESP_AT_SERIAL_PORT) {
}
WiFi.init(ESP_AT_SERIAL_PORT, ESP_AT_RESET_PIN);
while (WiFi.status() == WL_NO_MODULE) {
}
#endif

WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {
Expand Down
4 changes: 3 additions & 1 deletion src/wifi_transport.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_WIO_TERMINAL)
#if defined(ESP32) || defined(TARGET_PORTENTA_H7_M7) || defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_WIO_TERMINAL) || defined(BOARD_WITH_ESP_AT)
#include <Arduino.h>


Expand All @@ -11,6 +11,8 @@
#elif defined(ARDUINO_WIO_TERMINAL)
#include <rpcWiFi.h>
#include <WiFiUdp.h>
#elif defined(BOARD_WITH_ESP_AT)
#include <WiFiEspAT.h>
#endif

#include <micro_ros_arduino.h>
Expand Down