micro-ROS / micro-ROS/micro_ros_arduino
Workaround for micro-ros_publisher_wifi example hanging after 90 seconds
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 576
- Forks
- 146
- PR merge metrics
- No merged PRs in 30d
Description
## Issue template
I'd like to share a workaround for micro-ros_publisher_wifi example hanging after 90 seconds.
- Hardware description: a ESP32-WROOM-32 board connected to a Docker
- RTOS: Arduino "ESP32 Dev Module" board, default settings, with Micro-ROS
- Installation type: microros/micro-ros-agent:humble image, Arduino IDE 1.8.13 (Windows), v2.0.7-humble precompiled Micro-ROS
- Version or commit hash: humble
#### Steps to reproduce the issue
- Edit the sketch below to specify your WiFi SSID, password and IP of your PC that will run a Micro-ROS agent. Use the Arduino IDE (Windows) to compile and upload the sketch to an ESP32 module.
- Launch the Micro-ROS agent. In my case, I'm using a Windows machine with Docker-for-Windows installed. Here is the Windows shell command to launch the Docker Micro-ROS agent image.
```
docker run --name micro-ros-agent-humble -it -p 8888:8888/udp microros/micro-ros-agent:humble udp4 -p 8888
```
Once ESP32 connects to WiFi and Micro-ROS agent, I launch another bash and run
```
ros2 topic echo int32pub
data: 1201
---
data: 1202
---
data: 1203
---
data: 1204
...
```
#### Expected behavior
micro-ros_publisher_wifi example keeps running indefinitely long, until powered down
#### Actual behavior
After received 90 seconds. `ros2 topic echo int32pub` hangs, does not output message data anymore.
```
ros2 topic echo int32pub
...
data: 1796
---
data: 1797
---
data: 1798
---
```
#### Additional information
I've fixed this behavior by having ESP32 ping Micro-ROS agent periodically. Please see the code below.
I have also fixed this by
- changing rclc_publisher_init_best_effort() to rclc_publisher_init_best_effort()
- adding a subscriber to ESP32
Either of the fixes work, but the ping one is the most convenient for me.
```
#include
#include
#include
#include
#include
#include
#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;
std_msgs__msg__Int32 msg;
rclc_support_t support;
rcl_allocator_t allocator;
rcl_node_t node;
#define LED_PIN 2
#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(){
Serial.println(F("error_loop()"));
while(1){
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
delay(100);
}
}
void setup() {
Serial.begin(115200);
set_microros_wifi_transports((char*)"WIFI_SSID", (char*)"WIFI_PASSWORD",
(char*)"192.168.1.UROS_AGENT_IP", 8888);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
delay(2000);
allocator = rcl_get_default_allocator();
RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));
RCCHECK(rclc_node_init_default(&node, "uros_arduino", "", &support));
RCCHECK(rclc_publisher_init_best_effort(
&publisher,
&node,
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
"int32pub"));
msg.data = 0;
}
void loop() {
rcl_ret_t rc = rcl_publish(&publisher, &msg, NULL);
msg.data++;
if ((rc == RCL_RET_OK) && (msg.data % 600 == 0)) {
// pub freezes after 90sec if the line below is commented out
rmw_uros_ping_agent(1, 1);
}
delay(50);
}
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the micro_ros_publisher_wifi example and reproduce the ESP32 setup using the provided Docker Micro-ROS agent command. Read the publisher loop and the rmw_uros_ping_agent workaround, then investigate why publishing stops after about 90 seconds; done means the example runs indefinitely or the workaround is documented clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, docker
- Domain
- embedded-iot, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100