Active Heading Control Platform for Instruments Flown on High Altitude Balloons

Experiments flown on high-altitude balloons are typically free to spin without any control or information collected on the payload orientation during flight, limiting the scope of experiments that can be performed. Projects that include targeting (i.e. imaging the 2017 solar eclipse) have at best a random chance of succeeding, while video footage is often hard to watch due to high payload rotation rates. While passive stabilization reduces the rotation rate, active pointing control is necessary for continuous target acquisition. Here we discuss a project built by students at Wright College called the Controlled Heading Automation Device (CHAD) that actively controls the heading of other instruments (i.e. cameras) and has been proven to work in flight. This project is open source, 3D printable, made from cheap DIY electronics, and has been made available online (http://physi.cz/chad) so the high-altitude ballooning community can create, use, and adapt it to their own projects. We show how to create an attitude and heading reference system (AHRS) that can be used to continuously record payload orientation, which can supplement experiments where pointing information is needed. We then show how to have CHAD use the AHRS to automatically control the heading of other instruments in real-time without any other inputs.


INTRODUCTION
The use of High Altitude Balloons (HABs) has proven to be an excellent source of student research and projects. A widespread HAB community has formed, with many resources made available online that aid in planning, tracking, and creating experiments. There are also many DIY resources that teach students how to create electronic circuits that retrieve a wide range of data using microcontrollers. While the experiments that can be flown with balloons is continuously expanding, they are typically limited to experiments that do not require any control or record of the orientation of the experiments as the payloads typically rotate around freely. If the orientation of payloads can be recorded, and the heading of experiments can be controlled, it would broaden the types of experiments that can be flown.
Orientation control of payloads can be either passive or active. Passive control is capable of reducing rotation and pendulum motion of payloads. 1 This is useful for projects where a lower rotation rate is desired, such as when taking video. In order to maintain target acquisition, it is necessary to use active control of payloads. Devices that have been used for active control of HAB payloads include reaction wheels 2 and gimbals. 34 Here we investigate the use of a single stepper motor to control the heading (around the vertical payload stack axis) of payloads using only input from an attitude and heading reference system (AHRS).
We had the goal of making this stabilization platform 3D printable, using cheap electronics, and to make the project open source for the HAB community to create and improve upon. We have called this project the Controlled Heading Automation Device (CHAD). The main purpose of this paper is to make CHAD available to the HAB community, and inform about its design and capabilities. All resources including 3D CAD designs, Arduino programs, and more detailed explanations are available at http://physi.cz/chad. A secondary purpose is to describe how to created an AHRS for use with CHAD that can also be used for other projects where it's necessary to record the orientation of payloads. These resources and explanations are further meant to inform instruction of similar projects in an academic setting.

DESIGN 2.1 Overall Structure
The main goal of the structure is to allow the stepper motor to rotate the payload without bearing its weight, and to hold the AHRS in a constant position relative to the stepper motor for reasons discussed in § 3.1. The structure and electronics all attached to each other with size #4-40 screws of differing lengths. Nut-shaped cavities hold the nuts in place, which helps with assembly and stability.  For the structure of CHAD, we designed and 3D printed three of the parts (the main housing, motor platform, and payload arm) and purchased a 4 square, aluminum turntable. The main housing holds the electronics in place, including the AHRS and the Arduino controlling the stepper motor. The main housing attaches to the turntable and motor seat. It has an area on one side designed for attaching the Arduino with the motor shield, and the other side has a space for attaching the AHRS on a half-sized breadboard as seen in fig. 1. The turntable is attached inside the main housing. The payload arm attaches to the turntable, and extends below the main housing to attach to the payload. This way, the turntable bears the weight of the payload. The motor seat attaches to the top of the main housing and holds the stepper motor in place above the payload arm. It also has space to hold batteries for the Arduinos and motor. The payload arm is not designed to attach directly to payloads. Instead, another attachment can be created that is designed for the payload that attaches to the payload arm with four screws. For example, when we used CHAD to control a GoPro camera, we designed and 3D printed a GoPro attachment that could connect to the payload arm. A template payload attachment is provided online to use for new projects.

Magnetic Shield
Stepper motors are different from DC motors in that when a constant voltage is applied, the stepper motor arm is held in a constant position. The input current creates a magnetic field that attracts the gear teeth to hold it in place. We found that these magnetic fields were interfering with the magnetometers readings, and were strong enough to saturate the data. Further, the magnetic fields created by the stepper motor were not constant (see fig. 4), so it was not sufficient to simply move the magnetometer farther away and subtract the field from the data. We resolved this problem by making a magnetic shield out of steel (see fig. 5) to block the stepper motor magnetic fields from the magnetometer. This is the only part that needs to be fabricated without a 3D printer.

ATTITUDE AND HEADING REFERENCE SYSTEM 3.1 Calibration
An Arduino Micro was used control an HMC5883L 3-axis magnetometer and an MPU-6050 6axis gyroscope + accelerometer to measure the attitude and heading of CHAD. The accelerometer was calibrated by using an Arduino program created by Luis Ródenas * . This program returns accelerometer and gyroscope offsets which are used as inputs in the Arduino programs. The magnetometer required a more difficult process of calibration because hard and soft iron effects need to be corrected. When the 3-axis data is displayed for a correctly calibrated magnetometer that returns normalized data, it should appear as a sphere centered at (0,0,0) as seen in fig. 6. The hard iron effects are created by external sources of constant magnetic fields that result in the centroid of the data being shifted. Soft iron effects are created by ferromagnetic materials (i.e. steel) that distort magnetic fields, resulting in the shape of the data to be skewed from spherical to ellipsoidal, as can be seen in the uncalibrated CHAD readings in fig. 6. Soft iron effects are typically negligible, which requires a much simpler calibration, but we found adding the magnetic shield ( § 2.2) resulted in non-negligible soft iron effects. It is important to calibrate the magnetometer after CHAD is completely built because the hard and soft iron effects change based on the relative position of the magnetometer relative to any sources of these effects. We also it * Available for download at: http://pastebin.com/pF82frZH is important not to use a steel turntable as this will introduce a soft iron effects that varies as it turns.
The raw magnetometer data, h, needs to be converted into calibrated data, H. To do this, we used an algorithm called MagCal † created by researchers the Position, Location, and Navigation (PLAN) Group at the University of Calgary. 5 This algorithm returns a bias offset (used to correct hard iron effects), as well as a matrix that can be used to correct scale factors (the diagonal elements used to correct magnitude) and skew (off-axis elements used to correct soft iron effects). The calibrated data is found by using the relationship After using MagCal to calculate b, and calculating the inverse of A, we used these parameters in the AHRS program. In terms of the matrix elements, the corrections are found by Once these corrections have been made ‡ , the data should appear similar to the calibrated data seen in fig. 6.

Tilt Compensation
A magnetometer that returns multiple axis data can be used to measure the direction of North. The simplest method would be to have a magnetometer flat on the horizontal plane and to read the horizontal magnetic fields components B hx and B hy . These can then be used to find the yaw by where ψ = 0 • when the x-axis of the magnetometer is pointing North and the y-axis is pointing East. However, if the magnetometer is not flat, tilt compensation needs to be used to measure an accurate heading. The basic idea behind tilt compensation is to use rotation matrices to de-rotate the 3-axis magnetometer readings in order to find the horizontal components, B hx and B hy . This is similar to the technique used in cell phones to find their orientation. 6 The attitude (pitch, θ, and roll, φ) of the magnetometer needs to be measured to perform this de-rotation.
We used the MPU-6050 for the AHRS because it has both an accelerometer and gyroscope. Initially we tried using just an accelerometer to find the attitude of a platform, but found they become inaccurate if they are accelerated, shaken, or rotated, which is impractical for a HAB payload. An accelerometer alone can not differentiate between acceleration due to gravity or from movement, so a gyroscope is needed to remove acceleration due to movement. The Arduino libraries for the MPU-6050 include a function that returns a 3-axis gravitational vector with components g x , g y , and g z with any motional acceleration removed. The libraries also include the yaw (relative to the initial position), pitch, and roll for the breakout component. However, those angles are found relative to the accelerometer's x, y, and z coordinates, but not necessarily for CHAD or the magnetometer. This limits the positions (and thus the design of CHAD) in which we can use this accelerometer in order to be able to accurately convert its heading to the heading of CHAD. Instead, we find the pitch and roll by using the 3-axis gravity vector of the accelerometer, then tilt compensate the magnetometer data to measure the yaw. We use the North East Down (NED) frame and compare to a directional vector chosen for CHAD where X is directed North, Y is directed East, and Z is directed down when φ = ψ = 0 • . We then define the heading of CHAD as the angle the projection of X onto the horizontal plane makes relative to North. The pitch (θ) is the angle that X makes from the horizontal and is limited to the range −90 • < θ < 90 • . The roll (φ) is the angle Y makes from the horizontal and is limited to the range −180 • < φ < 180 • . CHAD's directional vector rotates with it, and the accelerometer and magnetometer vectors need to be mapped onto it. We can use the notation that G is the gravitational vector that has the same coordinates as CHAD, and have the uncalibrated and calibrated magnetometer vectors, h and H, with the same coordinates as well.
The North East Down frame (NED) is shown in fig. 8, with the roll, pitch, and yaw directions shown. Looking at the AHRS shown in fig. 7 (which also shows the vector directions for the breakout components), X is to the right, Y is coming out, Z is down. Using that notation, it can be seen the vector components for the accelerometer and magnetometer are as shown in fig. 8. Thus, for the accelerometer, G x = −g y , G y = −g z , and G z = −g x . For the magnetometer, h x = −b y , h y = b z , and h z = −b x . These solutions depend on the orientation of the accelerometer and magnetometer relative to the coordinates chosen for CHAD.
For a body that rotates with a certain roll, pitch, and yaw, the rotation matrices are found by If the accelerometer has rotated with a certain pitch and roll (yaw doesn't affect the measurement of gravity), it should measure gravity, g, as found by the relationship This means the gravity vector can be found by using the inverse of the pitch and roll angles to de-rotate the accelerometer readings: This results in three relationships: Solving equation 7b for φ gives: Solving equation 7a for θ gives: Similarly, we can de-rotate the pitch and roll of the magnetometer readings to find the horizontal components: Using the first two rows of the matrices, we can thus find the horizontal components of Earth's magnetic field by Once the horizontal components have been calculated, they can be used to find the yaw by using eq. (3).

HEADING CONTROL 4.1 Stepper Motor Control
For stepper motors, more steps per revolution would result in increased heading accuracy, and less of a jitter when changing position. There are also ways of increasing step resolution (i.e. interleave stepping) or smoothness (i.e. microstepping). However, we found that the jitter introduced into the GoPro video was easily removed by the video stabilization feature available on YouTube, so we kept the motor in double-coil mode to maximize the torque on the payload.
To make the stepper motor rotate (take a step), the applied voltage needs to switch to another coil winding inside the motor. There needs to be an active switch in a program that controls when the motor takes each step. To control the motor, we used the AccelStepper library created by Mike McCauley § . This library includes functions that control when the motor steps need to happen, and can include an acceleration when the rotational speed changes. However, in order for the step to take place, a function step() needs to be called in the Arduino program, which can limit the speed of the motor to the rate at which this function is called. This is in part why a second Arduino is used to control the motor, so that it uses little processing time for other functions.
For our test flight, our goal was to have the payload maintain a constant heading. That heading was chosen by its starting position because there is no active feedback as to what the payload heading is other than to compare it to its initial position.
We operate the stepper motor by telling it the number of steps it should take from its current position. There is no simple relationship between stepper motor position and heading angle because § Available for download at http://www.airspayce.com/mikem/arduino/AccelStepper/ the heading of CHAD (and thus the stepper motor) changes. Two measurements we can make are the heading of CHAD, θ C , from the AHRS, and the number of steps the stepper motor has moved its arm since the Arduino program began, N steps . We can use N steps to calculate the current position of the payload, θ cp , compared to its initial orientation relative to CHAD. (Note that while the position angles are in terms of motor steps in the Arduino program, we will discuss these angles in terms of degrees for simplicity and because different stepper motors can have different steps per revolution.) However, because the number of steps the motor has moved is a continuous count from its initial position, it will continue to increase (or decrease) after it has gone through full rotations. We can use a modulus to subtract out the integer number of full rotations (with N spr being the number of steps per rotation). For our motor, which moves 1.8 • per step, we can calculate θ cp by Note that this is not the direction in which the payload is facing, it is the relative angle between the payload and the initial heading of CHAD. As CHAD rotates, it needs to calculate how far to make the motor rotate the payload. As an example, if CHAD has rotated 90 • from its initial position, the motor should be at a position θ cp = −90 • in order for the payload to be at its initial position to maintain its heading. Because we are inputting how far the motor should rotate the payload, a simple (albeit incomplete, see § 4.2) correction can be made by The AHRS returns heading angles between -180 • and 180 • , while θ cp is a continuous count as the payload rotates. This creates a discontinuity in the relationship between the two parameters whenever CHAD's heading changes from southeast to southwest, or vice versa. To illustrate this, if CHAD is at a heading of 175 • (which means θ cp = −175 • ) and rotates by +10 • , the AHRS will return a heading of -175 • . This means the motor will be rotated by ∆θ = −(−175 • − 175 • ) = 350 • instead of -10 • . This would result in the motor turning the wrong direction, essentially taking the long way around to get to the desired heading. This means a correction needs to be made if |∆θ| > 180 • by adding or subtracting 360 • so that −180 • ≤ ∆θ < 180 • .

Payload Drift
CHAD does not position the payload instantaneously, and only reacts after the payload has moved with CHAD. By the time the motor has rotated the payload to the desired heading based on the calculated ∆θ, the angle θ C will have changed. This results in the payload drifting away from the desired heading in the direction in which CHAD is rotating. As CHAD rotates faster, this discrepancy increases. We found this problem could be fixed by adding a correction that is proportional to the angular speed of CHAD: We are effectively aiming the payload beyond the desired heading, and the drift problem results in the payload being at the desired heading. The constant κ was found experimentally by testing a range of values.
We used the AHRS to measure θ C and ω C , and use serial communication to transmit these values to the motor controller. In the lab, we found that sending these values at a rate of 10Hz was sufficient for maintaining control without limiting the motor speed due to the motor controller reading in the serial information.

PERFORMANCE
We flew CHAD on a HAB flight on October 30, 2015 with a GoPro camera ¶ to test its in-flight performance without any further stability control. The raw footage is jittery due to the stepper motor having a 1.8 • step −1 resolution, but this was removed by using video stabilization available for free on YouTube. We found that CHAD was able to correct the heading with rotation speeds seen reaching as high as ≈ 1rev/s, although the rotation speed of the platform would typically peak at ≈ 0.5rev/s. The video showed most movement when the payload was jostled by wind as CHAD does not react fast enough to correct for sudden changes in rotation speed. The strong jostling decreased with altitude, happening only periodically above about 3,000ft. After the jostling decreased, the main source of movement was due to the pendulum motion of the payloads as CHAD only corrects for changes in heading. This movement was also more apparent because the GoPro camera was tilted at a 45 • angle, so a change in attitude also appeared as a change in heading. A passive stability platform could help reduce changes in attitude so that CHAD only needs to correct for the heading. The fix for the payload drift problem also seemed to work as there didn't appear to be any correlation between heading change and a change in payload rotation speed.
The MPU-6050 is rated for temperatures down to −40 • C, while temperatures can go lower during a HAB flight. We found the gravitational measurements do become erratic at the low temperatures, so it is necessary to properly insulate the electronics. For our flight, we used the wrong grease for the turntable, which hardened when temperatures became low. Due to this, CHAD lost ability to turn the GoPro, so we are not sure how it performs at high altitudes using the electronics at low temperatures. The GoPro video stopped during the ascent, so we are also not sure about the performance during the descent.