8
8
9
9
#include "esp_log.h"
10
10
11
- #define RCLCPY_DOMAIN_ID 3
12
- #define RCLCPY_AGENT_IP "192.168.10.111"
13
- #define RCLCPY_AGENT_PORT "8888"
14
-
15
11
rclcpy_context_t rclcpy_default_context = {
16
12
.initialized = false,
17
13
};
@@ -41,7 +37,10 @@ static void* microros_zero_allocate(size_t number_of_elements, size_t size_of_el
41
37
return ptr ;
42
38
}
43
39
44
- void common_hal_rclcpy_init (void ) {
40
+ void rclcpy_reset (void ) {
41
+ }
42
+
43
+ void common_hal_rclcpy_init (const char * agent_ip , const char * agent_port , int16_t domain_id ) {
45
44
// Get empty allocator
46
45
rcl_allocator_t custom_allocator = rcutils_get_zero_initialized_allocator ();
47
46
@@ -65,29 +64,30 @@ void common_hal_rclcpy_init(void) {
65
64
if (ret != RCL_RET_OK ) {
66
65
ESP_LOGW ("RCLCPY" , "Options init failure: %d" , ret );
67
66
}
68
- ret = rcl_init_options_set_domain_id (& rclcpy_default_context .init_options , RCLCPY_DOMAIN_ID );
67
+ if (domain_id < 0 ) {
68
+ mp_raise_RuntimeError (MP_ERROR_TEXT ("Invalid ROS domain ID" ));
69
+ }
70
+ ret = rcl_init_options_set_domain_id (& rclcpy_default_context .init_options , domain_id );
69
71
if (ret != RCL_RET_OK ) {
70
72
ESP_LOGW ("RCLCPY" , "Options domain failure: %d" , ret );
71
73
}
72
74
73
75
// Set up Agent
74
76
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 );
77
+ ret = rmw_uros_options_set_udp_address (agent_ip , agent_port , rclcpy_default_context .rmw_options );
76
78
if (ret != RCL_RET_OK ) {
77
79
ESP_LOGW ("RCLCPY" , "Agent options failure: %d" , ret );
78
80
}
79
- //RCCHECK(rmw_uros_discover_agent(rmw_options));
80
81
81
82
// Support Init
82
- // ret = rclc_support_init(&rclcpy_default_context.rcl_support, 0, NULL, &rclcpy_default_context.rcl_allocator);
83
83
ret = rclc_support_init_with_options (& rclcpy_default_context .rcl_support ,
84
84
0 ,
85
85
NULL ,
86
86
& rclcpy_default_context .init_options ,
87
87
& rclcpy_default_context .rcl_allocator );
88
88
if (ret != RCL_RET_OK ) {
89
89
ESP_LOGW ("RCLCPY" , "Initialization failure: %d" , ret );
90
- mp_raise_RuntimeError (MP_ERROR_TEXT ("ROS failed to initialize" ));
90
+ mp_raise_RuntimeError (MP_ERROR_TEXT ("ROS failed to initialize. Is agent connected? " ));
91
91
} else {
92
92
rclcpy_default_context .initialized = true;
93
93
}
0 commit comments