micro-ROS / rmw_microxrcedds

RMW implementation using Micro XRCE-DDS middleware.
Apache License 2.0
30 stars 23 forks source link

rmw_uros_ping_agent always adds 100 ms delay #306

Closed mvanlobensels closed 2 months ago

mvanlobensels commented 3 months ago

Describe the bug The rmw_uros_ping_agent function adds 100 ms of delay to the function's timeout_ms input argument when the Micro-ROS Agent is not found or not connected.

For example, when measuring the time it takes to evaluate rmw_uros_ping_agent(10, 1), the result is 110 ms. Similarly, rmw_uros_ping_agent(100, 1) takes 200 ms. rmw_uros_ping_agent(10, 2) results in 210 ms.

To Reproduce I am using the micro-ros_reconnection_example to reconnect to the Agent in the case that a connection is lost, or when my microcontroller boots before the PC which runs the Micro-ROS Agent boots.

switch(agent_state)
{
    case WAITING_AGENT:
        time_start = uxr_millis();        
        agent_state = (RMW_RET_OK == rmw_uros_ping_agent(10, 1)) ? AGENT_AVAILABLE : WAITING_AGENT;
        time_end = uxr_millis() - time_start;
        break;
    case AGENT_AVAILABLE:
        ...
}

Expected behaviour I expect the delay to be equal to timeout_ms. We are controlling electric motors with the microcontroller, so adding a 100 ms delay to our system makes our robot uncontrollable.

System information:

pablogs9 commented 3 months ago

Sorry but as far as we do not support Pop OS 22.04 for Renesas RA6M5 I'm not sure about the behaviour of your system. Could you confirm that it behaves the same with a supported configuration?

mvanlobensels commented 3 months ago

Pop OS is the practically the same as Ubuntu, with drivers pre-installed and customized GNOME features. I find it hard to believe that that could be the issue. https://support.system76.com/articles/difference-between-pop-ubuntu/

So this additional 100 ms is not something that is implemented by design?

pablogs9 commented 3 months ago

I thought that Pop OS was some sort of RTOS running in the RA6M5, sorry for the confusion.

Which transport are you using to communicate the micro-ROS Client with the micro-ROS Agent?

mvanlobensels commented 3 months ago

I am using Serial USB to communicate between the Agent and the microcontroller based on this example.

pablogs9 commented 3 months ago

Could you check if changing the timeout here: https://github.com/micro-ROS/micro_ros_renesas2estudio_component/blob/a99ccd815ebe6de4b53b02189cedd36bb1847c7d/extra_sources/microros_transports/usb_transport.c#L136 solves the issue?

Not sure right now if you can set it to

return handle_usb(USB_WRITE, (uint8_t *) buf, len, 0);

but maybe something less than WRITE_TIMEOUT (that is 100 ms).

mvanlobensels commented 2 months ago

Thank you. This was indeed the cause of the 100 ms delay.