8000 Requested fixes to exceptions, docs, config · cezer-io/circuitpython@635c8b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 635c8b1

Browse files
committed
Requested fixes to exceptions, docs, config
1 parent 5924719 commit 635c8b1

File tree

12 files changed

+65
-74
lines changed

12 files changed

+65
-74
lines changed

locale/circuitpython.pot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,11 @@ msgstr ""
864864
msgid "Couldn't allocate decoder"
865865
msgstr ""
866866

867+
#: ports/espressif/common-hal/rclcpy/__init__.c
868+
#, c-format
869+
msgid "Critical ROS failure during soft reboot, reset required: %d"
870+
msgstr ""
871+
867872
#: ports/stm/common-hal/analogio/AnalogOut.c
868873
msgid "DAC Channel Init Error"
869874
msgstr ""
@@ -1877,6 +1882,10 @@ msgstr ""
18771882
msgid "ROS failed to initialize. Is agent connected?"
18781883
msgstr ""
18791884

1885+
#: ports/espressif/common-hal/rclcpy/__init__.c
1886+
msgid "ROS internal setup failure"
1887+
msgstr ""
1888+
18801889
#: ports/espressif/common-hal/rclcpy/__init__.c
18811890
msgid "ROS memory allocator failure"
18821891
msgstr ""

ports/espressif/Makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,15 @@ ESP_IDF_COMPONENTS_EXPANDED += $(BUILD)/esp-idf/esp-idf/esp-camera/libesp-camera
724724
endif
725725

726726
ifneq ($(CIRCUITPY_RCLCPY),0)
727-
ifeq ($(IDF_TARGET),esp32)
728-
BINARY_BLOBS += microros-lib/esp32/libmicroros.a
729-
else ifeq ($(IDF_TARGET),esp32s2)
730-
BINARY_BLOBS+= microros-lib/esp32s2/libmicroros.a
731-
else ifeq ($(IDF_TARGET),esp32s3)
732-
BINARY_BLOBS += microros-lib/esp32s3/libmicroros.a
733-
endif
727+
ifeq ($(IDF_TARGET),esp32)
728+
BINARY_BLOBS += microros-lib/esp32/libmicroros.a
729+
else ifeq ($(IDF_TARGET),esp32s2)
730+
BINARY_BLOBS+= microros-lib/esp32s2/libmicroros.a
731+
else ifeq ($(IDF_TARGET),esp32s3)
732+
BINARY_BLOBS += microros-lib/esp32s3/libmicroros.a
733+
else
734+
$(error Unsupported Espressif target for Micro-ROS: $(IDF_TARGET).)
735+
endif
734736
endif
735737

736738
ifneq ($(VALID_BOARD),)

ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r2_ros/mpconfigboard.mk

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,3 @@ 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

ports/espressif/boards/m5stack_cardputer_ros/board.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "py/ringbuf.h"
1818
#include "shared/runtime/interrupt_char.h"
1919

20+
2021
#define DELAY 0x80
2122

2223
uint8_t display_init_sequence[] = {
@@ -41,7 +42,6 @@ uint8_t display_init_sequence[] = {
4142

4243
// Overrides the weakly linked function from supervisor/shared/board.c
4344
void board_init(void) {
44-
4545
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
4646
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
4747
bus->base.type = &f 8000 ourwire_fourwire_type;

ports/espressif/boards/m5stack_cardputer_ros/cardputer_keyboard.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ void cardputer_keyboard_init(void) {
110110
row_addr_pins, // row_addr_pins
111111
7, // num_column_pins
112112
column_pins, // column_pins
113+
true, // columns_to_anodes
114+
false, // transpose
113115
0.01f, // interval
114116
20, // max_events
115117
2 // debounce_threshold

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "esp_log.h"
1111

12-
1312
void common_hal_rclcpy_node_construct(rclcpy_node_obj_t *self,
1413
const char *node_name, const char *node_namespace) {
1514

@@ -28,9 +27,11 @@ void common_hal_rclcpy_node_deinit(rclcpy_node_obj_t *self) {
2827
if (common_hal_rclcpy_node_deinited(self)) {
2928
return;
3029
}
30+
// Clean up Micro-ROS object
3131
rcl_ret_t ret = rcl_node_fini(&self->rcl_node);
32-
if (ret != RCL_RET_OK || !rcl_node_is_valid(&self->rcl_node)) {
32+
if (ret != RCL_RET_OK) {
3333
ESP_LOGW("RCLCPY", "Node cleanup error: %d", ret);
34+
// rclcpy_default_context.critical_fail=RCLCPY_NODE_FAIL;
3435
}
3536
self->deinited = true;
3637
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "esp_log.h"
1010

11-
1211
void common_hal_rclcpy_publisher_construct(rclcpy_publisher_obj_t *self, rclcpy_node_obj_t *node,
1312
const char *topic_name) {
1413

@@ -35,9 +34,11 @@ void common_hal_rclcpy_publisher_deinit(rclcpy_publisher_obj_t *self) {
3534
if (common_hal_rclcpy_publisher_deinited(self)) {
3635
return;
3736
}
37+
// Clean up Micro-ROS object
3838
rcl_ret_t ret = rcl_publisher_fini(&self->rcl_publisher, &self->node->rcl_node);
39-
if (ret != RCL_RET_OK || !rcl_publisher_is_valid(&self->rcl_publisher)) {
40-
ESP_LOGW("RCLCPY", "Publisher cleanup warning: %d", ret);
39+
if (ret != RCL_RET_OK) {
40+
ESP_LOGW("RCLCPY", "Publisher cleanup error: %d", ret);
41+
// rclcpy_default_context.critical_fail=RCLCPY_PUB_FAIL;
4142
}
4243
self->node = NULL;
4344
}

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88

99
#include "esp_log.h"
1010

11+
#define RCLCPY_SUPPORT_FAIL 1
12+
#define RCLCPY_OPTIONS_FAIL 2
1113

1214
rclcpy_context_t rclcpy_default_context = {
1315
.initialized = false,
16+
.critical_fail = 0,
1417
};
1518

1619
static void *microros_allocate(size_t size, void *state) {
@@ -40,16 +43,16 @@ static void *microros_zero_allocate(size_t number_of_elements, size_t size_of_el
4043

4144
void rclcpy_reset(void) {
4245
if (rclcpy_default_context.initialized) {
43-
// Clean up support context
46+
// Clean up micro-ROS objects
4447
rcl_ret_t ret = rclc_support_fini(&rclcpy_default_context.rcl_support);
4548
if (ret != RCL_RET_OK) {
46-
ESP_LOGW("RCLCPY", "Support cleanup error: %d", ret);
49+
// ESP_LOGW("RCLCPY", "Support cleanup error: %d", ret);
50+
rclcpy_default_context.critical_fail = RCLCPY_SUPPORT_FAIL;
4751
}
48-
49-
// Clean up init options
5052
ret = rcl_init_options_fini(&rclcpy_default_context.init_options);
5153
if (ret != RCL_RET_OK) {
52-
ESP_LOGW("RCLCPY", "Init options cleanup error: %d", ret);
54+
// ESP_LOGW("RCLCPY", "Init options cleanup error: %d", ret);
55+
rclcpy_default_context.critical_fail = RCLCPY_OPTIONS_FAIL;
5356
}
5457

5558
// Reset context state
@@ -59,52 +62,51 @@ void rclcpy_reset(void) {
5962
}
6063

6164
void common_hal_rclcpy_init(const char *agent_ip, const char *agent_port, int16_t domain_id) {
62-
// Get empty allocator
63-
rcl_allocator_t custom_allocator = rcutils_get_zero_initialized_allocator();
65+
if (rclcpy_default_context.critical_fail != 0) {
66+
mp_raise_RuntimeError_varg(MP_ERROR_TEXT("Critical ROS failure during soft reboot, reset required: %d"), rclcpy_default_context.critical_fail);
67+
}
6468

65-
// Set custom allocation methods
69+
// Set up circuitpython-friendly allocator
70+
rcl_allocator_t custom_allocator = rcutils_get_zero_initialized_allocator();
6671
custom_allocator.allocate = microros_allocate;
6772
custom_allocator.deallocate = microros_deallocate;
6873
custom_allocator.reallocate = microros_reallocate;
6974
custom_allocator.zero_allocate = microros_zero_allocate;
70-
// Set custom allocator as default
7175
if (!rcutils_set_default_allocator(&custom_allocator)) {
72-
ESP_LOGW("RCLCPY", "allocator failure");
7376
mp_raise_RuntimeError(MP_ERROR_TEXT("ROS memory allocator failure"));
7477
}
7578
rclcpy_default_context.rcl_allocator = custom_allocator;
7679

7780
rcl_ret_t ret;
7881

79-
// Options Init
82+
// Micro-ROS options initialization
8083
rclcpy_default_context.init_options = rcl_get_zero_initialized_init_options();
8184
ret = rcl_init_options_init(&rclcpy_default_context.init_options, rclcpy_default_context.rcl_allocator);
8285
if (ret != RCL_RET_OK) {
83-
ESP_LOGW("RCLCPY", "Options init failure: %d", ret);
86+
mp_raise_RuntimeError(MP_ERROR_TEXT("ROS internal setup failure"));
8487
}
8588
if (domain_id < 0) {
8689
mp_raise_RuntimeError(MP_ERROR_TEXT("Invalid ROS domain ID"));
8790
}
8891
ret = rcl_init_options_set_domain_id(&rclcpy_default_context.init_options, domain_id);
8992
if (ret != RCL_RET_OK) {
90-
ESP_LOGW("RCLCPY", "Options domain failure: %d", ret);
93+
mp_raise_RuntimeError(MP_ERROR_TEXT("ROS internal setup failure"));
9194
}
9295

93-
// Set up Agent
96+
// Set up Micro-ROS Agent
9497
rclcpy_default_context.rmw_options = rcl_init_options_get_rmw_init_options(&rclcpy_default_context.init_options);
9598
ret = rmw_uros_options_set_udp_address(agent_ip, agent_port, rclcpy_default_context.rmw_options);
9699
if (ret != RCL_RET_OK) {
97-
ESP_LOGW("RCLCPY", "Agent options failure: %d", ret);
100+
mp_raise_RuntimeError(MP_ERROR_TEXT("ROS internal setup failure"));
98101
}
99102

100-
// Support Init
103+
// Final support object init requires a connected agent
101104
ret = rclc_support_init_with_options(&rclcpy_default_context.rcl_support,
102105
0,
103106
NULL,
104107
&rclcpy_default_context.init_options,
105108
&rclcpy_default_context.rcl_allocator);
106109
if (ret != RCL_RET_OK) {
107-
ESP_LOGW("RCLCPY", "Initialization failure: %d", ret);
108110
mp_raise_RuntimeError(MP_ERROR_TEXT("ROS failed to initialize. Is agent connected?"));
109111
} else {
110112
rclcpy_default_context.initialized = true;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
typedef struct {
2121
bool initialized;
22+
uint8_t critical_fail;
2223
rcl_allocator_t rcl_allocator;
2324
rclc_support_t rcl_support;
2425
rcl_init_options_t init_options;

py/circuitpy_defns.mk

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ endif
201201
ifeq ($(CIRCUITPY_DISPLAYIO),1)
202202
SRC_PATTERNS += displayio/%
203203
endif
204+
ifeq ($(CIRCUITPY_DUALBANK),1)
205+
SRC_PATTERNS += dualbank/%
206+
endif
204207
ifeq ($(CIRCUITPY__EVE),1)
205208
SRC_PATTERNS += _eve/%
206209
endif
@@ -279,6 +282,9 @@ endif
279282
ifeq ($(CIRCUITPY_MAX3421E),1)
280283
SRC_PATTERNS += max3421e/%
281284
endif
285+
ifeq ($(CIRCUITPY_MDNS),1)
286+
SRC_PATTERNS += mdns/%
287+
endif
282288
ifeq ($(CIRCUITPY_MEMORYMAP),1)
283289
SRC_PATTERNS += memorymap/%
284290
endif
@@ -288,12 +294,6 @@ endif
288294
ifeq ($(CIRCUITPY_MICROCONTROLLER),1)
289295
SRC_PATTERNS += microcontroller/%
290296
endif
291-
ifeq ($(CIRCUITPY_RCLCPY),1)
292-
SRC_PATTERNS += rclcpy/%
293-
endif
294-
ifeq ($(CIRCUITPY_MDNS),1)
295-
SRC_PATTERNS += mdns/%
296-
endif
297297
ifeq ($(CIRCUITPY_MSGPACK),1)
298298
SRC_PATTERNS += msgpack/%
299299
endif
@@ -309,9 +309,6 @@ endif
309309
ifeq ($(CIRCUITPY_OS),1)
310310
SRC_PATTERNS += os/%
311311
endif
312-
ifeq ($(CIRCUITPY_DUALBANK),1)
313-
SRC_PATTERNS += dualbank/%
314-
endif
315312
ifeq ($(CIRCUITPY_PARALLELDISPLAYBUS),1)
316313
SRC_PATTERNS += paralleldisplaybus/%
317314
endif
@@ -345,6 +342,9 @@ endif
345342
ifeq ($(CIRCUITPY_RANDOM),1)
346343
SRC_PATTERNS += random/%
347344
endif
345+
ifeq ($(CIRCUITPY_RCLCPY),1)
346+
SRC_PATTERNS += rclcpy/%
347+
endif
348348
ifeq ($(CIRCUITPY_RGBMATRIX),1)
349349
SRC_PATTERNS += rgbmatrix/%
350350
endif

0 commit comments

Comments
 (0)
0