PX4 Geometric Controller

PX4 Geometic Controller

In this project, I have used PX4 framework and geometric controller to control the drone to fly with the trajectory which I have published. To complete this mission, I have used geometric controller. First, I have set up the px4 with gazebo simulation environment. Then, I need to use mavros to communication with the hardware which is simulated in gazebo. In this I have used the offboard node to test if the communication is successful. At last, I have run the geometric controller to let the drone fly with a circle trajectory.

1) PX4 Gazebo Simulation Setup

In this part, I followed the instructions as shown in the ROS with Gazebo Simulation PX4 Documentation to check if the necessary environment is setup correctly, you can clone the project using the following command.

Notice

The PX4 framework is switched with 1.12.3 version (stable) which is tested successfully.

1
2
3
mkdir -p px4_ws && cd px4_ws
git clone -b v1.12.3 https://github.com/PX4/PX4-Autopilot.git
cd PX4-Autopilot && make px4_sitl_default gazebo

To source the PX4 environment, I have run the following commands

1
2
3
4
source ~/catkin_ws/devel/setup.bash    # (optional)
source Tools/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)/Tools/sitl_gazebo

Then, I can run the rest of the roslaunch files in the same terminal

1
roslaunch px4 posix_sitl.launch

2) Install MAVROS

In this part, I have followed the instructions as show in MAVROS Documentation. MAVROS is a ROS(1) package that enables MAVLink extendable communication between computers running ROS(1) for any MAVLink enabled autopilot, ground station, or peripheral. MAVROS is the ‘’official’’ supported bridge between ROS(1) and the MAVLink protocol.

While MAVROS can be used to communicate with any MAVLink-enabled autopilot, this documentation explains how to set up communication between the PX4 Autopilot and a ROS(1) enabled companion computer.

I have run the apt to install the MAVROS and MAVLink

1
sudo apt install ros-noetic-mavros ros-noetic-mavros-extras

And I have also clone these two project in the local workspace.

1
2
3
4
mkdir -p px4_ws/mavros_ws/src && cd px4_ws/mavros_ws/src
git clone -b master https://github.com/mavlink/mavros.git
git clone https://github.com/mavlink/mavlink.git
cd .. && catkin build

Then I could use the MAVROS node to communicate with the drone which is simulated in Gazebo.

3) Install mavros_controllers

These controllers are controlling MAVs using mavros package in OFFBOARD mode. So the repository contains controllers for controlling MAVs using the mavros package.

I have cloned the project in the local workspace with following commands.

1
2
3
4
5
6
7
cd px4_ws/mavros_ws/src
git clone https://github.com/MingshanHe/mavros_controllers
git clone https://github.com/catkin/catkin_simple
git clone https://github.com/ethz-asl/eigen_catkin
git clone https://github.com/ethz-asl/mav_comm
cd .. && catkin build
source devel/setup.bash

The following launch file enables the geometric controller to follow a circular trajectory. First, I have run the gazebo simulation with MAVROS, and then I have run the geometric controller.

1
2
roslaunch px4 mavros_posix_sitl.launch
roslaunch geometric_controller sitl_trajectory_track_circle.launch

1


PX4 Geometric Controller
http://mingshanhe.github.io/2022/05/20/ROS/PX4_2/
Author
Mingshan He
Posted on
May 20, 2022
Licensed under