-
Notifications
You must be signed in to change notification settings - Fork 138
Open
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
---
<OUTPUT STOPS>
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 <micro_ros_arduino.h>
#include <stdio.h>
#include <rcl/rcl.h>
#include <rcl/error_handling.h>
#include <rclc/rclc.h>
#include <std_msgs/msg/int32.h>
#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);
}
Metadata
Metadata
Assignees
Labels
No labels