micro-ROS / micro-ROS/micro_ros_arduino

microros reconect whitout a blocking delay FROM destroy_entities()

Open
#1,396 0 comments 0 reactions 1 assignee View on GitHub

@Acuadros95 is already working on this.

Since May 29, 2023.

Dominant language
C
Stars
576
Forks
146
PR merge metrics
No merged PRs in 30d

Description

#### 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](https://github.com/micro-ROS/micro_ros_arduino/blob/foxy/examples/micro-ros_reconnection_example/micro-ros_reconnection_example.ino) 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](https://micro.ros.org/docs/api/rmw/#function-rmw_uros_ping_agent)
```c
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](https://github.com/micro-ROS/micro_ros_arduino/issues/506), only there the problem is solved and I am using the latest version of microros.

#### main piece of code from the example
```c
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;
}
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.