Connecting ArduPilot and ROS on Raspberry PI 4

I’m trying to connect Ardupilot with ROS through serial. First, I launch roscore with roscore. then I launch MAVROS with roslaunch mavros apm.launch fcu_url:=/dev/ttyAMA0:921600. The connection seems to be fine initially, but then I get

[ INFO] [1669287030.625656361]: MAVROS started. MY ID 1.240, TARGET ID 1.1
[ERROR] [1669287030.625774009]: serial0: receive: End of file
terminate called after throwing an instance of 'std::system_error'
  what():  Resource deadlock avoided
================================================================================REQUIRED process [mavros-1] has died!
process has died [pid 6178, exit code -6, cmd /opt/ros/noetic/lib/mavros/mavros_node __name:=mavros __log:=/home/pi/.ros/log/1a44db34-6bd7-11ed-8ce7-e55fa1a5e52e/mavros-1.log].
log file: /home/pi/.ros/log/1a44db34-6bd7-11ed-8ce7-e55fa1a5e52e/mavros-1*.log
Initiating shutdown!

Log file →

When I try to connect through USB I use roslaunch mavros apm.launch and everything goes fine

[ INFO] [1669290437.586314251]: MAVROS started. MY ID 1.240, TARGET ID 1.1
[ INFO] [1669290437.586932005]: CON: Got HEARTBEAT, connected. FCU: ArduPilot
[ WARN] [1669290437.593711566]: MODE: Unknown APM based FCU! Type: 0
[ WARN] [1669290438.600592828]: CMD: Unexpected command 520, result 0
[ INFO] [1669290438.600882789]: GF: Using MISSION_ITEM_INT
[ INFO] [1669290438.601048454]: RP: Using MISSION_ITEM_INT
[ INFO] [1669290438.601302230]: WP: Using MISSION_ITEM_INT
[ INFO] [1669290438.601475099]: VER: 1.1: Capabilities         0x000000000000fbef
[ INFO] [1669290438.601608857]: VER: 1.1: Flight software:     040103ff (2fb939a1)
[ INFO] [1669290438.601724208]: VER: 1.1: Middleware software: 00000000 (        )
[ INFO] [1669290438.601871781]: VER: 1.1: OS software:         00000000 (45395b6a)
[ INFO] [1669290438.601982318]: VER: 1.1: Board hardware:      00000000
[ INFO] [1669290438.602087872]: VER: 1.1: VID/PID:             0000:0000
[ INFO] [1669290438.602226816]: VER: 1.1: UID:                 0000000000000000
[ INFO] [1669290447.589802403]: HP: requesting home position
[ INFO] [1669290447.592889454]: FCU: ArduCopter V4.1.3 (2fb939a1)
[ INFO] [1669290447.593647338]: FCU: ChibiOS: 45395b6a
[ INFO] [1669290447.594194889]: FCU: Pixhawk4 002F0039 42565006 20323441
[ INFO] [1669290447.594435869]: FCU: RCOut: PWM:1-16
[ INFO] [1669290447.594765089]: FCU: IMU0: fast sampling enabled 8.0kHz/2.0kHz
[ INFO] [1669290447.595094105]: FCU: Frame: UNSUPPORTED
[ INFO] [1669290452.335433157]: PR: parameters list received
[ INFO] [1669290452.592369640]: GF: mission received
[ INFO] [1669290452.592924543]: RP: mission received
[ INFO] [1669290452.594307348]: WP: mission received
[ERROR] [1669290457.021080918]: FCU: PreArm: Check firmware or FRAME_CLASS
[ERROR] [1669290457.021879987]: FCU: PreArm: Throttle below Failsafe
[ERROR] [1669290457.022070337]: FCU: PreArm: Hardware safety switch
[ERROR] [1669290457.022306743]: FCU: PreArm: 3D Accel calibration needed
[ERROR] [1669290457.023591881]: FCU: PreArm: VisOdom: not healthy

Thank you

If you have not disabled Bluetooth, your port is not a UART type an cannot operate at this speed
Reduce speed to 57600 and it should work

I tried with roslaunch mavros apm.launch fcu_url:=/dev/ttyAMA0:57600 but it didn’t work. Same error

Seems there is issue with device access, maybe the console is still active on the RPI4
You may look at some modification I made here:

In any case, you can use minicom to debug the issue

The only difference between your config.txt and mine is enable_uart=1. If I add that line the Raspberry doesn’t boot anymore, just a black screen.