Attitude Detection and Localization for Unmanned Aerial Vehicles

Abstract Over the past decade, unmanned aerial vehicles (UAV) have been developed rapidly for more and more applications among civilian uses such as reconnaissance, earth sensing, and scientific data collection. For achieving those applications, the UAVs have to be equipped with an accurate attitude detection and localization module to maintain a stable attitude and a correct heading direction during flight. This paper reports the implementation of an attitude detection and localization module for UAVs by integrating sensing data from the GPS sensor, inertial measurement unit (IMU), and digital compass. The module is realized based on the Arduino platform to compute the fused attitude and localization information and send the fused data to the ground station computer in real time. To avoid the data drift problem of the GPS sensor, the zero velocity updated algorithm is used to detect the zero motion of the vehicle from IMU measurements for deciding whether to update the localization information. Graphical abstract System architecture of the attitude detection and localization module, in which the Arduino microcontroller is utilized to read measurements from IMU to calculate the acceleration and attitude of the UAV, read data from the digital compass to obtain flight direction, and retrieve the GPS packets to get latitude and longitude. Then, the XBEE transceiver is used to send these integrated attitude and localization data to the ground station computer for further processing.

module to maintain a stable flying attitude and correct flight direction. In recent years, localization services such as digital map navigation systems and Google Maps web services have become very popular. Modern smartphones all have built-in GPS location modules and Wi-Fi transceivers which can provide localization services with different levels of accuracy. However, the GPS technology is limited in one important respect because line of sight must be maintained between several satellites and the receiver. Local geography such as hills, mountains and gorges, forests and tall buildings in cities and even the weather can interfere with satellite communication. In addition, GPS sensors are subject to data drift problem. [4] An IMU contains accelerometers and gyroscopes to detect angular velocities and accelerations on three axes of the body coordinate system. It can further provide the displacement and the attitude [5] of an object by use of double integral calculation and coordinate transformation. In contrast to GPS, IMU measurements are not affected by the environment in which the object is located. Though IMUs were originally used for missile guidance applications, due to recent advances of MEMS technology which make IMU devices be manufactured in very tiny size and with low power consumption, IMUs can now be worn on the body or embedded into clothing for different kinds of applications such as human tracking and locating, [6] recording athletics and sports training data, [7] the detecting of falls and assistance in rehabilitation, [8] human motion capture for creating animations. [9] In addition, they are perfectly suitable for use on UAVs.
Nevertheless, position and attitude angle computed from IMU data may accumulate errors proportional to the square or cube of time. As a result, Jimenez et al. [10] proposed a method with integration of IMU data, the extended Kalman filter technique, and the zero velocity update (ZUPT) algorithm to implement a localization system. Nam [11] proposed the use of IMU alone to perform localization along with particular events (such as turning) and map information to compensate for accumulated position errors. Duan and Luo [12] proposed an integrated localization system to merge image measurements with IMU data for state estimation in formation flight application of UAVs. Wang et al. [13] proposed an accurate GPS-IMU/dead reckoning data fusion method for providing absolute localization for driverless cars. Wang et al. [14] proposed a robust and novel non-linear complementary filter approach for MAVs attitude estimation based on low-cost MARG and embedded air data sensors.
In this paper, an attitude detection and localization module are presented that integrates sensing data from GPS, IMU and a digital compass to estimate the attitude and position of a UAV. In addition, to overcome the drift problem of GPS, the ZUPT algorithm is applied by first

Introduction
Unmanned aerial vehicles (UAVs), originally used in military applications, earth sensing, reconnaissance, and scientific data collection have now been rapidly developed for a wide range of applications, such as recreation and entertainment, remote communication and monitoring, and smart living. For example, Amazon has been developing the ' Amazon PrimeAir' project, [1] in which UAVs are used to deliver packages that weigh less than 5 lbs, within 30 min, to a location on a GPS map indicated by a customer, see Figure 1. A four-rotor md4-1000 microdrone UAV, carrying a high resolution camera, was applied to flying 12 km over the Gotthard area of the Alps from Switzerland to Italy in very windy conditions using GPS Waypoint mode,[2] see Figure 2. The US Massachusetts Institute of Technology (MIT) Senseable City Lab developed a UAV for guiding visitors [3] to their destinations by input of the location codes on a mobile phone to overcome the problem of their going astray.
To achieve these applications, the UVAs need to be equipped with a precise attitude detection and localization  detecting from the IMU whether the UAV is moved and then deciding whether GPS data should be used to update the localization data.

GPS outdoor positioning
The GPS sensor can periodically output $GPRMC packets, as shown in Table 1, based on NMEA protocol. The packet, if valid, simply provides the longitude and latitude of the current position, which can be used with the Google Maps API to access the digital map at that position via the Internet in real time.
The GPS localization technology has a limitation that enough satellites have to be within line of sight. The GPS signal may be blocked by metal roofs or tall buildings. Besides, GPS precision is often degraded subject to drift problem. As shown in Figure 3, even when the GPS sensor is stationary, the measured longitudes and latitudes may drift significantly. The red dots on the figure indicate the longitudes and latitudes coordinates measured by the stationary GPS sensor, and the drift can exceed tens of meters. Therefore, the ZUPT algorithm [10] is applied by IMU measurements to overcome the drift problem. In short, first remove the gravitational effect from the acceleration measurements of IMU to obtain the true acceleration of the UAV and accordingly determine if the UAV has moved and whether to update the UAV's position by use of GPS measurements.

Attitude detection and localization based on IMU
The following describes the attitude detection and localization method based on IMU measurements. As shown in Figure 4, let {W} denote the world frame, {B} denote the body frame of IMU. The IMU module is mounted on the UAV, and the state vector is represented as equation (1), where P k = x k y k z k T , V k = ẋ kẏkżk T , and O k = � k, k, k T denote the position, velocity, and attitude of the UAV. The IMU uses gyroscopes and accelerometers to detect the angular velocities and accelerations on three axes of the body coordinate system, {B}, and through the coordinate transformation and double integral calculation, as shown in Figure 5, the position and orientation of the UAV relative to the world frame {W} can be obtained. Accordingly, the attitude O k and the rotation matrix R W B,k can be computed from IMU. To overcome the GPS drift problem, the ZUPT algorithm is applied for detecting whether the UAV is moved.
The proposed ZUPT algorithm is described as follows: Let a B k denote the acceleration measurements of IMU in {B}, which contains the component of gravitational acceleration. To detect whether the UAV has moved, the actual acceleration of the UAV relative to {B}, ã B k , is computed by removing the gravitational acceleration from a B k . Before that, the gravitational acceleration vector needs to be transformed from the world frame, {W}, into the body frame, {B}. By use of the rotational matrix, R W B,k , computed from IMU, the computation of the vector, ã B k , can be expressed as equation (2),  accordingly decide whether to update the position data detected by the GPS. The block diagram of the proposed ZUPT algorithm is shown in Figure 6.

System architecture
The Arduino microcontroller is utilized to read measurements from IMU to calculate the acceleration and attitude of the UAV, read data from the digital compass to obtain flight direction, and retrieve the GPS packets to get latitude and longitude. Then, the XBEE transceiver is used to send these integrated attitude and localization data to the ground station computer for further processing. The signal flow graph of the proposed attitude detection and localization module is shown in Figure 7. The hardware components of the module are shown in Figure 8. A GUI program for monitoring the attitude and localization of the UAV is developed on the ground station computer based on the Java language and the Processing programming environment. An animation of the UAV is drawn on the display of the computer, as shown in Figure 9(a), by attitude data of the UAV. A digital satellite map is also drawn on the display, as shown in Figure 9(b), by the Google mapper library with green dots marked on the detected GPS positions. As mentioned previously, to overcome the GPS drift problem, the ZUPT algorithm is performed on the ground station computer to determine whether the UAV has moved, followed by a decision as to whether to update the position using the GPS measurements.

Hardware and software components
In this subsection, the hardware and software components utilized to realize the proposed module are described.
where G = (0, 0, g) T denotes the gravitational acceleration of the earth. Using statistics of the true acceleration, ã B k , one can determine whether the UAV has moved and   (a) Arduino platform: Because the UAV usually has very tight restriction in its payload, the smallsized Arduino Pro Mini microcontroller board (see Figure 10) is utilized as the processing unit of the proposed module. The Pro Mini board is only 0.7 × 1.3 inches in size and can be powered directly by a lithium battery. The board has 14 digital output/input pins, 6 analog input pins, one I 2 C interface and one UART interface. The I 2 C interface was used to read measurements from the IMU and the digital compass. The hardware UART is connected to the XBEE transceiver to transmit the integrated attitude and localization data to the ground station computer. On the other hand, a software simulated UART is used to interface with the GPS and screen out the $GPRMC packet among all NMEA packets.     (b) XBEE transceiver: A pair of XBEE Pro 63 mW transceivers (see Figure 11) was utilized to transmit the attitude and localization data to the code within the context of the visual arts. It contains various libraries for 2D/3D graphics and is very helpful for programming images, animation, and interaction. (g) Google Mapper library: Google Mapper is a lightweight library that can be used to download images of any size from Google Map and to convert the geographic coordinates (i.e. longitude and latitude) into pixel coordinates on the map image.

Conclusions
In this paper, an attitude detection and localization module for UAVs was designed and implemented. The Arduino Pro Mini microcontroller board was chosen as the processing unit because of its light weight and its open hardware design. It fuses data from several cheap sensors, such as EM406A GPS sensor, the MPU6050 IMU, and the HMC5883L digital compass, to obtain the attitude and localization of the UAV. Since GPS sensors often suffer from the position drift problem which may degrade the sensing positional accuracy of the UAV. To overcome the problem, the ZUPT algorithm is proposed to detect the zero motion of the UAV from the measurements of the IMU and determine whether to update the UAV's position with the GPS data. Experiments were conducted to ground station computer. The transceivers are programmed at the AT command mode and the transmitting distance may be up to one mile. The transceivers are configured in star topology such that the ground station computer can monitor attitudes and positions of several UAVs simultaneously. (c) MPU6050 IMU: The MPU6050 device (see Figure  12(a)) contains a three-axis gyroscope and a threeaxis accelerometer to detect linear and rotational movement of an object. It also has an on-board digital motion processor which can process a sixaxis MotionFusion algorithm[15] to calculate the quaternion, or equivalently the attitude, of the object. The sensing data is stored in a FIFO buffer which can be read via the I 2 C interface. (d) HMC5883L digital compass: The HMC5883L is a three-axis digital compass (see Figure 12(b)) that provides 1°-2° compass heading accuracy. The sensor data can be read via the I 2 C interface. (e) GPS module: The EM406A GPS receiver (see Figure 13) is used to obtain longitude and latitude information resolved from GPS satellites. The output is in NMEA protocol format sent by the built-in serial port at 4800 baud rate. (f) Processing IDE: Processing is an open source programming language and integrated development environment (see Figure 14) especially suitable for students, artists, designers, and researchers to   verify the validness of the proposed module. A GUI program that contains a 3D animation and a satellite map was developed on the ground station computer for monitoring the detected attitude and the position of the UAV. The proposed module may be further extended in the future to provide the indoor localization function. For example, applying double integral calculation and coordinate transformation to IMU measurements can obtain the position, velocity, and orientation of a UAV in indoor environment, as depicted in Figure 5. Furthermore, the module can be further enhanced by integrating all the sensor components onto one circuit board and increasing the transmission distance of the XBEE transceivers.

Disclosure statement
No potential conflict of interest was reported by the authors.