4 minute read

Introduction

In this post, we will talk about the integration to PX4 + Mavros + Airsim for drone behavior and the different configurations that have to be done.

Airsim offers a ROS wrapper. The ROS wrapper is composed of two ROS nodes: the first is a wrapper over the AirSim multirotor C++ client library, and the second is a simple PD position controller. For more information : AirSim/airsim_ros_pkgs

The first approach was to use this ROS wrapper to be able to give a behavior by means of speeds to the drone with the topic that provided AirSim ROS Wrapper Node. The difficulty that we can find is that when we command velocities to the drone in the x and y axes the height of the drone is not constant, that is to say, as we command velocities in some of the mentioned axes the drone is losing the height and as a result it ends up on the ground since this node does not have any position controller in the z axis nor velocity controllers in the x and y axes. It is true that there is a node called Simple PID Position Controller Node that provides a position controller in the x, y and z axes but what we need is to control the position of z by commanding velocities in the x and y axes and angular velocities in the z axis. Given what happened, we opted for the solution of integrating PX4 together with Mavros and Airsim, since PX4 offers position and velocity controllers and together with Mavros to be able to command velocities

Configuration of Airsim settings file

To use PX4 together with Airsim, the first thing to do is to configure the Airsim configuration file to specify that we want to use PX4. Note that PX4 [simulator] uses TCP, so we must add: “UseTcp”: true,. Note that we are also enabling LockStep, see PX4 LockStep for more information Lockstep

All the installation and what to build of PX4 firmware SITL mode is on this page: PX4 STIL. Step 4 is important to analyze it and to know which ports are enabled, in order to be able to make the connections with Mavlink through the mavros node.

For this purpose a diagram is shown:

Whiteboard

The ports 14030 and 14020 appers in window PX4 STIL when we execute : make make px4_sitl_default none_iris

portsPX4

PX4 Flight Modes Overview

Flight modes define how the autopilot responds to remote control input, and how it manages vehicle movement during fully autonomous flight.

The modes provide different types/levels of autopilot assistance to the user (pilot), ranging from automation of common tasks like takeoff and landing, through to mechanisms that make it easier to regain level flight, hold the vehicle to a fixed path or position, etc.

In this diagram, you can view flight modes:

commander-flow-diagram

In our case, we are interested in the OFFBOARD flight mode, the HOLD/POSITION flight mode to keep the drone at a constant altitude.

Offboard Mode

This mode allows us to control the movement of the vehicle and the altitude, by setting position, velocity, acceleration, attitude, attitude rates or thrust/torque setpoints.

PX4 must receive a stream of MAVLink setpoint messages or the ROS 2 OffboardControlMode at 2 Hz as proof that the external controller is healthy. If the rate falls below 2Hz while under external control PX4 will switch out of offboard mode after a timeout (COM_OF_LOSS_T), and attempt to land or perform some other failsafe action (security actions). The action depends on whether or not RC control is available, and is defined in the parameter COM_OBL_RC_ACT. For more information : Safety and Failsafes

Parameter COM_FAIL_ACT_T is disable in our case because of if it able before entering failsafe (RTL, Land, Hold), wait COM_FAIL_ACT_T seconds in Hold mode for the user to become aware. During this time the user cannot take control. Then the configured fail-safe action is triggered and the user can take control.

In resume, this mode we will help to command velocities of drone with the help of the topic provided by mavros.

Frames Mavros

The coordinate frames that follow Mavros are 21 (You can see it in mavros messages in the SetMavFrame service SetMavFrame

We use coordinate frames BODY_NED (number 8) because of same as MAV_FRAME_BODY_FRD when used with velocity/accelaration values.

For change coordinate frames, we must go file px4_config.yaml and “setpoint_velocity” in “mav_frame” set BODY_NED

Offboard Parameters

Offboard mode is affected by the following parameters:

  1. COM_OF_LOSS_T : Time-out (in seconds) to wait when offboard connection is lost before triggering offboard lost failsafe (COM_OBL_RC_ACT)

  2. COM_OBL_RC_ACT : Flight mode to switch to if offboard control is lost (Values are - 0: Position, 1: Altitude, 2: Manual, 3: *Return, 4: Land).

  3. COM_RC_OVERRIDE
  4. COM_RC_STICK_OV
  5. COM_RCL_EXCEPT

We will use parameters COM_OF_LOSS_T and COM_OBL_RC_ACT for when we stop publishing speeds

Note: For know more about full parameter reference in PX4 Parameters

Hold Mode

The Hold flight mode causes the vehicle to stop and hover at its current GPS position and altitude.

Position Mode

Position is an easy-to-fly RC mode in which roll and pitch sticks control acceleration over ground in the vehicle’s left-right and forward-back directions (similar to a car’s accelerator pedal), and throttle controls speed of ascent-descent.

Position mode is the safest manual mode for new fliers

PositionMode

QGControl

QGControl is applications that it provides full flight control and vehicle setup for PX4 or ArduPilot powered vehicles.

To install in Ubuntu Linux : Download QGControl

This application allows you to see which parameters have been loaded with PX4 SITL and to visualize which flight mode you are in. It’s more useful for can change some parameter if you wish it. Also we can teleoperate vehicle through joystick.