Can Neural Networks Fly?

For centuries people have been staring at the stars. Is that possible for modern tools like neural networks bring us closer to a full-fledged space era?

Elena Margatskaya
The Startup
13 min readNov 7, 2020

--

Photo by Greg Rakozy on Unsplash

We might have a vast number of reasons to create a self-driving spacecraft that can land gracefully on some cosmos object surface. For instance, it`s supposed that investigation of asteroids might cast light on the life origin at our planet. Besides, a future generation might come up with an idea to utilize asteroids as an alternative source of minerals. Apart from this, one day the Armageddon film scenario might come true, and we will need to explode an asteroid to save our lives. By the way, could it be possible for Bruce Willis’s character to survive in that film? If only they had managed to deliver an explosive payload on the asteroid remotely for changing its trajectory, it would have been a total happy end without any sacrifice. Anyway, whatsoever the aim of the flight to a small space object is, it has undeniable outlooks.

The landing problem

It turned out to be a real challenge when we endeavor to land on a relatively small object like an asteroid that not only has its own velocity but also doesn’t generate strong enough a gravitational field which is moreover usually nonlinear. As a result, when you try to land gravitation doesn’t help, and if you control the spacecraft too aggressively, it might just bounce from the asteroid surface. So such a delicate mission like landing or delivering the payload on asteroids demands to be highly accurate. This point brings us to a soft landing problem that is called “soft” because its main goal is preventing significant damage or destruction of a spacecraft.

How would you actually provide the soft landing?

Most satellites have simple reliable chemical thrusters. One of them utilizes chemical-reaction monopropellants. On one hand, they are not as efficient as some other propulsion technologies. Though on the other hand, engineers choose monopropellant systems when the need for simplicity and reliability outweigh the need for high delivered impulse. If the propulsion system must produce large amounts of thrust or have a high specific impulse as for an interplanetary spacecraft, other technologies are used.

Therefore, we suppose that using monopropellant chemical thrusters is good enough for our spacecraft which is expected to land on an asteroid. Here again not everything as good as we would like it to be as chemical engines have only two states of acting: either being switched on or being switched off or to be specific, they are working in a relay mode. Let’s figure out what this relay mode means for the soft landing.

In space, any additional impulse, even very tiny, will result in a change of the trajectory, and it might take a lot of effort and fuel to get back on track. Just imagine that you need to park a car with no gas pedal available, so you cannot control the speed in a traditional way. You only have a button — while you are pressing it the car is moving forward with some acceleration. Add here the absence of air and tire resistance and the inability of using a brake pedal to stop immediately. Doesn’t this seem an easy task, right? Moreover, let’s assume that if you don’t succeed, the next trial will cost you a half fuel tank or so. Now it doesn’t seem easy at all among all these restrictions. At this point, we are forced to conclude that in some sense it’s a pretty risky and expensive intention.

Coming back to the landing problem it means that the golden middle is finding the right moments of engine activating to achieve a given velocity near the surface which is supposed to be about 2 meters per second or less if we want it to be “soft”.

Several numerical approaches allow us to solve the given problem and provide a soft landing. While I was reading one of them it just stroke me: what if a neural network can be trained for doing the same or maybe even better. What if we can just show to a network an example of how we assume to land and it will be good enough to generalize the training result for performing the soft landing in different conditions, i.e. initial velocity, distance to the asteroid, and something along these lines. It`s like to take Michael Schumacher`s driving style from several tracks which he won and teach a neural network to drive the same way. So the idea looked to be pretty appealing and I decided to check it on the soft landing task.

Training data mining

The first problem — Michael Schumacher has never landed on an asteroid. So I was needed to find some training data for my network. I was trying several basic concepts, that worked fine by the way, when I came up with the idea of using Pontryagin`s maximum principle.

It is a well-known approach in optimal control theory that was formulated in 1956 and has a strong mathematical basis. This principle is especially vital in systems providing either a maximum speed or a fuel-saving mode where it is tended to be used a relay type of control. It says for itself that its initial application was the maximization of a rocket terminal speed. Returning to our car park task it means that now we can find the right moment for pressing on the button with two options like to park as soon as possible or save as much fuel as possible.

For starters we can describe the spacecraft dynamic in the simplest way: dH/dt = V, dV/dt = F/m, where H — a distance to the asteroid, V — spacecraft speed, m — spacecraft mass, F — here force produced by the engine to move on the spacecraft. We also assume that spacecraft mass doesn’t change during the flight (though it’s not true as we consume fuel), spacecraft angular position is stabilized, all parameters and coordinates are measured without interference. It seems to be naive but we really can do that to test our hypothesis. Then after several mathematical manipulations we get two pretty simple rules of switching the spacecraft engine within the task of maximum speed. One rule is reliable for generating maximum engine force at the forward direction +Fmax and another rule for generating maximum engine force at the backward direction -Fmax though physically we understand that it will need two separate engines — one for the forward movement and another for backward one because a chemical thruster can not work at a reverse regime.

Now to be closer to reality let’s say that our spacecraft mass equals 300 kg, the initial distance between the asteroid and spacecraft is 100 km, initial spacecraft speed is 0 m/s and we have an engine producing 100 N force on board. In other words, it should be something like that:

In this case, Pontryagin`s maximum principle gives us the following solution:

As we can see the engine switches on from the very beginning till the moment the spacecraft reaches the speed of 180 m/s, then it triggers to backward force -100 N, and at the time 1100 sec the touchdown’s completed:

For the fuel-saving case we will have three conditions of switching the spacecraft engine so that we have not only +Fmax and -Fmax but also F = 0, i.e. the engine is switched off mode. As you can guess it will take bags of time to get to the asteroid (please note that an example below is shown in relative units):

Well, we might conclude that Pontryagin`s maximum principle is a powerful tool for providing a spacecraft landing but the stumbling block here is its numerical nature which means that the result is highly dependant on the initial state. For instance, if the spacecraft mass or velocity or whatsoever is turned out to be different from expected, you will need to recalculate the control signal. As we talk about different initial spacecraft states we should also consider that for example force producing by the engine might vary from 100 N say up to +- 20 % and for a numerical approach it would be the worst-case scenario.

Now assume that we take the maximization speed option. Then for getting training data all that we need is to take a sample from 1100 sec flight duration with the time step 2 sec and build the data table with the spacecraft speed, the distance to the asteroid, and the engine force values. It`ll be like that:

For a neural network training it means that we take information about the current spacecraft velocity and the distance to the asteroid as inputs and want to get a reliable output signal i.e. force value, or in reality, it would be a signal for switching engines.

How it works

Now it`s time to build a neural network that is able to approximate every given pair of input/output from our table, and hopefully it will be stable in case of different possible initial spacecraft state.

When it comes to neural networks it`s used to describe them as computing systems inspired by the biological neural networks in a sense that they receive some input signals which pass through neurons and give some output respond. However, we should realize that it’s based on mathematical theory and might be described with ordinary equations.

The first and simplest type of an artificial neural network was a feed-forward neural network that might be presented with the following picture:

Here x1, x2 — inputs (i.e. information about current spacecraft velocity and distance to the object), w and b — parameters of the hidden layers (layers located between the input x and output y), a[1] — nodes of the first hidden layer, a[2] — nodes of the second hidden layer, symbols [1] and [2] denote the order number of the first and the second hidden layer respectively.

We can see here that all inputs are connected with all nodes a1…a4 in the first hidden layer that in their turn are connected with all nodes in the second hidden layer. Because of that, it’s called a fully-connected neural network. Nodes, along with a neural network, came from a simplification of neurons in a brain so they are per se just pretty simple equations. For each layer we may write:

In all the presented equations for nodes we see the symbol “z” which denotes an auxiliary variable and “g” that is an activation function defining the output of a node depending on its input. For better understanding we might have a look at the simplest activation function — “step function”:

Its output will be 0 when the input or “z” (according to equations above) is <0 and the output will be 1 when z>0.In our set of equations we implemented a “sigmoid activation function” that looks similar to the previous one but gives us more flexibility:

In our set of equations we implemented a “sigmoid activation function” that looks similar to the previous one but gives us more flexibility:

What`s more, all connections in the network has its own weight “w” that defines the contribution, or we might say the influence, to each node from each input. To make it fall into place all that we need is to tune these weights and biases “b”, or in other words, to train the neural network to get a desirable output signal. Mathematically it means that we need to minimize some cost function so that it will reproduce an output for the given inputs as closer to the training set as possible. For this purpose we might use a widespread algorithm that’s called backpropagation and computes a gradient of the loss function concerning the weights of the network for a single input-output example.

I shall note that these are just some basic concepts underlying neural networks area and we won’t go deeply into computation explaining as it’s impossible to deal with all the issues in the article.

Nowadays there are many types of neural networks that differ from each other in structure and computation complexity so that the type and amount of your input data define the type of a neural network. Due to having a relatively small amount of training data, low space dimension of two input variables and one output we might implement a simple feed-forward neural network as it won’t be computationally consuming at the given task.

Feeding training data to neural network

Let’s try to train the feed-forward neural network with the following configuration (was chosen by the rule of thumb) that contains two hidden layers with 25 and 2 neurons respectively, a sigmoid activation function and a backpropagation training algorithm. There is a variety of tools that provide operations with neural networks such as Tensorlow, Keras, Kafe, etc. For the described landing task I used the Matlab Neural Network tool as it could be easily applied for the spacecraft flight simulation and turned out to be capable to handle my training data. In addition, one more advantage of implementing the NN Matlab tool is its user-friendly interface where you can build some neural network without having deep programming skills.

The result of training the neural network with the described configuration is presented below:

As was expected, it’s up and running at miming the training data (see the picture that gave us Pontryagin`s maximum principle for speed maximization) and now it’s the time to test this idea on more real conditions.

Mindset evolution or putting it all together

This result brings me to the idea of organizing some near-real scenario based upon my own inferences. Let`s imagine that our spacecraft is 100 kilometers away from the asteroid. So we need to get closer, for example to 10 kilometers using 100 N thruster, then we fly up to 1 kilometer using another 4 N thruster to be able to scan the asteroid surface, find an appropriate place on it and finally provide the soft landing there.

According to the presented scenario I built three sets of training data for each sub-task based on Pontryagin`s maximum principle and trained three neural networks separately that are supposed to work out depending on the distance to the asteroid. The spacecraft with angular stability control and the asteroid I described as objects with 6 degrees of freedom (6 DOF).

A further short video shows the result of the given simulation scenario:

It`s definitely looking up though has some flaws as hopping force with multiple commutations in the middle of the flight, but it can be eliminated with more careful neural network training.

Now it’s crash-test time to size the outcome up and check its ability to handle unexpected conditions like deviation of expected force value or initial position variation that we’ve discussed earlier. To be honest I counted for the well-known neural network ability to approximate practically any function but I didn’t hope it would be so effective, I even might say too good to be true. What I’ve tried to challenge my neural network:

1. Different initial spacecraft velocity: 0 m/s, 50 m/s, 100 m/s

2. Different initial spacecraft position

3. Different initial spacecraft mass: 200 kg, 300 kg, 400 kg

4. The case when the spacecraft and an asteroid are moving towards each other

5. Different impulse value producing with a thruster like 80 N and 120 N

The result was overwhelming in each experiment, the neural networks system provide the soft landing for all of the five cases described above.

To illustrate this, here are some graphics for the first case with different initial velocity:

As you can see the flight trajectory practically doesn’t change no matter what the initial velocity is. It turns out that the neural network tends to provide such trajectory as one for that it was trained to. On closer inspection we see that such optimality achieves every time due to a specific output signal, in fact, the spacecraft force graphics are quite different on all three pictures. Eventually, the system appears to be invariant to different conditions because the neural network produces suitable output to trajectory stays optimal.

“Everything you can imagine is real”. — P.Picasso

Despite all assumptions that we`ve made, this toy example finally shows that neural networks really can fly, or at least they have a chance to compete with classical control systems. Who knows probably the George Lucas` Star Wars era is much closer than we are thinking. Isn`t it inspired? As for me, this awesome experience forced me to begin my year and a half journey deep into machine learning and neural networks area. That`s a great new world with vast opportunities even such odd like the spacecraft soft landing on the asteroid.

This experiment has taught me that you shouldn’t be afraid of trying your ideas, even though if it seems like “No way, it`s never going to work”. Pablo Picasso was right when he once said “Everything you can imagine is real”.

Please let me know if you have any feedback.

--

--