micro-ROS / freertos_apps

Sample applications for FreeRTOS + micro-ROS
Apache License 2.0
81 stars 50 forks source link

[BUG] Serial transport not be established if first plug the board, then start agent. #92

Closed ZhenshengLee closed 2 years ago

ZhenshengLee commented 2 years ago

Issue template

Steps to reproduce the issue

  1. compile the app int32_publisher and flash it to mcu
  2. compile the agent
  3. plug the board with USB
  4. start agent using ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/serial/by-id/usb-STMicroelectronics_STM32_STLink_0670FF555071494867152654-if02
  5. ros2 topic echo /freertos_int32_publisher

Expected behavior

Any time you plug the board, agent would established the link.

Actual behavior

agent output

ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/serial/by-id/usb-STMicroelectronics_STM32_STLink_0670FF555071494867152654-if02 
[1646308710.731945] info     | TermiosAgentLinux.cpp | init                     | running...             | fd: 3
[1646308710.732117] info     | Root.cpp           | set_verbose_level        | logger setup           | verbose_level: 4

Additional information

If you first run agent, then plug the board, the link will be established, and the demo would work

I think it may be related with #72 , and may be a problem with the initialization of the serial link.

I am not familar with embedded development so any help would be appreciated.

Thanks.

pablogs9 commented 2 years ago

This is not a bug, the client will try to connect to the agent at the begging of the app for a certain amount of times with a certain timeout.

If this attempt fails, in this example, the app will fail. You can check the return value of this function and retry until the agent is reached. You can ping the agent in order to wait until it is available. But in general, you should handle the client-agent connection.

In your use case, if you open the agent and later the client, the client might lose all the opportunities to connect. If you open the agent and then the client, it will succeed.

ZhenshengLee commented 2 years ago

Thanks a lot!

I will check more info from xrce-agent and xrce-client doc.