Environment
Windows 11
pixhawk2.4.8
Raspberry Pi 4B
QGroundControl 4.2.8
Mission Planner 1.3.80
ardupilot
ubuntu 20.04.2
ros noetic
(The software and hardware versions used by me are for reference only)
Steps
- Install firmware on pixhawk (I use arduSub 4.2.0)
- Install ubuntu20 on Raspberry Pi
- Raspberry Pi enables hardware serial communication
- Install ros on raspberry pi
- Install mavros on raspberry pi
- pixhawk configures the serial port in QGroundControl
- Configure the startup script of mavros
- Connection between raspberry pi and pixhawk
- Start mavros test
- Topic publishing and subscription
1. pixhawk installation firmware
Use ground station software (mission planner or QGC) to burn, which can be installed online or offline.
Use the firmware with apj suffix (ardusub.apj) in Windows 11, install it directly on MP, follow the prompts, and install it again if you make any mistakes.
2. Install ubuntu20 on Raspberry Pi
At present, ubuntu20 will be relatively stable and support the ros 1 version noetic
Of course you have to download the operating system from the official website
There are too many tutorials online, skip them
3. Enable hardware serial communication on Raspberry Pi
Raspberry Pi 4B has 40 pins, of which TXD and RXD are used for serial communication and need to be configured before they can be used.
In the ubuntu system, use the command to find the serial port named ttyAMA0
ll /dev/
Set ttyAMA0 as the hardware serial port, refer to the tutorial of the boss
to appear
serial0 → ttyAMA0 serial1 → ttyS0
Among them, to install raspi-config on ubuntu20, please refer to this
4. Install ros on Raspberry Pi
One-click installation of Yuxiang ros is so fragrant
5. Install mavros on Raspberry Pi
There are many tutorials, here we use binary installation
sudo apt-get install ros-noetic-mavros ros-noetic-mavros-extras
The GeographicLib dependent library installation recommended by the official website often cannot be installed due to network problems. It is recommended to install it offline and download it from the boss’s gitee.
Copy the geoids gravity magnetic three folders to the /usr/share/GeographicLib folder
Jump to the mavros directory
roscd mavros
Start the mavros node to see whether the installation is successful.
roslanch mavros apm.launch
6. pixhawk configures the serial port in QGroundControl
There are multiple serial ports on pixhawk. I use telem 2 to communicate with the Raspberry Pi. In order to avoid the alarm of RTT too high for timesync (the baud rate is too low), I need to set the fixed baud rate of the serial port to 921600.
Connect pixhawl to QGC via USB, and change the serial2 baud rate to 921600 in the settings.
7. Configure mavros startup script
Since I am using ardusub firmware, I use the apm.launch script to start the node
Modify the apm.launch file under /opt/ros/noetic/share/mavros/launch
<arg name="fcu_url" default="/dev/ttyACM0:57600" />
Change the serial port name and baud rate to the following
<arg name="fcu_url" default="/dev/ttyAMA0:921600" />
Requires sudo permissions to modify
8. Connection between Raspberry Pi and pixhawk
Just connect pixhawk to telem 2 and power port (required for testing)
Connect the TX, RX and GND of telem 2
The power port is connected to the ammeter, and the ammeter is connected to the power supply for independent power supply (when I use the USB port of pixhawk to connect to the Raspberry Pi, the power will be cut off and restarted. The voltage may be unstable, so it is powered separately)
Finally, connect the three wires of telem 2 to the pins of Raspberry Pi. For reference, it is recommended to use Dupont wire. I did not connect 5v, so there are three wires. Raspberry Pi and pixhawk are powered separately.
9. Start mavros test
roslaunch mavros apm.launch
In the print window, you can see that the window connection is successful, the initialization is successful, and the heartbeat is monitored.
10. Topic publishing and subscription
Use the command to view all topics
rostopic list
/mavlink/from /mavlink/gcs_ip /mavlink/to /mavros/adsb/send /mavros/adsb/vehicle /mavros/battery /mavros/cam_imu_sync/cam_imu_stamp /mavros/camera/image_captured /mavros/cellular_status/status /mavros/companion_process/status /mavros/distance_sensor/rangefinder_pub /mavros/distance_sensor/rangefinder_sub /mavros/esc_info /mavros/esc_status /mavros/esc_telemetry /mavros/estimator_status /mavros/extended_state /mavros/fake_gps/mocap/pose /mavros/geofence/waypoints /mavros/global_position/compass_hdg /mavros/global_position/global /mavros/global_position/gp_lp_offset /mavros/global_position/gp_origin /mavros/global_position/local /mavros/global_position/raw/fix /mavros/global_position/raw/gps_vel /mavros/global_position/raw/satellites /mavros/global_position/rel_alt /mavros/global_position/set_gp_origin /mavros/gps_input/gps_input /mavros/gps_rtk/rtk_baseline /mavros/gps_rtk/send_rtcm /mavros/gpsstatus/gps1/raw /mavros/gpsstatus/gps1/rtk /mavros/gpsstatus/gps2/raw /mavros/gpsstatus/gps2/rtk /mavros/home_position/home /mavros/home_position/set /mavros/imu/data /mavros/imu/data_raw /mavros/imu/diff_pressure /mavros/imu/mag /mavros/imu/static_pressure /mavros/imu/temperature_baro /mavros/imu/temperature_imu /mavros/landing_target/lt_marker /mavros/landing_target/pose /mavros/landing_target/pose_in /mavros/local_position/accel /mavros/local_position/odom /mavros/local_position/pose /mavros/local_position/pose_cov /mavros/local_position/velocity_body /mavros/local_position/velocity_body_cov /mavros/local_position/velocity_local /mavros/log_transfer/raw/log_data /mavros/log_transfer/raw/log_entry /mavros/mag_calibration/report /mavros/mag_calibration/status /mavros/manual_control/control /mavros/manual_control/send /mavros/mission/reached /mavros/mission/waypoints /mavros/mocap/pose /mavros/mount_control/command /mavros/mount_control/orientation /mavros/mount_control/status /mavros/nav_controller_output /mavros/obstacle/send /mavros/odometry/in /mavros/odometry/out /mavros/onboard_computer/status /mavros/param/param_value /mavros/play_tune /mavros/radio_status /mavros/rallypoint/waypoints /mavros/rangefinder/rangefinder /mavros/rc/in /mavros/rc/out /mavros/rc/override /mavros/setpoint_accel/accel /mavros/setpoint_attitude/cmd_vel /mavros/setpoint_attitude/thrust /mavros/setpoint_position/global /mavros/setpoint_position/global_to_local /mavros/setpoint_position/local /mavros/setpoint_raw/attitude /mavros/setpoint_raw/global /mavros/setpoint_raw/local /mavros/setpoint_raw/target_attitude /mavros/setpoint_raw/target_global /mavros/setpoint_raw/target_local /mavros/setpoint_trajectory/desired /mavros/setpoint_trajectory/local /mavros/setpoint_velocity/cmd_vel /mavros/setpoint_velocity/cmd_vel_unstamped /mavros/state /mavros/statustext/recv /mavros/statustext/send /mavros/terrain/report /mavros/time_reference /mavros/timesync_status /mavros/trajectory/desired /mavros/trajectory/generated /mavros/trajectory/path /mavros/tunnel/in /mavros/tunnel/out /mavros/vfr_hud /mavros/vision_pose/pose /mavros/vision_pose/pose_cov /mavros/wind_estimation /move_base_simple/goal
View topic information
rostopic info topic name
Check topic posting frequency
rostopic hz topic name
Print topic information
rostopic echo topic name
Print heading angle
rostopic echo /mavros/global_position/compass_hdg
Print three-axis acceleration and angular velocity
rostopic echo /mavros/imu/data
If there is no output when printing, please refer to the expert’s instructions.
rosservice call /mavros/set_stream_rate 0 10 1
Modify the broadcast frequency of the flight controller