Pixhawk 4 flight control establishes connection with Up Board’s ROS
The purpose of establishing a connection between Pixhawk 4 and ROS:
to install the microcomputer and Pixhawk 4 flight control board on the drone to achieve autonomous flight of the drone
Table of contents
1. mavros function package
The Pixhawk 4 flight controller needs to establish contact with the microcomputer through the mavros function package in the microcomputer ROS, and then communicate through the mavlink protocol. Therefore, we must first install the Ubuntu system on the microcomputer and install the ROS and mavros function packages.
Here I install mavros according to the usage documentation of XTDrone Yuque
- Depends on installation
sudo apt install ninja-build exiftool ninja-build protobuf-compiler libeigen3-dev genromfs xmlstarlet libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
pip2 install pandas jinja2 pyserial cerberus pyulog==0.7.0 numpy toml pyquaternion empy pyyaml
pip3 install packaging numpy empy toml pyyaml jinja2 pyargparse
Install mavros
sudo apt install ros-melodic-mavros ros-melodic-mavros-extras
wget https://gitee.com/robin_shaun/XTDrone/raw/master/sitl_config/mavros/install_geographiclib_datasets.sh
sudo chmod a+x ./install_geographiclib_datasets.sh
sudo ./install_geographiclib_datasets.sh
2. Pixhawk 4 flight control serial port settings
There are two ways to connect to ROS
The first one: USB serial port and TELEM2 connection of Pixhawk 4
- I found the interface diagram corresponding to the flight control on the PX4 official website. There are only 3 lines connected between TELEM2 and the USB serial port:
2 (TX) → USB port (RX)
3 (RX) → USB port (TX)
6 (GND) → USB port ( GND)
- After the USB serial port is connected to the computer, make sure that Ubuntu and the USB serial port are connected. If not, it may be a problem with the virtual machine. Then go to the path where you installed ROS (mine is in opt/ros/),
opt/ros/melodic/share/mavros/launch/px4.launch/
Enter px4.launch and modify the following line of code
<arg name="fcu_url" default="/dev/ttyACM0:115200" />
ttyACM0:115200
Change tottyUSB0:921600
- Power the Pixhawk 4 flight controller, then open the terminal and enter
roslaunch mavros px4.launch
Based on this error report, we give it permission
sudo chmod 777 /dev/ttyUSB0
then start again
roslaunch mavros px4.launch
Second method: Connect the USB port of Pixhawk 4 to the computer
At this time, you need to add px4.launch in the path below
opt/ros/melodic/share/mavros/launch/px4.launch/
change into
<arg name="fcu_url" default="/dev/ttyACM0:115200" />
Save and exit, open terminal, start
roslaunch mavros px4.launch
3. Test whether the Pixhawk 4 flight controller is connected to ROS
Open a new terminal
rostopic echo /mavros/local_position/pose
or
rostopic echo /mavros/local_position/velocity_body
If the information can be printed out, the connection is normal.
or
rqt_graph
View in other ways