Wednesday, September 18, 2019

Opening the Space Box

Recently, I solved the high-value problem posed by Lockheed Martin's Space Box Challenge at my university. I was not prepared for what came next.

What is the Space Box?

Physically, it is a big, shiny, black box that looks like it came from a science fiction movie. The purpose of the box is to give university students a chance to demonstrate their problem-solving abilities. To get inside, you must solve one of four problems. There are three questions that are challenging, but they can be solved relatively easily with some thought and a little bit of math. Those three questions change daily for the three days the box was on campus. Upon solving a problem correctly, participants are rewarded by getting to go inside the box to view a cool space animation that surrounds you on all sides. Upon exiting the box, problem solvers receive a replica of the albums sent into space on the Voyager spacecraft. The fourth question, however, was much more difficult to solve than the other three. The reward was also much more substantial: A job offer from Lockheed Martin.

Opening the Box

As I mentioned, I solved the high-value problem, and I have since been offered a position working for Lockheed Martin. I am still in disbelief as I think about it right now. Many, many thanks to Lockheed Martin for bringing this challenge to my university and giving me this amazing opportunity. I am excited about the future.


The Problem and Solution

Many people have been asking me about the problem I solved and how I solved it. I usually just answer, "with some math." For the more curious, here is the problem I solved:



Right away, this problem looks very intimidating. It seems to combine aspects of orbital mechanics and electromagnetism into a single problem. However, after you start to look at the problem more closely, it is only asking us to find a relationship between two reference frames. So let's look at how to tackle this problem.

The problem basically defines a magnetic reference frame, and then asks us to find an expression for the angle at which the angular rate of rotation of the magnetic reference frame is double the orbital rate of the satellite (read: angular velocity).

The only outside information needed to solve this problem is a dipole model of the Earth's magnetic field, which can be found in multiple forms across the internet, including Wikipedia. Because the expressions get quite long - and because I am lazy - I use the following shorthand:
\[s_\alpha=\sin\left(\alpha\right)\]
\[c_\alpha=\cos\left(\alpha\right)\]
Since the problem uses a reference angle measured from the equator, this is the form we want.
\[B_r=-\frac{2 B_0}{R^3}s_\alpha\]
\[B_\theta = \frac{B_0}{R^3}c_\alpha\]
\[|B| = \frac{B_0}{R^3} \sqrt{1+3s_\alpha^2}\]
where \(R\) is the distance from the center of the orbit divided by the radius of Earth. Note that these equations define a polar coordinate system which depends on the angular position within the orbit and both \(B_0\) and \(R\), neither of which are given. As it turns out, we don't need those values to solve the problem. I will define a set of unit vectors fixed on the satellite body, with \(\hat{e}_r\) pointing radially outward from the orbit and \(\hat{e}_\theta\) pointing along the trajectory of the satellite. The magnetic field is then given by
\[\vec{B} = \frac{B_0}{R^3}\left(-2s_\alpha \hat{e}_r + c_\alpha \hat{e}_\theta\right)\]
Using the given definition of the magnetic reference frame, we can compute the unit vector
\[\hat{x}_{mz} = \frac{\vec{B}}{|\vec{B}|} = \frac{-2s_\alpha}{\sqrt{1+3s_\alpha^2}}\hat{e}_r + \frac{c_\alpha}{\sqrt{1+3s_\alpha^2}}\hat{e}_\theta\]
We could calculate the others unit vectors also, but there is no need. We only need one unit vector to compute the angle of the reference frame with respect to the inertial reference frame. We need to express everything in terms of an inertial reference frame, because that is the reference frame in which the angular velocity of the satellite is defined. If we define the inertial frame with \(\hat{x}_1\) pointing to the right and \(\hat{x}_2\) pointing up, then we can write 
\[\hat{e}_r = c_\alpha \hat{x}_1 + s_\alpha \hat{x}_2 \]
\[\hat{e}_\theta = -s_\alpha \hat{x}_1 + c_\alpha \hat{x}_2 \]
Substitution into the equation above (and a little bit of algebra) gives
\[\hat{x}_{mz} = \left(\frac{-3s_\alpha c_\alpha}{\sqrt{1+3s_\alpha^2}}\right)\hat{x}_1 + \left(\frac{-2s_\alpha^2+c_\alpha^2}{\sqrt{1+3s_\alpha^2}}\right)\hat{x}_2\]
Ultimately, we need an expression of the angle between the magnetic reference frame and the inertial reference frame so we can take a derivative. To get this angle, we simply take a dot product. Defining \(\beta\) as the positive angle between \(\hat{x}_1\) and \(\hat{x}_{mz}\),
\[ \cos(\beta) = \hat{x}_{mz} \cdot \hat{x}_1 = \frac{-3s_\alpha c_\alpha}{\sqrt{1+3s_\alpha^2}} \]
Take the inverse cosine, and we get
\[ \beta = \cos^{-1}\left(\frac{-3s_\alpha c_\alpha}{\sqrt{1+3s_\alpha^2}}\right) \]
Now we have our expression of the angle of the magnetic reference frame. All that's left to do is take a derivative. I used Wolfram Alpha for help with this, although it can be done by hand with a fair amount of patience.
\[\dot{\beta} = \frac{-3\dot{\alpha}\left(3 s_\alpha^4 + s_\alpha^2 - c_\alpha^2 \right)}{\left(3s_\alpha^2+1\right)\sqrt{3s_\alpha^2-9s_\alpha^2 c_\alpha^2 + 1}}\]
Note that \(\dot{\beta}=\omega_{mz}\) and \(\dot{\alpha} = \omega_0\), so what we have is an expression for \(\omega_{mz}\) in terms of \(\omega_0\). With some trigonometric identities and simplification, we get a slightly nicer expression.
\[\omega_{mz} = \frac{-3\left(\cos(2\alpha)-3\right)}{2\left(\sin^2(\alpha)+1\right)}\omega_0\]
The question asks for an expression for when the angular rate of rotation of the magnetic reference frame is exactly twice the orbit rate. In other words, when does that coefficient equal 2? There are a few ways to do this, but Wolfram Alpha again makes short work of the problem.
\[\frac{-3\left(\cos(2\alpha)-3\right)}{2\left(\sin^2(\alpha)+1\right)} = 2 \quad\textrm{when}\quad \alpha=\pi n \pm \frac{1}{2}\cos^{-1}\left(\frac{1}{3}\right) \quad\textrm{for}\quad\ n\in\mathbb{Z}\].
If you just need the first instance of the angle (which in this case also happens to be the magnitude angle from the horizon in all four quadrants) just take \(n=0\) and you get
\[\alpha = \frac{1}{2}\cos^{-1}\left(\frac{1}{3}\right)\]
That's it. It takes no more than a page or so of work, and it can be done in 30 minutes if you know what you are doing.

Wednesday, January 9, 2019

Teensy Trouble

In my Ph.D. studies, I have been doing a fair amount of embedded programming. My favorite microcontroller by far has been the aptly-named Teensy. These microcontrollers have some serious hardware at a very reasonable price. They are also incredibly easy to program due to the fact that they can be programmed with arduino code. I could go on and on about why I like them, but today I found a relatively minor issue that caused me a lot of trouble.

The Teensy 3.6 has many pins capable of reading analog voltages. The two pins I decided to use for my project are pins 32 (A13) and 35 (A16). I implemented the functionality using analogRead(13)  and analogRead(16), respectively. Interestingly, A13 worked as expected, but A16 did not.  Instead, it behaved like a floating pin, and even shorting that pin to ground had no impact on the reading (this should have been a clue, actually). It wasn't just A16, either. All analog pins numbered A14 or higher were not working, while all numbered A13 or lower were working as expected.

After much frustration and much investigation, I found the answer. Since analogRead() can accept either analog pin numbers or actual pin numbers as its argument, numbers over 14 are ambiguous to the code, so it assumes the argument is the actual pin number. To avoid this, you can either use the actual pin number or use the analog pin number preceded by "A" (i.e. A14, A15, etc.). This works because those are just macros to the actual pin numbers. In my case, using analogRead(A16) solved the problem.

Tuesday, September 27, 2016

Predicting Control Surface Hinge Moments using Computational Fluid Dynamics

My Master's thesis has finally been published! You can view my thesis here (faster) or on The University of Alabama Electronic Theses and Dissertations database. I started this research with absolutely no CFD experience. I am quite proud of the fact that I was able to learn enough that I am now considered by many to be an expert. When I look at how far I have come in the last three years, it truly amazes me. I never thought I would learn so much.

Thanks to everyone who supported me while I worked on this research, and thanks for your continued support as I continue in my studies.

Saturday, September 3, 2016

Rebuilding a Three-Channel Aircraft (Dionysus)

When I was a kid, I had a 3-channel Cub-like RC airplane. While in storage, the aircraft suffered some rather severe hangar rash. The damage was the result of the unexpected compression load applied to the fuselage due to poor visibility conditions. In other words, I stepped on the plane because it was dark.

Bringing It Back From The Dead

After I recently "retired" another aircraft when the wing incidence started varying mid-flight, I decided it was time to rebuild the old . The fuselage had been collapsed into itself, so I still had most of the broken pieces after all the years. This made reconstruction a great deal easier. Using copious amounts of wood glue and CA, and just a couple pieces of new balsa, the aircraft was ready for a new skin.

I opted to replace all of the skin because the old skin would no longer adhere to the balsa. I removed the existing skin and gave the airframe a new skin of Ultracote Lite (transparent yellow). I found that it is easy to work with, it adheres well, and it gives a very nice finish. The "Lite" version is substantially thinner than the normal stuff.

The completed repair of the fuselage damage.
This spot on the wing had also been damaged. The broken piece was glued back in place.


In addition to structural repairs, I decided that it was a good time to modernize the components. Gone are the 72 MHz receiver, brushed motor, gearbox, ESC, and NiMh (NiCd?) battery. I now have a Spektrum 2.4 GHz receiver, brushless motor and ESC, and a 3s LiPo battery.



I fabricated a motor mount to convert the aircraft from a brushed inrunner motor to a brushless outrunner. The entire motor mount assembly is attached to the airframe using a couple of cable ties through existing holes, so I can easily remove it if needed.  With this motor, the aircraft has much more power than it needs. The thrust-to-weight ratio is about 2, so it can climb vertically.





I also added a Mobius ActionCam to record video of my flights. I mounted the camera on the bottom of the fuselage, directly at the center of gravity. A piece of 1/8-inch birch plywood on the inside of the fuselage acts as a reinforcement plate, distributing the load to the balsa fuselage. The camera mount simply bolts onto the fuselage. You can see some footage recorded with this camera below and on my YouTube channel.


You can see the reinforcement plate for the camera at the bottom of the fuselage.


The total weight of the aircraft with battery and camera installed is 1 lb 15 oz. Because I used parts that I already had lying around, the total cost of the rebuild was about $5 plus my time. Overall, I am pleased with the quality of the rebuild.

Test Flight Footage and Observations

Of course, the point of undertaking this repair was to get the aircraft flying again. So early one morning, I took it to the soccer field for a test flight. It turns out that 8:00 AM is a good time to fly for a number of reasons. Not only is it the most convenient time for me, but also the soccer fields are not in use, the weather is usually calm, and the lighting is perfect for filming to the west.



The aircraft itself performs very well. Since the aircraft has no ailerons, it relies on the dihedral of the wing to produce a rolling moment with rudder deflection. I mapped the rudder to the aileron channel on my transmitter. The dynamic roll response is surprisingly fast. Truth be told, I only notice the lack of ailerons during slow flight.

With the salvaged parts I had on hand, the aircraft has much more power than it needs. I estimate the thrust-to-weight ratio to be about 2, so it can climb vertically with no problem. The recorded flight lasted 10 minutes, and the 3S 2200 mAh battery was still at 11.8 V at the end of the flight.

Having successfully resurrected the aircraft, it is only appropriate to give it a suitable name. I like to name things after mythological entities, and I think Dionysus fits pretty well given the story. I just hope I don't have to change the name to Osiris down the road.

Thursday, April 30, 2015

Temporal and Spatial Stability Analysis of the Orr-Sommerfeld Equation

This is the second and final part of the stability analysis of the Orr-Sommerfeld Equation. In my previous post, I went through the derivation and nondimensionalization of the Orr-Sommerfeld Equation. In this part, I show how to perform the temporal and spatial stability analyses.

Blasius Velocity Profile

A 2-D Blasius boundary layer can be expressed as
$$\bar{U}=f'\left(\eta\right)\tag{1}\label{blasius}$$
where
$$\begin{align}\eta=y\sqrt{\frac{U_{\infty}}{2\nu x}}\\f'''+ff''&=0\\f(0)=f'(0)&=0\\f'(\infty)&=1\end{align}$$
This is a nonlinear ordinary differential equation that is most easily solved using a shooting method. In a shooting method, the boundary value problem is made into an initial value problem, whereby an initial guess of one parameter is iteratively updated until the opposite boundary conditions are met. In the present case, the unknown boundary condition is \(f''(0)\) , so it is iteratively adjusted until \(|f'(10)-1|\leq10^{-6}\). The present case uses a fourth-order Runge-Kutta method of integration. The initial condition The transformation of the Blasius velocity profile from \(\eta\) to \(\xi\) is performed by determining the distance from the wall, \(\delta\), where the stream-wise velocity is \(99.9\%\) of the free-stream velocity.
$$\begin{align}\bar{U}\left(\xi\right)&=\bar{U}\left(\frac{\eta}{\delta}\right)\\\bar{U}''\left(\xi\right)&=\frac{1}{\delta^{2}}\bar{U}''\left(\frac{\eta}{\delta}\right)\end{align}\tag{2}\label{transform}$$
The figure below shows the Blasius velocity profile and its derivatives.


Temporal Stability

The Orr-Sommerfeld equation can be analyzed for temporal stability by assuming that \(\bar{\alpha}\) is real. This enables us to rearrange the non-dimensional Orr-Sommerfeld equation as follows.
$$\left(-\bar{U}\bar{\alpha}^{2}-U''+\frac{i\bar{\alpha}^{3}}{Re_{\delta}}\right)\bar{\phi}+\left(\bar{U}-\frac{2i\bar{\alpha}}{Re_{\delta}}\right)\bar{\phi}''+\left(\frac{i}{\bar{\alpha}Re_{\delta}}\right)\bar{\phi}''''=\bar{c}\left(\bar{\phi}''-\bar{\alpha}^{2}\bar{\phi}\right)\tag{3}\label{realalpha}$$
If we discretize this equation using a finite difference approximation for \(\bar{\phi}''\) and \(\bar{\phi}''''\), we get an equation of the form
$$A\Phi=\tilde{c}B\Phi\tag{4}\label{eigmatrixform}$$
where \(\Phi\) is a vector containing values \(\bar{\phi}_{i}\) at discrete locations. This is nothing more than an eigenvalue problem, where \(\tilde{c}\) is a diagonal matrix of eigenvalues for the discrete system. The present calculations use a second order central differencing scheme to approximate the second and fourth derivative terms.
$$\begin{align}\bar{\phi}_{i}''&\approx\frac{\bar{\phi}_{i-1}-2\bar{\phi}_{i}+\bar{\phi}_{i+1}}{h^{2}}\\\bar{\phi}_{i}''''&\approx\frac{\bar{\phi}_{i-2}-4\bar{\phi}_{i-1}+6\bar{\phi}_{i}-4\bar{\phi}_{i+1}+\bar{\phi}_{i+2}}{h^{4}}\end{align}\tag{5}\label{eqfindiff}$$
At the boundaries, \(\bar{\phi}=0\), so the first and last columns of \(A\) and \(B\) are removed. However, \(\bar{\phi}'=0\) also at the boundaries. Fortunately, using a backward difference method at the boundary gives \(\bar{\phi}_{-1}\approx\bar{\phi}_{0}\), so the \(\bar{\phi}_{i-2}\) term can be omitted from the \(\bar{\phi}''''\) approximation just inside the wall boundary. Similarly, the \(\bar{\phi}_{i+2}\) term can be omitted just inside the free-stream boundary.
The finite difference approximations in Equation \ref{eqfindiff} gives a pentadiagonal \(A\) and tridiagonal \(B\).
$$\begin{align}A&=\frac{1}{h^{4}}\left[\begin{array}{ccccc}a_{11} & a_{21} & a_{3} &  & 0\\a_{21} & \ddots & \ddots & \ddots\\a_{3} & \ddots & \ddots & \ddots & a_{3}\\ & \ddots & \ddots & \ddots & a_{2n}\\0 &  & a_{3} & a_{2n} & a_{1n}\end{array}\right]\\B&=\frac{1}{h^{2}}\left[\begin{array}{cccc}b_{1} & b_{2} &  & 0\\b_{2} & \ddots & \ddots\\ & \ddots & \ddots & b_{2}\\0 &  & b_{2} & b_{1}\end{array}\right]\end{align}\tag{6}\label{fdmatrix}$$
where
$$\begin{align}a_{1i}&=h^{4}\left(-\bar{U}_{i}\bar{\alpha}^{3}-\bar{U}_{i}''\bar{\alpha}+\frac{i\bar{\alpha}}{Re_{\delta}}\right)-2h^{2}\left(\bar{U}_{i}\bar{\alpha}-\frac{2i\bar{\alpha}}{Re_{\delta}}\right)+6\left(\frac{i}{Re_{\delta}}\right)\\a_{2i}&=h^{2}\left(\bar{U}_{i}\bar{\alpha}-\frac{2i\bar{\alpha}}{Re_{\delta}}\right)-4\left(\frac{i}{Re_{\delta}}\right)\\a_{3}&=\frac{i}{Re_{\delta}}\\b_{1}&=-h^{2}\bar{\alpha}^{3}-\bar{\alpha}\\b_{2}&=\bar{\alpha}\end{align}\tag{7}\label{fdmatrixcoef}$$
The coefficients in \(A\) depend on the velocity profile, which varies with the distance from the wall. However, \(B\) is constant for a given \(\bar{\alpha}\). In addition, \(B\) is guaranteed to be real and symmetric, and is thus guaranteed to be invertible. We can thus left multiply Equation \ref{eigmatrixform} by \(B^{-1}\) and rewrite the equation as follows.
$$B^{-1}A\Phi=B^{-1}\tilde{c}B\Phi\tag{8}\label{newmatform}$$
It is clear that the eigenvalues of \(B^{-1}A\) are the eigenvalues in \(\tilde{c}\). Matlab's eig function was used to solve for the eigenvalues for each combination of \(\bar{\alpha}\) and \(Re\). The following figure shows the eigenvalues of the discrete system using one value of \(\bar{\alpha}\) and \(Re\). Each combination of \(\bar{\alpha}\) and \(Re\) gives a unique set of eigenvalues similar to these.


Because this is a stability analysis, we only care about the most unstable eigenvalue. The governing equation is related to \(e^{i\alpha(x-\left(c_{r}+ic_{i}\right)t)}\). If \(\alpha\) is real, then any instabilities must come from an eigenvalue with a positive imaginary component. For this reason, the interesting eigenvalue is the eigenvalue with the maximum imaginary component. This analysis was done over a range of \(\bar{\alpha}\) and \(Re\), and the most unstable eigenvalue was stored for each combination. Matlab's contour function was then used to plot the contours shown in the following figure.


It is important to note that the contours shown here differ from those found by Wazzan in [7] because the Orr-Sommerfeld equation has been nondimensionalized in a different manner. The present case used the boundary layer thickness \(\delta\), while Wazzan used displacement thickness \(\delta^{*}\).

Spatial Stability

The temporal stability analysis is performed assuming that \(\bar{\alpha}\) is real. In the spatial stability analysis, we assume that \(\omega\) is real. It is possible to derive a polynomial eigenvalue problem for the eigenvalues \(\bar{\alpha}\), but solving the polynomial eigenvalue problem presented some challenges. Namely, at least one of the coefficient matrices was singular.


To circumvent this challenge, a mapping method has been used to give a relation between a complex \(\bar{\alpha}\) and a complex \(\omega\). In the present case, we hold \(\bar{\alpha}_{i}\) at a specific value and vary \(\bar{\alpha}_{r}\). For each \(\bar{\alpha}_{r}\), the discrete eigenvalue problem is solved for \(\omega\), and the most unstable eigenvalue is kept as before. By varying \(\bar{\alpha}_{r}\) with \(\bar{\alpha}_{i}\), a curve of \(\omega\) values can be plotted in the complex plane, as shown in the figure above. We then determine if there is an \(\bar{\alpha}_{r}\) that gives \(\omega_{i}=0\) and store any locations that satisfy this condition. This process is repeated for a range of \(Re\) for all interesting \(\bar{\alpha}_{i}\) values. The results of this process are shown in the figure below.


Discussion

This report is not the first on this topic, and the results do match fairly well with the references. Once the discretization was properly arranged, the eigenvalue computation was trivial using Matlab's built-in functions. Some factors added complexity to the project. The temporal stability curves are sensitive to the discretization step size and the number of \(Re\) and \(\bar{\alpha}\) values used. However, the spatial stability curves were far more sensitive. 

It turns out that an insufficient number of \(\bar{\alpha}_{r}\) values will give bad resolution in the complex \(\omega\) plane, periodically overestimating the zero locations. This caused some oscillations at larger values of \(Re\). Additionally, a large number of Reynold's Number steps were required to ensure that the each of the desired contours were visible.Compounding the issue was the fact that an extra variable effectively raised computation time by nearly an order of magnitude.

References

  1. J. D. Anderson. Fundamentals of Aerodynamics. Aeronautical and Aerospace Engineering Series. McGraw Hill, 4th edition, 2007.
  2. M. J. Maghrebi. Orr Sommerfeld Solver using Mapped Finite Di fference scheme for plane wake fl ow. Journal of Aerospace Science and Technology, 2(4):55-63, December 2005
  3. P. J. J. Moeleker. Linear Temporal Stability Analysis. Technical report, Delft University of Technology, 1998. Series 01: Aerodynamics 07.
  4. B. S. Ng and W. H. Reid. Simple Asymptotics for the Temporal Spectrum of an Orr-Sommerfeld Problem. Applied Mathematics Letters, 13:51-55, 2000.
  5. S. A. Orszag. Accurate Solution of the Orr-Sommerfeld Stability Equation. Technical report, Massachusetts Institute of Technology, May 1971.
  6. T. Patel. Stability Properties of Self-propelled Wakes. Master's Thesis, University of California, San Diego, 2012.
  7. A. R. Wazzan, T. T. Okamura, and A. M. O. Smith. Spatial and Temporal Stability Charts for the Falkner-Skan Boundary-layer Profiles. Technical report, Douglas Aircraft Company, 1968.
  8. F. M. White. Viscous Fluid Flow. McGraw-Hill Series in Mechanical Engineering. McGraw Hill, 2nd edition, 1991.

Matlab Codes

These are the Matlab files needed to perform this analysis. Please feel free to use them as you will, but please give me credit. A link to my blog is always appreciated.
Main Stability Analysis Code: cs_orr_sommerfeld_stability.m
Fourth Order Runge-Kutta Routine: cs_rk4.m