micro_ros_arduino icon indicating copy to clipboard operation
micro_ros_arduino copied to clipboard

microros reconect whitout a blocking delay FROM destroy_entities()

Open Publicano opened this issue 2 years ago • 0 comments

Hardware en software

  • Teensy 4.1
  • v2.0.5-humble Microros in docker

Problem description

i am trying to create a connection between the teensy and the microros agent without adding a blocking delay in my code. For this, I used the micro-ros_reconnection_example code. This one only has a delay due to the rmw_uros_ping_agent() function.

Expected behavior

i would expect the rmw_uros_ping_agent function to cause the set delay as explained here

rmw_ret_t rmw_uros_ping_agent(
    **const int timeout_ms**,
    const uint8_t attempts
)

Actual behavior

when the ping_agent function is called for the first time after startup in the WAITING_AGENT there is a blocking delay of about 3 sec. the second time it is the set delay.

Additional information

It is very similar to #506, only there the problem is solved and I am using the latest version of microros.

main piece of code from the example

switch (state) {
    case WAITING_AGENT:
      EXECUTE_EVERY_N_MS(500, state = (RMW_RET_OK == rmw_uros_ping_agent(100, 1)) ? AGENT_AVAILABLE : WAITING_AGENT;);
      break;
    case AGENT_AVAILABLE:
      state = (true == create_entities()) ? AGENT_CONNECTED : WAITING_AGENT;
      if (state == WAITING_AGENT) {
        destroy_entities();
      };
      break;
    case AGENT_CONNECTED:
      EXECUTE_EVERY_N_MS(200, state = (RMW_RET_OK == rmw_uros_ping_agent(10, 1)) ? AGENT_CONNECTED : AGENT_DISCONNECTED;);
      if (state == AGENT_CONNECTED) {
        rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100));
      }
      break;
    case AGENT_DISCONNECTED:
      destroy_entities();
      state = WAITING_AGENT;
      break;
    default:
      break;
  }

Publicano avatar May 26 '23 07:05 Publicano