micro-ROS/micro-ROS-demos

Cannot fully start micro-ros-agent without first disconnecting MCU

Closed this issue · 3 comments

Hi there! I was wondering if I always have to first disconnnect my micro-controller from the host PC before running the micro-ros-agent and then reconnecting the micro-controller to complete a successful 'handshake' between the agent and the micro-controller.

Setup

Steps to reproduce the issue

First scenario: Micro-controller is disconnect from host PC and I run:

ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyUSB0 -v6

This produces:

[1697184634.436365] info     | TermiosAgentLinux.cpp | init                     | Serial port not found. | device: /dev/ttyUSB0, error 2, waiting for connection...
[1697184635.442714] info     | TermiosAgentLinux.cpp | init                     | Serial port not found. | device: /dev/ttyUSB0, error 2, waiting for connection...

The micro is then plugged into the host PC via USB, resulting in the agent being set up completely. It creates the client, session, participants, topics, datawriters, publishers...

[1697184669.369164] info     | TermiosAgentLinux.cpp | init                     | running...             | fd: 3
[1697184669.369615] info     | Root.cpp           | set_verbose_level        | logger setup           | verbose_level: 6
[1697184669.526507] info     | Root.cpp           | create_client            | create                 | client_key: 0x31656C75, session_id: 0x81
[1697184669.526586] info     | SessionManager.hpp | establish_session        | session established    | client_key: 0x31656C75, address: 0
[1697184669.526776] debug    | SerialAgentLinux.cpp | send_message             | [** <<SER>> **]        | client_key: 0x31656C75, len: 19, data:
0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
[1697184669.539784] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x31656C75, len: 52, data:
0000: 81 80 00 00 01 07 2A 00 00 0A 00 01 01 03 00 00 1B 00 00 00 00 01 FB 3F 13 00 00 00 48 69 77 6F
0020: 6E 64 65 72 5F 78 41 72 6D 5F 6E 6F 64 65 00 00 00 00 00 00
[1697184669.558660] info     | ProxyClient.cpp    | create_participant       | participant created    | client_key: 0x31656C75, participant_id: 0x000(1)
[1697184669.558837] debug    | SerialAgentLinux.cpp | send_message             | [** <<SER>> **]        | client_key: 0x31656C75, len: 14, data:
0000: 81 80 00 00 05 01 06 00 00 0A 00 01 00 00
[1697184669.558873] debug    | SerialAgentLinux.cpp | send_message             | [** <<SER>> **]        | client_key: 0x31656C75, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 01 00 00 00 80
[1697184669.569700] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x31656C75, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 01 00 00 00 80
[1697184669.576870] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x31656C75, len: 96, data:
0000: 81 80 01 00 01 07 56 00 00 0B 00 02 02 03 00 00 48 00 00 00 17 00 00 00 72 74 2F 73 65 72 76 6F
0020: 5F 70 6F 73 5F 70 75 62 6C 69 73 68 65 72 00 00 01 BB 40 3F 24 00 00 00 73 65 6E 73 6F 72 5F 6D
0040: 73 67 73 3A 3A 6D 73 67 3A 3A 64 64 73 5F 3A 3A 4A 6F 69 6E 74 53 74 61 74 65 5F 00 00 01 00 00
[1697184669.577798] info     | ProxyClient.cpp    | create_topic             | topic created          | client_key: 0x31656C75, topic_id: 0x000(2), participant_id: 0x000(1)
[1697184669.578148] debug    | SerialAgentLinux.cpp | send_message             | [** <<SER>> **]        | client_key: 0x31656C75, len: 14, data:
0000: 81 80 01 00 05 01 06 00 00 0B 00 02 00 00
[1697184669.578243] debug    | SerialAgentLinux.cpp | send_message             | [** <<SER>> **]        | client_key: 0x31656C75, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 02 00 00 00 80
[1697184669.590752] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x31656C75, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 02 00 00 00 80
[1697184669.590832] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x31656C75, len: 24, data:
0000: 81 80 02 00 01 07 10 00 00 0C 00 03 03 03 00 00 02 00 00 00 00 00 00 01
[1697184669.591047] info     | ProxyClient.cpp    | create_publisher         | publisher created      | client_key: 0x31656C75, publisher_id: 0x000(3), participant_id: 0x000(1)
[1697184669.591225] debug    | SerialAgentLinux.cpp | send_message             | [** <<SER>> **]        | client_key: 0x31656C75, len: 14, data:
0000: 81 80 02 00 05 01 06 00 00 0C 00 03 00 00
[1697184669.591250] debug    | SerialAgentLinux.cpp | send_message             | [** <<SER>> **]        | client_key: 0x31656C75, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 03 00 00 00 80
[1697184669.603837] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x31656C75, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 03 00 00 00 80
[1697184669.603892] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x31656C75, len: 36, data:
0000: 81 80 03 00 01 07 1C 00 00 0D 00 05 05 03 00 00 0E 00 00 00 00 02 01 3F 03 00 01 00 0A 00 00 00
0020: 00 00 00 03

The program works fine like this.

Second scenario: The micro-controller is already connected to the host PC and I run:

ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyUSB0 -v6

This only results in:

[1697184677.461765] info     | TermiosAgentLinux.cpp | init                     | running...             | fd: 3
[1697184677.462048] info     | Root.cpp           | set_verbose_level        | logger setup           | verbose_level: 6

and the setup is not complete.

Is there some way to get around this so that I do not have to disconnect my micro every time I want to start my micro-ros-agent?

Any help is greatly appreciated, thank you.

Thank you very much for the feedback!

micro-ROS does not handle reconnections to the agent. You need to implement it in your application.

Please read these documents:

Following these got it working very nicely, thank you!