Skip to content

Commit cdb2a0c

Browse files
committed
Fix ros agent issue with RMW
Resolves an issue where an incomplete handshake with the ROS agent caused an error failure code during microros initialization.
1 parent 75ed059 commit cdb2a0c

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r2_ros/mpconfigboard.mk

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,30 @@ CIRCUITPY_ESP_PSRAM_MODE = qio
1414
CIRCUITPY_ESP_PSRAM_FREQ = 80m
1515

1616
CIRCUITPY_RCLCPY = 1
17+
18+
# turn off for debug flash space
19+
CIRCUITPY_ESPCAMERA = 0
20+
CIRCUITPY_AESIO = 0
21+
CIRCUITPY_AUDIOBUSIO = 0
22+
CIRCUITPY_AUDIOCORE = 0
23+
CIRCUITPY_AUDIOIO = 0
24+
CIRCUITPY_AUDIOMIXER = 0
25+
CIRCUITPY_AUDIOMP3 = 0
26+
CIRCUITPY_BLEIO_HCI = 0
27+
CIRCUITPY_DISPLAYIO = 0
28+
CIRCUITPY_FLOPPYIO = 0
29+
CIRCUITPY_FRAMEBUFFERIO = 0
30+
CIRCUITPY_PIXELMAP = 0
31+
CIRCUITPY_GETPASS = 0
32+
CIRCUITPY_KEYPAD = 0
33+
CIRCUITPY_MSGPACK = 0
34+
CIRCUITPY_PIXELBUF = 0
35+
CIRCUITPY_PS2IO = 0
36+
CIRCUITPY_RGBMATRIX = 0
37+
CIRCUITPY_RAINBOWIO = 0
38+
CIRCUITPY_ROTARYIO = 0
39+
CIRCUITPY_TOUCHIO = 0
40+
CIRCUITPY_USB_HID = 0
41+
CIRCUITPY_USB_MIDI = 0
42+
CIRCUITPY_WARNINGS = 0
43+
CIRCUITPY_ULAB = 0
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
CONFIG_MICRO_ROS_ESP_XRCE_DDS_MIDDLEWARE=y
22
CONFIG_MICRO_ROS_ESP_NETIF_WLAN=y
3-
CONFIG_MICRO_ROS_AGENT_IP="192.168.1.100"
4-
CONFIG_MICRO_ROS_AGENT_PORT="8888"
53
CONFIG_MICRO_ROS_APP_STACK=16000
64
CONFIG_MICRO_ROS_APP_TASK_PRIO=5

ports/espressif/common-hal/rclcpy/__init__.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
#include "shared-bindings/rclcpy/__init__.h"
88

9+
#include "esp_log.h"
10+
11+
#define RCLCPY_DOMAIN_ID 3
12+
#define RCLCPY_AGENT_IP "192.168.10.111"
13+
#define RCLCPY_AGENT_PORT "8888"
14+
915
rclcpy_context_t rclcpy_default_context = {
1016
.initialized = false,
1117
};
@@ -44,16 +50,43 @@ void common_hal_rclcpy_init(void) {
4450
custom_allocator.deallocate = microros_deallocate;
4551
custom_allocator.reallocate = microros_reallocate;
4652
custom_allocator.zero_allocate = microros_zero_allocate;
47-
4853
// Set custom allocator as default
4954
if (!rcutils_set_default_allocator(&custom_allocator)) {
55+
ESP_LOGW("RCLCPY", "allocator failure");
5056
mp_raise_RuntimeError(MP_ERROR_TEXT("ROS memory allocator failure"));
5157
}
52-
5358
rclcpy_default_context.rcl_allocator = custom_allocator;
59+
5460
rcl_ret_t ret;
55-
ret = rclc_support_init(&rclcpy_default_context.rcl_support, 0, NULL, &rclcpy_default_context.rcl_allocator);
61+
62+
// Options Init
63+
rclcpy_default_context.init_options = rcl_get_zero_initialized_init_options();
64+
ret = rcl_init_options_init(&rclcpy_default_context.init_options, rclcpy_default_context.rcl_allocator);
65+
if (ret != RCL_RET_OK) {
66+
ESP_LOGW("RCLCPY", "Options init failure: %d", ret);
67+
}
68+
ret = rcl_init_options_set_domain_id(&rclcpy_default_context.init_options, RCLCPY_DOMAIN_ID);
5669
if (ret != RCL_RET_OK) {
70+
ESP_LOGW("RCLCPY", "Options domain failure: %d", ret);
71+
}
72+
73+
// Set up Agent
74+
rclcpy_default_context.rmw_options = rcl_init_options_get_rmw_init_options(&rclcpy_default_context.init_options);
75+
ret = rmw_uros_options_set_udp_address(RCLCPY_AGENT_IP, RCLCPY_AGENT_PORT, rclcpy_default_context.rmw_options);
76+
if (ret != RCL_RET_OK) {
77+
ESP_LOGW("RCLCPY", "Agent options failure: %d", ret);
78+
}
79+
//RCCHECK(rmw_uros_discover_agent(rmw_options));
80+
81+
// Support Init
82+
// ret = rclc_support_init(&rclcpy_default_context.rcl_support, 0, NULL, &rclcpy_default_context.rcl_allocator);
83+
ret = rclc_support_init_with_options(&rclcpy_default_context.rcl_support,
84+
0,
85+
NULL,
86+
&rclcpy_default_context.init_options,
87+
&rclcpy_default_context.rcl_allocator);
88+
if (ret != RCL_RET_OK) {
89+
ESP_LOGW("RCLCPY", "Initialization failure: %d", ret);
5790
mp_raise_RuntimeError(MP_ERROR_TEXT("ROS failed to initialize"));
5891
} else {
5992
rclcpy_default_context.initialized = true;
@@ -66,4 +99,4 @@ rclcpy_context_t * common_hal_rclcpy_get_default_context(void) {
6699

67100
bool common_hal_rclcpy_default_context_is_initialized(void) {
68101
return rclcpy_default_context.initialized;
69-
}
102+
}

ports/espressif/common-hal/rclcpy/__init__.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
#include <rcl/error_handling.h>
1515
#include <rclc/rclc.h>
1616
#include <rclc/executor.h>
17+
#include <rmw_microros/rmw_microros.h>
1718

1819
typedef struct {
1920
bool initialized;
2021
rcl_allocator_t rcl_allocator;
2122
rclc_support_t rcl_support;
23+
rcl_init_options_t init_options;
24+
rmw_init_options_t* rmw_options;
2225
} rclcpy_context_t;
2326

2427
extern rclcpy_context_t rclcpy_default_context;

0 commit comments

Comments
 (0)