Sunday, December 16, 2018

AVCS2: Attitude and Heading Reference System (GY-88 10-DOF) module


The GY-88 packages 3 popular sensors (technically more than 3, but I will cover that later) in a single convenient PCB. Each sensor measures a specific type of spacial data. The module contains a 6-axis accelerometer, a magnometer, and a barometer. All the sensors you need to create a Attitude and Heading Reference System (AHRS). In this post I will go over each sensor in more detail. I will also cover how it can be used to inform an Autonomous Vehicle Control System aimed at multi-rotor flight control.
The design for this module is based on the MPU6050, HMC5883L, and BMP085 sensors. This combination of sensors (or minor variations of it) have become the de facto standard for projects requiring spacial awareness such as autonomous vehicles, robotics, and Motion-based Human Interface Devices. I will be going over the first case here, but the information, concepts, and even some of the code, will translate to the others equally well.


The Sensors

While the package is marketed as a combination of the 3 sensors mentioned in the opening, it would be fair to say that it is technically 4-6 sensors. You see, the MPU6050 is a '6-axis accelerometer' which really means a 3-axis accelerometer and a 3-axis gyroscope combined along the same axial orientation (more on this below). Since the accelerometer and the gyroscope measure different type of motion you can consider the gyroscope another sensor. Finally, both the MPU6050 and the BMP085 have a thermometer that is sometimes accessible (depending on the exact GY-* module you get). If you count each as it's own sensor you could say the module has 6 sensors. However, having 2 thermometers in such a small space isn't likely to give you more information so I could also see someone saying it is really only 5. Enough about how many sensors. Let's get down to what each one does in more detail.

MPU6050

This image shows the 3 axis in relation to the body orientation of an aircraft. It illustrates why I made the distinction I did between 6-axis and 3-axis above. The first piece of this sensor, the accelerometer, measures the force of acceleration along the X, Y, and Z, axis. This can be seen as the linear motion. Commonly referred to as Forward, Backward, Up, Down, Left, and Right but their are obviously variations (port and starboard for example). The gyroscope provides the second piece to the puzzle which is the rotational force (torque) being applied to each axis. These are distinguished by their names Roll, Pitch, and Yaw as well as the use of the Greek symbols Phi, Omikron, and Psi respectively. Torque can be applied in a clockwise or counter-clockwise direction with relation to the axis it is being applied along. These two pieces of information allow us to calculate our current (and future) orientation with relation to the surface of the earth. This information also forms the most basic flight assistance platform called an Inertial Measurement Unit (IMU). The IMU by itself give us the ability to add stabilization assistance to flight modes. Collectively the angles along the X and Y and Z axis are called the Attitude.

HMC5883L


The Honeywell Magnetic Compass (HMC) allows us to calculate the compass heading of our flight system. Now, in addition to knowing the position with relation to the earth's surface, we can also calculate the exact direction an object is facing with regard to Magnetic North, once you account for the magnetic declination (http://www.magnetic-declination.com/) that is. Adding the Heading information to the Attitude information gives the system an absolute directional reference such as North, South, East, and West. The combination of the IMU with a magnetic compass allows for basic Autopilot. Autonomous flights, called "Missions", can be planned as a series of triplets (heading, speed, time).

BMP085


The BMP085 is the final major sensor on the GY-88 package. It is used to sense barometric pressure. You may remember from you elementary earth science days that the air gets 'thinner' the higher you are from sea level. At 0m, the standard barometric pressure is 101.325 kPa (760 mmHg). By taking the local atmospheric pressure, you can accurately calculate the altitude based on the difference in pressure. Luckily the BMP085 library does the heavy lifting when it comes to this calculation. For more accurate altitude calculation, you can enter the specific atmospheric pressure at sea level for your flight area. This will change a bit based off of weather conditions also so make sure to calibrate it correctly prior to each flight for the best results. 

I mentioned previously that the GY-88 package also sometimes exposes the temperature sensor on one or more of the components. Because this too can be used to make an educated guess about altitude I chose to lump it in with the BMP085. Before we get into numbers, it’s important to remember that temperature can vary for a number of different reasons: shade, sun, nearby buildings (or lack of them) can all influence the temperature so it shouldn't be relied on alone. These caveats aside, If there's no snow (or rain) falling from the sky (and you’re not in a cloud), the temperature will decrease by about 5.4°F for every 304.8 meters (1,000 feet) you raise the elevation. This equates to about 9.8°C per 1,000 meters. However, if it is snowing or raining (or you are in-fact in a cloud), the temperature decreases by about 3.3°F for every 304.8 meters (1,000 feet) you raise the elevation. Meaning a change of approximately 6°C per 1,0000 meters. For a more in depth discussion you can check out the posting here

The Hookup

The GY-88 is +5v tolerant. The sensors themselves run at +3.3v, though so the GY-88 in the picture also contains an onboard 3.3v regulator. You can bypass this regulator by not connecting to the 5v pin and instead power the package via the 3v3 pin. Make sure you apply the right voltage for the pin setup you select. The GY-88 is also a bit power hungry for such a small package. I recommend not powering it directly off an Arduino +5v (or +3v3 pin). Instead, power it directly off a regulated +5v or +3.3v source. The I2C pins (SCL, SDA) are used to communicate with the MPU6050. The M_DRDY should be hooked to a digital input pin. The pin will be pulled high from the sensor-side when there is HMC5883L data ready. The G_AD0 pin should be set as an analog input pin. This is where you will receive the MPU6050's Gyroscopic output. The G_INT pin should be hooked to a digital input pin. It will be pulled high by the sensor-side when the MPU6050 has Gyroscopic data available. This is only required if you plan to use interrupt-based programming to give the gyroscope precedence in code.

The System

AHRS position in data flow
Each of these sensors is popular in the maker community. So, each has a couple possible libraries. Each library will come with examples that can serve as a good coding outline. However, combining the sensors into an AHRS suitable for use in an autopilot takes a bit more work. First you have to understand the way decision making is made in-flight. This is famously known as the pilot's OODA loop. In order: the pilot needs to Observer the current state of their situation. They need to Orient themselves to the implications of changes they observe. They need to Decide the next action that needs to be taken. Finally, they need to Act upon their decision. This technique was developed by United States Air Force Colonel John Boyd. Everything in the design of an aircraft should serve to enhance the pilots ability to complete this OODA loop more efficiently. The AHRS fits into the Observe and Orient phases. 


The pilot will run through  each of his instruments to get the current reading (the observe phase). They will then compare this to previous readings in the orient phase. An example might be figuring out the relative approach speed to some landing spot. The autopilot uses this information in it's decision making process as well to decide if it should slow down, speed up, or maintain current speed. In a practical programmatic sense, We break the autopilot's OODA loop into two parts called the Fast Loop and the Slow Loop. Reading these sensors (and the others) is done inside the Fast Loop. This loop is where all critical flight I/O happens. By contrast, the Slow Loop exists for non-critical processes to execute without compromising the ability of the system to react quickly to sensor changes. I will write more about these loops in a future post describing the flight controller programming. For now, what is important to understand is that these sensors are read quickly, and their outputs are fed to a set of mathematical functions collectively called the PID. Without getting into the mathy bits these stand for Proportional, Integral, and Differential respectively. Each of these functions outputs a a number which is the amount of adjustment the system should apply according it it's view of the data. The Proportional is like only looking at only the present sensor data. The Integral looks at data that happened in the past. It adds a bit of smoothing and helps to eliminate oscillations from overshooting the desired attitude. Finally the Derivative is predicting where the vehicle will be at some future time. I will discuss the PID (along with the other parts of the system not covered here) in more detail in a future posting. These outputs are mixed with other inputs in the aptly named Mix code. The job of the Mix code is to take the output of the PID system and apply the definition of the current mode (such as angular mode or assisted mode). The Mix code then sends the final adjustments needed to the Motor control code. The motor control code adjust the individual motor speeds which affects the attitude and/or heading. The whole cycle is then repeated


Conclusion


The GY-88 is a good little sensor. I picked one up for around $18.00 but they seem to be getting more expensive. As I write this, I see them going on Amazon for upwards of $24.00. I think that is still a good deal, though. If you plan to build a small Quadcopter but want the features of it's bigger brothers, this may be the best option. All the code for this, along with the other sections of the Autonomous Vehicle Control System will be released together as a self contained project in the next few months.

No comments:

Post a Comment