micro-ROS / micro_ros_platformio

micro-ROS library for Platform.IO
Apache License 2.0
205 stars 77 forks source link

Serial1 communication and GPIO pins on Raspberry Pi 4B and RPi Pico #109

Closed pkowalsk1 closed 1 year ago

pkowalsk1 commented 1 year ago

Steps to reproduce the issue

I have a Raspberry Pi 4B and an RPi Pico, and I want to utilize Serial1 (GPIO 0 and 1) for serial communication. When using USB communication and Serial, everything works fine. However, when attempting to use Serial1 and GPIO pins, I encounter the following problem:

include <rcl/rcl.h>

include <rclc/executor.h>

include <rclc/rclc.h>

...

void setup() { pinMode(LED_BUILTIN, OUTPUT);

Serial1.begin(576000); while (!Serial1) ;

set_microros_serial_transports(Serial1); delay(2000);

// Rest of uRos entities (pubs, subs) ...

digitalWrite(LED_BUILTIN, HIGH); delay(100); }

void loop() { RCSOFTCHECK(rclc_executor_spin_some(&executor, RCL_MS_TO_NS(10))); }

- platformio.ini:
```ini
[env:pico]
platform = raspberrypi
board = pico
framework = arduino
upload_port = /media/pk/RPI-RP2
upload_protocol = picotool
monitor_speed = 115200

board_microros_distro = humble
board_microros_transport = serial

lib_ldf_mode = chain+
lib_deps =
    https://github.com/micro-ROS/micro_ros_platformio
    https://github.com/adafruit/Adafruit_Sensor#1.1.7
    https://github.com/adafruit/Adafruit_BNO055#1.6.1

Actual behavior

set_microros_serial_transports or rmw_uros_set_custom_transport functions fail and my error_loop starts executing.

Logs from microros-agent container:

microros  | [1689791613.039798] info     | TermiosAgentLinux.cpp | init                     | running...             | fd: 3
microros  | [1689791613.040897] info     | Root.cpp           | set_verbose_level        | logger setup           | verbose_level: 6
microros  | [1689791619.452667] info     | Root.cpp           | create_client            | create                 | client_key: 0x0DA77874, session_id: 0x81
microros  | [1689791619.457659] info     | SessionManager.hpp | establish_session        | session established    | client_key: 0x0DA77874, address: 0
microros  | [1689791619.457937] debug    | SerialAgentLinux.cpp | send_message             | [** <<SER>> ]        | client_key: 0x0DA77874, len: 19, data:
microros  | 0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
microros  | [1689791620.452336] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x0DA77874, len: 24, data:
microros  | 0000: 80 00 00 00 00 01 10 00 58 52 43 45 01 00 01 0F 0D A7 78 74 81 00 FC 01
microros  | [1689791620.452540] info     | SessionManager.hpp | establish_session        | session re-established | client_key: 0x0DA77874, address: 0
microros  | [1689791620.452769] debug    | SerialAgentLinux.cpp | send_message             | [ <<SER>> ]        | client_key: 0x0DA77874, len: 19, data:
microros  | 0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
microros  | [1689791621.452286] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x0DA77874, len: 24, data:
microros  | 0000: 80 00 00 00 00 01 10 00 58 52 43 45 01 00 01 0F 0D A7 78 74 81 00 FC 01
microros  | [1689791621.452449] info     | SessionManager.hpp | establish_session        | session re-established | client_key: 0x0DA77874, address: 0
microros  | [1689791621.452560] debug    | SerialAgentLinux.cpp | send_message             | [ <<SER>> ]        | client_key: 0x0DA77874, len: 19, data:
microros  | 0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
microros  | [1689791622.452273] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x0DA77874, len: 24, data:
microros  | 0000: 80 00 00 00 00 01 10 00 58 52 43 45 01 00 01 0F 0D A7 78 74 81 00 FC 01
microros  | [1689791622.452433] info     | SessionManager.hpp | establish_session        | session re-established | client_key: 0x0DA77874, address: 0
microros  | [1689791622.452526] debug    | SerialAgentLinux.cpp | send_message             | [ <<SER>> ]        | client_key: 0x0DA77874, len: 19, data:
microros  | 0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
microros  | [1689791623.452256] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x0DA77874, len: 24, data:
microros  | 0000: 80 00 00 00 00 01 10 00 58 52 43 45 01 00 01 0F 0D A7 78 74 81 00 FC 01
microros  | [1689791623.452415] info     | SessionManager.hpp | establish_session        | session re-established | client_key: 0x0DA77874, address: 0
microros  | [1689791623.452517] debug    | SerialAgentLinux.cpp | send_message             | [ <<SER>> ]        | client_key: 0x0DA77874, len: 19, data:
microros  | 0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
microros  | [1689791624.452249] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x0DA77874, len: 24, data:
microros  | 0000: 80 00 00 00 00 01 10 00 58 52 43 45 01 00 01 0F 0D A7 78 74 81 00 FC 01
microros  | [1689791624.452379] info     | SessionManager.hpp | establish_session        | session re-established | client_key: 0x0DA77874, address: 0
microros  | [1689791624.452571] debug    | SerialAgentLinux.cpp | send_message             | [ <<SER>> ]        | client_key: 0x0DA77874, len: 19, data:
microros  | 0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
microros  | [1689791625.452239] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x0DA77874, len: 24, data:
microros  | 0000: 80 00 00 00 00 01 10 00 58 52 43 45 01 00 01 0F 0D A7 78 74 81 00 FC 01
microros  | [1689791625.452362] info     | SessionManager.hpp | establish_session        | session re-established | client_key: 0x0DA77874, address: 0
microros  | [1689791625.452493] debug    | SerialAgentLinux.cpp | send_message             | [ <<SER>> ]        | client_key: 0x0DA77874, len: 19, data:
microros  | 0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
microros  | [1689791626.452218] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x0DA77874, len: 24, data:
microros  | 0000: 80 00 00 00 00 01 10 00 58 52 43 45 01 00 01 0F 0D A7 78 74 81 00 FC 01
microros  | [1689791626.452340] info     | SessionManager.hpp | establish_session        | session re-established | client_key: 0x0DA77874, address: 0
microros  | [1689791626.452485] debug    | SerialAgentLinux.cpp | send_message             | [ <<SER>> ]        | client_key: 0x0DA77874, len: 19, data:
microros  | 0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
microros  | [1689791627.452217] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x0DA77874, len: 24, data:
microros  | 0000: 80 00 00 00 00 01 10 00 58 52 43 45 01 00 01 0F 0D A7 78 74 81 00 FC 01
microros  | [1689791627.452341] info     | SessionManager.hpp | establish_session        | session re-established | client_key: 0x0DA77874, address: 0
microros  | [1689791627.452463] debug    | SerialAgentLinux.cpp | send_message             | [ <<SER>> ]        | client_key: 0x0DA77874, len: 19, data:
microros  | 0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
microros  | [1689791628.452209] debug    | SerialAgentLinux.cpp | recv_message             | [==>> SER <<==]        | client_key: 0x0DA77874, len: 24, data:
microros  | 0000: 80 00 00 00 00 01 10 00 58 52 43 45 01 00 01 0F 0D A7 78 74 81 00 FC 01
microros  | [1689791628.452337] info     | SessionManager.hpp | establish_session        | session re-established | client_key: 0x0DA77874, address: 0
microros  | [1689791628.452478] debug    | SerialAgentLinux.cpp | send_message             | [ <<SER>> **]        | client_key: 0x0DA77874, len: 19, data:
microros  | 0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00

Additional information

I have also tried using other pins such as 12, 13, 17, and 15 for Serial1, but the problem persists. (arduino::UART MySerial(12, 13, NC, NC); or gpio_set_function(xx, GPIO_FUNC_UART);)

The issue with Serial1 is further manifested by the fact that I cannot use Serial1.println("hello") without including a delay(1) function in between.

You can find my attempts here, especially regarding the transport configuration.

pkowalsk1 commented 1 year ago

I addressed this issue within the context of the provided pull request. It appears that a pivotal step was the removal of the board_microros_transport = serial line from the platformio.ini file.

I successfully leveraged GP12 and GP13 as the RX and TX pins, achieving this by employing the gpio_set_function() prior to invoking the begin() method of my UART class object.