micro-ROS / micro-ROS-Agent

ROS 2 package using Micro XRCE-DDS Agent.
Apache License 2.0
97 stars 51 forks source link

micro-ROS-Agent Serial Only Works for 115200 BAUD #215

Closed Jake-Carter closed 5 months ago

Jake-Carter commented 5 months ago

Describe the bug

The micro-ROS agent only seems to work with a serial connection at 115200 baud. Attempting to connect at any other baudrate results in no connection.

ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyACM0 --baud 230400

Even at -v6 there are no error messages, and I can see serial activity coming into the right port as my device attempts to connect. It has the symptoms of a baudrate mismatch.

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

To Reproduce Steps to reproduce the behaviour:

  1. Attempt to connect to the agent over a serial port at any BAUD rate except 115200

System information (please complete the following information):

Additional context

I'm currently working on a custom platform, and don't have any other hardware to test. I've ordered an ST Nucleo board to have another reference, but if anyone can run a test on a known working platform I would greatly appreciate it.

pablogs9 commented 5 months ago

Is possible to open your serial device with other baudrate for other purposes?

I mean, if you open a miniterm/minicom with a different baudrate, do you receive data from the micro-ROS Client?

Jake-Carter commented 5 months ago

Here is the miniterm output at 115200 baud:

~ » python -m serial.tools.miniterm /dev/ttyACM0 115200                                               jhcarter@jhcarter-X670E
--- Miniterm on /dev/ttyACM0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

-=- MAX78000 micro-ROS + FreeRTOS (V10.5.1) Demo -=-
SystemCoreClock = 60000000
Initializing RTC
Assigning custom transports
Starting scheduler in 1s...
~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏t�,-�␀�␇S,~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏t�,-�␀�␇S,~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏t�,-�␀�␇S,~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏t�,-�␀�␇S,~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏t�,-�␀�␇S,~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏t�,-�␀�␇S,~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏t�,-�␀�␇S,
--- exit ---

and at 230400 baud

~ » python -m serial.tools.miniterm /dev/ttyACM0 230400                                               jhcarter@jhcarter-X670E
--- Miniterm on /dev/ttyACM0  230400,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

-=- MAX78000 micro-ROS + FreeRTOS (V10.5.1) Demo -=-
SystemCoreClock = 60000000
Initializing RTC
Assigning custom transports
Starting scheduler in 1s...
�>V�␀�␇0�~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏
--- exit ---

So it seems my printf statements are working normally at the different baud rates, but not my custom serial transport functions. I will check my implementation. Closing as this is most likely an issue on my side.

Jake-Carter commented 5 months ago

Hi @pablogs9, re-opening as I fixed the issues with my serial transports but the issues still persists.

I set the client key in my application code so that it would not randomly generate one each time. At 57600, 115200, and 230400 I logged the miniterm output to a file, and a diff shows they are all identical.

~/repos/msdk/Examples/MAX78000/micro-ROS/object_detector (dev/micro-ros*) » python -m serial.tools.miniterm /dev/ttyUSB0 230400 | tee log_230400
--- Miniterm on /dev/ttyUSB0  230400,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

-=- MAX78000 micro-ROS + FreeRTOS (V10.5.1) Demo -=-
SystemCoreClock = 60000000
Initializing RTC
Testing all ASCII characters...
---
␀␁␂␃␄␅␆␇
␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~␡��������������������������������������������������������������������������������������������������������������������������������
---
Assigning custom transports
Starting scheduler in 1s...
~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏�^�␑�␀�␇␐  ~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏�^�␑�␀�␇␐  ~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏�^�␑�␀�␇␐  ~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏�^�␑�␀�␇␐~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏�^�␑�␀�␇␐   ~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏�^�␑�␀�␇␐  ~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏�^�␑�␀�␇␐  ~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏�^�␑�␀�␇␐~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏�^�␑�␀�␇␐   ~␀␀␘␀�␀␀␀␀␁␐␀XRCE␁␀␁␏�^�␑�␀�␇␐
--- exit ---

log_57600.txt log_115200.txt log_230400.txt

However, the agent only establishes the session at 115200... The others hang with no error messages.

~/repos/msdk/Examples/MAX78000/micro-ROS/object_detector (dev/micro-ros*) » ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyUSB0 --baud 115200
[1705710566.747570] info     | TermiosAgentLinux.cpp | init                     | running...             | fd: 3
[1705710566.747742] info     | Root.cpp           | set_verbose_level        | logger setup           | verbose_level: 4
[1705710583.128053] info     | Root.cpp           | create_client            | create                 | client_key: 0xBA5EBA11, session_id: 0x81
[1705710583.128103] info     | SessionManager.hpp | establish_session        | session established    | client_key: 0xBA5EBA11, address: 0

Do you have a platform to test at a non-default baud rate?

pablogs9 commented 5 months ago

Are you sharing the same UART for XRCE and printf? That would likely fail

Jake-Carter commented 5 months ago

I am, but only call printf as logging info before running the appMain task.

I removed all printfs and reassigned the stdio drivers to use a separate UART, but still have the same results

pablogs9 commented 5 months ago

Try using -b or --baudrate:

image

https://micro-xrce-dds.docs.eprosima.com/en/latest/agent.html?highlight=baud

Jake-Carter commented 5 months ago

Jeez, yep. Dumb mistake... I was using --baud instead of --baudrate... thanks.