You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using rclc_support_init_with_options instead of rcl_init_options_init, the Micro-ROS client can successfully connect to the agent on the first and second attempt, but fails to connect on subsequent attempts.
#include<Arduino.h>#include<micro_ros_platformio.h>#include<rcl/rcl.h>#include<rclc/rclc.h>#include<rclc/executor.h>#include<micro_ros_utilities/string_utilities.h>#include<rmw_microros/rmw_microros.h>#include<std_msgs/msg/bool.h>#include<std_msgs/msg/u_int64.h>#include<sensor_msgs/msg/range.h>#include<Ultrasonic.h>#include<Wire.h>#include<ACROBOTIC_SSD1306.h>#include<Int64String.h>#if !defined(MICRO_ROS_TRANSPORT_ARDUINO_SERIAL)
#error This example is only avaliable for Arduino framework with serial transport.
#endif#defineROS_DOMAIN_ID 57
...
rclc_executor_texecutor;
rclc_support_tsupport;
rcl_allocator_tallocator;
rcl_node_tnode;
rcl_timer_ttimer;
rcl_init_options_tinit_options;
#defineRCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}}
#defineRCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}
...
// Timeout for each ping attemptconstinttimeout_ms=100;
// Number of ping attemptsconstuint8_tattempts=1;
// Spin periodconstunsigned intspin_timeout=RCL_MS_TO_NS(100);
// Enum with connection statusenumstates {
WAITING_AGENT,
AGENT_AVAILABLE,
AGENT_CONNECTED,
AGENT_DISCONNECTED
} state;
// Error handle loopvoiderror_loop() {
while(1) {
delay(100);
}
}
boolcreate_entities(void) {
size_tdomain_id= (size_t)(ROS_DOMAIN_ID);
// Initialize micro-ROS allocatorallocator=rcl_get_default_allocator();
// Initialize and modify options init_options=rcl_get_zero_initialized_init_options();
RCCHECK(rcl_init_options_init(&init_options, allocator));
RCCHECK(rcl_init_options_set_domain_id(&init_options, domain_id));
// Initialize rclc support object with custom optionsRCCHECK(rclc_support_init_with_options(&support, 0, NULL, &init_options, &allocator));
// create nodeRCCHECK(rclc_node_init_default(&node, "micro_ros_raspico_node", "", &support));
////////////////////////////////////////////////////////////////////////////////////////////////////////////// allocator = rcl_get_default_allocator();// // create init_options// RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));// // create node// RCCHECK(rclc_node_init_default(&node, "micro_ros_raspico_node", "", &support));////////////////////////////////////////////////////////////////////////////////////////////////////////////// create publisher
...
// create timer,constunsigned inttimer_timeout=20;
RCCHECK(rclc_timer_init_default(
&timer,
&support,
RCL_MS_TO_NS(timer_timeout),
timer_callback));
// create executorexecutor=rclc_executor_get_zero_initialized_executor();
RCCHECK(rclc_executor_init(&executor, &support.context, 5, &allocator));
RCCHECK(rclc_executor_add_timer(&executor, &timer));
// Add a subscriber to the executor
...
return true;
}
voiddestroy_entities(void){
rmw_context_t*rmw_context=rcl_context_get_rmw_context(&support.context);
(void) rmw_uros_set_context_entity_destroy_session_timeout(rmw_context, 0);
RCCHECK(rcl_publisher_fini
...
RCCHECK(rcl_timer_fini(&timer));
RCCHECK(rclc_executor_fini(&executor));
RCCHECK(rcl_node_fini(&node));
RCCHECK(rclc_support_fini(&support));
}
voidsetup() {
Wire.begin();
...
// Configure serial transportSerial.begin(921600);
set_microros_serial_transports(Serial);
delay(2000);
}
voidloop() {
switch (state)
{
caseWAITING_AGENT:
// Check for agent connectionstate= (RMW_RET_OK==rmw_uros_ping_agent(timeout_ms, attempts)) ? AGENT_AVAILABLE : WAITING_AGENT;
break;
caseAGENT_AVAILABLE:
// Create micro-ROS entitiesstate= (true ==create_entities()) ? AGENT_CONNECTED : WAITING_AGENT;
if (state==WAITING_AGENT)
{
// Creation failed, release allocated resourcesdestroy_entities();
};
break;
caseAGENT_CONNECTED:
// Check connection and spin on successstate= (RMW_RET_OK==rmw_uros_ping_agent(timeout_ms, attempts)) ? AGENT_CONNECTED : AGENT_DISCONNECTED;
if (state==AGENT_CONNECTED)
{
RCSOFTCHECK(rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100))); }
break;
caseAGENT_DISCONNECTED:
// Connection is lost, destroy entities and go back to first stepdestroy_entities();
state=WAITING_AGENT;
break;
default:
break;
}
}
The text was updated successfully, but these errors were encountered:
Issue template
When using rclc_support_init_with_options instead of rcl_init_options_init, the Micro-ROS client can successfully connect to the agent on the first and second attempt, but fails to connect on subsequent attempts.
The text was updated successfully, but these errors were encountered: