Connecting ArduPilot and ROS on Raspberry PI 4

Hi,
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 → https://www.mediafire.com/file/z6iho4eaz3m16om/rosout.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.

I follow the steps to install in Tier 1 Ubuntu 22.04, how did you get the roscore installed? Is it because I installed ros-humble-ros-base and not desktop version? I follow suggestion here, base is enough.

I got the message
Command ‘roscore’ not found, but can be installed with :
sudo apt install python3-roslaunch

[Edit]
ROS 2 does not exist roscore anymore

Did you manage to get the serial connection working?

in my case, I got the following errors using the followinfg command. I tried adding sudo in front, commands not found.

ros2 launch mavros apm.launch fcu_url:=///dev/ttyAMA1:921600

[mavros_node-1] [WARN] [1703040975.607465545] [mavros.sys]: VER: your FCU don’t support AUTOPILOT_VERSION, switched to default capabilities
[mavros_node-1] [INFO] [1703040995.594057491] [mavros.mavros_router]: link[1000] trying to reconnect…
[mavros_node-1] [ERROR] [1703040995.594602266] [mavros.mavros_router]: link[1000] reconnect failed: DeviceError:serial:open: Permission denied

sudo: ros2: command not found
sudo: source: command not found

[edit]
oh I need to chmod.
sudo chmod 666 /dev/ttyAMA1

[mavros_node-1] [INFO] [1703043435.797725348] [mavros.mavros]: MAVROS UAS via /uas1 started. MY ID 1.191, TARGET ID 1.1
[mavros_node-1] [INFO] [1703043435.893891732] [mavros.mavros_router]: link[1001] detected remote address 1.191
[mavros_node-1] [WARN] [1703043435.939497584] [mavros.cmd]: CMD: Unexpected command 520, result 0
[mavros_node-1] [INFO] [1703043435.943280407] [mavros.geofence]: GF: Using MISSION_ITEM_INT
[mavros_node-1] [INFO] [1703043435.943579029] [mavros.rallypoint]: RP: Using MISSION_ITEM_INT
[mavros_node-1] [INFO] [1703043435.943688081] [mavros.mission]: WP: Using MISSION_ITEM_INT
[mavros_node-1] [INFO] [1703043435.943783875] [mavros.sys]: VER: 1.1: Capabilities 0x000000000000fbef
[mavros_node-1] [INFO] [1703043435.943882428] [mavros.sys]: VER: 1.1: Flight software: 040300ff (3137623834343339)
[mavros_node-1] [INFO] [1703043435.943941260] [mavros.sys]: VER: 1.1: Middleware software: 00000000 (0000000000000000)
[mavros_node-1] [INFO] [1703043435.944166254] [mavros.sys]: VER: 1.1: OS software: 00000000 (6430656435653636)
[mavros_node-1] [INFO] [1703043435.944273658] [mavros.sys]: VER: 1.1: Board hardware: 008c0000
[mavros_node-1] [INFO] [1703043435.944323546] [mavros.sys]: VER: 1.1: VID/PID: 2dae:1016
[mavros_node-1] [INFO] [1703043435.944360970] [mavros.sys]: VER: 1.1: UID: 0000000000000000
[mavros_node-1] [WARN] [1703043436.006865604] [mavros.time]: TM: Wrong FCU time.
[mavros_node-1] [INFO] [1703043436.506899043] [mavros.mavros]: CON: Got HEARTBEAT, connected. FCU: ArduPilot
[mavros_node-1] [INFO] [1703043436.507231312] [mavros.mission]: WP: detected enable_partial_push: 1
[mavros_node-1] [INFO] [1703043437.523120229] [mavros.sys]: VER: 1.1: Capabilities 0x000000000000fbef
[mavros_node-1] [INFO] [1703043437.523386092] [mavros.sys]: VER: 1.1: Flight software: 040300ff (93448b71)
[mavros_node-1] [INFO] [1703043437.523461535] [mavros.sys]: VER: 1.1: Middleware software: 00000000 ( )
[mavros_node-1] [INFO] [1703043437.523514255] [mavros.sys]: VER: 1.1: OS software: 00000000 (66e5de0d�-��)
[mavros_node-1] [INFO] [1703043437.523562032] [mavros.sys]: VER: 1.1: Board hardware: 008c0000
[mavros_node-1] [INFO] [1703043437.523610364] [mavros.sys]: VER: 1.1: VID/PID: 2dae:1016
[mavros_node-1] [INFO] [1703043437.523683806] [mavros.sys]: VER: 1.1: UID: 0000000000000000
[mavros_node-1] [ERROR] [1703043442.256876783] [mavros.sys]: FCU: PreArm: Throttle below failsafe
[mavros_node-1] [ERROR] [1703043442.257912717] [mavros.sys]: FCU: PreArm: Hardware safety switch
[mavros_node-1] [ERROR] [1703043442.258968541] [mavros.sys]: FCU: PreArm: Battery 1 below minimum arming voltage
[mavros_node-1] [INFO] [1703043446.508945540] [mavros.home_position]: HP: requesting home position
[mavros_node-1] [INFO] [1703043446.515052189] [mavros.sys]: FCU: ArduCopter V4.3.0 (93448b71)
[mavros_node-1] [INFO] [1703043446.516115457] [mavros.sys]: FCU: ChibiOS: 66e5de0d
[mavros_node-1] [INFO] [1703043446.516858733] [mavros.sys]: FCU: CubeOrange 001D002D 32315108 38323831
[mavros_node-1] [INFO] [1703043446.517399126] [mavros.sys]: FCU: RCOut: PWM:1-8 DS600:9-12 PWM:13-14
[mavros_node-1] [INFO] [1703043446.518137050] [mavros.sys]: FCU: IMU0: fast sampling enabled 8.0kHz/2.0kHz
[mavros_node-1] [INFO] [1703043446.518518762] [mavros.sys]: FCU: IMU1: fast sampling enabled 9.0kHz/2.3kHz
[mavros_node-1] [INFO] [1703043446.519244983] [mavros.sys]: FCU: IMU2: fast sampling enabled 9.0kHz/2.3kHz
[mavros_node-1] [INFO] [1703043446.519585140] [mavros.sys]: FCU: Frame: QUAD/X
[mavros_node-1] [INFO] [1703043451.518598889] [mavros.mission]: WP: mission received
[mavros_node-1] [INFO] [1703043456.519703880] [mavros.rallypoint]: RP: mission received
[mavros_node-1] [INFO] [1703043461.519426965] [mavros.geofence]: GF: mission received
[mavros_node-1] [INFO] [1703043466.715644111] [mavros.param]: PR: parameters list received
[mavros_node-1] [ERROR] [1703043473.256038877] [mavros.sys]: FCU: PreArm: Throttle below failsafe
[mavros_node-1] [ERROR] [1703043473.256735284] [mavros.sys]: FCU: PreArm: Hardware safety switch
[mavros_node-1] [ERROR] [1703043473.257150755] [mavros.sys]: FCU: PreArm: Battery 1 below minimum arming voltage
[mavros_node-1] [WARN] [1703043496.505907427] [mavros.time]: TM: Wrong FCU time.
[mavros_node-1] [ERROR] [1703043504.255434445] [mavros.sys]: FCU: PreArm: Throttle below failsafe
[mavros_node-1] [ERROR] [1703043504.256417975] [mavros.sys]: FCU: PreArm: Hardware safety switch
[mavros_node-1] [ERROR] [1703043504.256974571] [mavros.sys]: FCU: PreArm: Battery 1 below minimum arming voltage