Skip to content

Commit 6b15ab7

Browse files
Add ESP32 Ethernet transport (#169)
* wip * wip * wip * wip * wip * wip * single callback * update example * wip * wip * wip * wip * Update README.md Co-authored-by: Pablo Garrido <pablogs9@gmail.com> --------- Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
1 parent 1da069f commit 6b15ab7

File tree

10 files changed

+600
-13
lines changed

10 files changed

+600
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
platform: [teensy41, teensy40, teensy36, teensy35, teensy31, due, zero, olimex_e407, esp32dev, nanorp2040connect, portenta_h7_m7, teensy41_eth, nanorp2040connect_wifi, portenta_h7_m7_wifi, esp32dev_wifi, portenta_h7_m7_humble, portenta_h7_m7_jazzy, portenta_h7_m7_rolling, teensy41_custom, pico]
17+
platform: [teensy41, teensy40, teensy36, teensy35, teensy31, due, zero, olimex_e407, esp32dev, nanorp2040connect, portenta_h7_m7, teensy41_eth, nanorp2040connect_wifi, portenta_h7_m7_wifi, esp32dev_wifi, esp32dev_ethernet, portenta_h7_m7_humble, portenta_h7_m7_jazzy, portenta_h7_m7_rolling, teensy41_custom, pico]
1818

1919
steps:
2020
- uses: actions/checkout@v3

README.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ PlatformIO will handle the full build process, including dependencies, compilati
2828
## Supported boards
2929
Supported boards are:
3030

31-
| Board | Platform | Framework | Transports | Default meta file |
32-
| -------------------------------------------- | ------------- | ----------- | -------------------------------- | ------------------------ |
33-
| `portenta_h7_m7` | `ststm32` | `arduino` | `serial` <br/> `wifi` | `colcon.meta` |
34-
| `teensy41` | `teensy` | `arduino` | `serial` <br/> `native_ethernet` | `colcon.meta` |
35-
| `teensy40` | `teensy` | `arduino` | `serial` | `colcon.meta` |
36-
| `teensy36` <br/> `teensy35` <br/> `teensy31` | `teensy` | `arduino` | `serial` | `colcon_lowmem.meta` |
37-
| `due` | `atmelsam` | `arduino` | `serial` | `colcon_verylowmem.meta` |
38-
| `zero` | `atmelsam` | `arduino` | `serial` | `colcon_verylowmem.meta` |
39-
| `olimex_e407` | `ststm32` | `arduino` | `serial` | `colcon.meta` |
40-
| `esp32dev` | `espressif32` | `arduino` | `serial` <br/> `wifi` | `colcon.meta` |
41-
| `nanorp2040connect` | `raspberrypi` | `arduino` | `serial` <br/> `wifi_nina` | `colcon_verylowmem.meta` |
42-
| `pico` | `raspberrypi` | `arduino` | `serial` | `colcon.meta`|
31+
| Board | Platform | Framework | Transports | Default meta file |
32+
| -------------------------------------------- | ------------- | ----------- | ---------------------------------------- | ------------------------ |
33+
| `portenta_h7_m7` | `ststm32` | `arduino` | `serial` <br/> `wifi` | `colcon.meta` |
34+
| `teensy41` | `teensy` | `arduino` | `serial` <br/> `native_ethernet` | `colcon.meta` |
35+
| `teensy40` | `teensy` | `arduino` | `serial` | `colcon.meta` |
36+
| `teensy36` <br/> `teensy35` <br/> `teensy31` | `teensy` | `arduino` | `serial` | `colcon_lowmem.meta` |
37+
| `due` | `atmelsam` | `arduino` | `serial` | `colcon_verylowmem.meta` |
38+
| `zero` | `atmelsam` | `arduino` | `serial` | `colcon_verylowmem.meta` |
39+
| `olimex_e407` | `ststm32` | `arduino` | `serial` | `colcon.meta` |
40+
| `esp32dev` | `espressif32` | `arduino` | `serial` <br/> `wifi` <br/> `ethernet`* | `colcon.meta` |
41+
| `nanorp2040connect` | `raspberrypi` | `arduino` | `serial` <br/> `wifi_nina` | `colcon_verylowmem.meta` |
42+
| `pico` | `raspberrypi` | `arduino` | `serial` | `colcon.meta` |
43+
44+
\* Community contributed
4345

4446
The community is encouraged to open pull request with custom use cases.
4547

@@ -133,6 +135,19 @@ The transport can be configured with the `board_microros_transport = <transport>
133135
set_microros_native_ethernet_transports(local_mac, local_ip, agent_ip, agent_port);
134136
```
135137

138+
- `ethernet`
139+
140+
```c
141+
IPAddress client_ip(192, 168, 1, 177);
142+
IPAddress gateway(192, 168, 1, 1);
143+
IPAddress netmask(255, 255, 255, 0);
144+
IPAddress agent_ip(192, 168, 1, 113);
145+
size_t agent_port = 8888;
146+
147+
// Optional hostname, defaults to nullptr (no hostname set)
148+
set_microros_ethernet_transports(client_ip, gateway, netmask, agent_ip, agent_port, "my-microros-device");
149+
```
150+
136151
- `custom`
137152

138153
The user will need to write transport functions in app code and provide it to the micro-ROS library using [`rmw_uros_set_custom_transport()` API](https://micro.ros.org/docs/tutorials/advanced/create_custom_transports/)

ci/platformio.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ board_microros_transport = native_ethernet
138138
lib_deps =
139139
../
140140

141+
[env:esp32dev_ethernet]
142+
platform = espressif32
143+
board = esp32dev
144+
framework = arduino
145+
board_microros_transport = ethernet
146+
lib_deps =
147+
../
148+
141149
; WiFi platforms
142150

143151
[env:portenta_h7_m7_wifi]

ci/src/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#if defined(MICRO_ROS_TRANSPORT_ARDUINO_WIFI)
44
#include <WiFi.h>
5+
#elif defined(MICRO_ROS_TRANSPORT_ARDUINO_ETHERNET)
6+
#include <ETH.h>
57
#endif
68

79
#include <micro_ros_platformio.h>
@@ -78,6 +80,14 @@ void setup() {
7880
char psk[]= "WIFI_PSK";
7981

8082
set_microros_wifi_transports(ssid, psk, agent_ip, agent_port);
83+
#elif defined(MICRO_ROS_TRANSPORT_ARDUINO_ETHERNET)
84+
IPAddress local_ip(192, 168, 1, 177);
85+
IPAddress gateway(192, 168, 1, 1);
86+
IPAddress netmask(255, 255, 255, 0);
87+
IPAddress agent_ip(192, 168, 1, 113);
88+
size_t agent_port = 8888;
89+
90+
set_microros_ethernet_transports(local_ip, gateway, netmask, agent_ip, agent_port, "micro-ros-eth");
8191
#elif defined(MICRO_ROS_TRANSPORT_ARDUINO_CUSTOM)
8292
rmw_uros_set_custom_transport(
8393
MICROROS_TRANSPORTS_FRAMING_MODE,

examples/ethernet_pubsub/README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# micro-ROS Ethernet Publisher/Subscriber Example
2+
3+
This example demonstrates how to create a micro-ROS node on an ESP32 that communicates over Ethernet with a ROS 2 system. The node implements a simple request-response pattern where it listens for names and responds with greetings.
4+
5+
## Overview
6+
7+
The ESP32 node:
8+
- Subscribes to the topic `micro_ros_name`
9+
- When it receives a name (e.g., "John"), it publishes "Hello John!" to the topic `micro_ros_response`
10+
- Uses Ethernet for communication with the ROS 2 system
11+
- Operates on ROS 2 domain ID 8
12+
13+
## Hardware Requirements
14+
15+
- ESP32 development board
16+
- LAN8710 or LAN8720 Ethernet PHY module
17+
- Ethernet cable
18+
19+
### Ethernet PHY Wiring
20+
21+
Connect the LAN8720 module to the ESP32 using the following pins:
22+
23+
| ESP32 GPIO | LAN87XX Pin | Description |
24+
|------------|-------------|-------------|
25+
| GPIO 5 | POWER | PHY Power |
26+
| GPIO 23 | MDC | Clock |
27+
| GPIO 18 | MDIO | Data |
28+
| GPIO 17 | Clock | 50MHz Clock |
29+
30+
## Network Configuration
31+
32+
The example uses the following network configuration (configurable in `main.cpp`):
33+
34+
- ESP32 IP: 10.4.4.177
35+
- Gateway: 10.4.4.1
36+
- Netmask: 255.255.255.0
37+
- Agent IP: 10.4.4.187
38+
- Agent Port: 8888
39+
40+
## Software Setup
41+
42+
1. Install PlatformIO (if not already installed)
43+
2. Install Docker and Docker Compose
44+
3. Clone this repository
45+
4. Navigate to the example directory:
46+
```bash
47+
cd examples/ethernet_pubsub
48+
```
49+
50+
## Building and Flashing
51+
52+
1. Build and flash the firmware:
53+
```bash
54+
pio run -t upload
55+
```
56+
57+
2. (Optional) Monitor the serial output:
58+
```bash
59+
pio device monitor
60+
```
61+
62+
## Running the micro-ROS Agent and RQT
63+
64+
1. Allow X11 connections from Docker (needed for RQT):
65+
```bash
66+
xhost +local:docker
67+
```
68+
69+
2. Start the micro-ROS agent and RQT:
70+
```bash
71+
docker compose up
72+
```
73+
74+
This will start:
75+
- A micro-ROS agent listening on UDP port 8888
76+
- RQT with proper X11 forwarding for visualization
77+
78+
## Testing the Example
79+
80+
1. In RQT:
81+
- Click on Plugins -> Topics -> Message Publisher
82+
- Add the topic `/micro_ros_name`
83+
- Set the message type to `std_msgs/String`
84+
- Enter a name in the `data` field and click the checkbox to publish
85+
86+
2. To view responses:
87+
- In RQT, click on Plugins -> Topics -> Topic Monitor
88+
- Subscribe to `/micro_ros_response`
89+
- You should see responses like "Hello <name>!" when you publish names
90+
91+
## Troubleshooting
92+
93+
- If RQT doesn't appear, ensure X11 forwarding is properly set up with `xhost +local:docker`
94+
- Check the serial monitor for connection status and debugging information
95+
- Verify that your network configuration matches the settings in `main.cpp`
96+
- Ensure all Ethernet pins are properly connected
97+
98+
## Cleaning Up
99+
100+
1. Stop the Docker containers:
101+
```bash
102+
docker compose down
103+
```
104+
105+
2. Revoke X11 permissions (optional):
106+
```bash
107+
xhost -local:docker
108+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: "2.1"
2+
3+
services:
4+
micro-ros-agent:
5+
image: microros/micro-ros-agent:humble
6+
container_name: micro-ros-agent
7+
network_mode: host
8+
stdin_open: true
9+
tty: true
10+
environment:
11+
- ROS_DOMAIN_ID=8
12+
ports:
13+
- 8888:8888/udp
14+
command: udp4 --port 8888 --verbose 6
15+
16+
rqt:
17+
image: osrf/ros:humble-desktop
18+
container_name: rqt-visualizer
19+
network_mode: host
20+
ipc: host
21+
pid: host
22+
tty: true
23+
privileged: true
24+
device_cgroup_rules:
25+
- 'c 189:* rmw'
26+
environment:
27+
- ROS_DOMAIN_ID=8
28+
- DISPLAY=${DISPLAY}
29+
- QT_X11_NO_MITSHM=1
30+
volumes:
31+
- /tmp/.X11-unix:/tmp/.X11-unix:rw
32+
command: bash -c "source /opt/ros/humble/setup.bash && rqt"
33+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[env:esp32dev]
2+
platform = espressif32
3+
board = esp32dev
4+
framework = arduino
5+
board_microros_transport = ethernet
6+
monitor_speed = 115200
7+
lib_deps =
8+
https://github.com/micro-ROS/micro_ros_platformio

0 commit comments

Comments
 (0)