Arduino rocket on a 3D printer – learning to land rockets at home

Good afternoon everyone, today I would like to share my experience in designing a rocket with thrust vector control. It so happened that I sat at home for a long time and decided to buy a 3D printer, and of course the first thing that I decided to print was a model of a “Trampoline-M” rocket, which can also be landed with a wireless flamethrower sword.

A rocket and a flamethrower sword (which "not a sword" and "not flamethrower")
Rocket and sword-flamethrower (which is “not a sword” and “not a flamethrower”)

Have I done rockets before? Never!!! Well, the truth is in one of my iOS games on the self-written Objective-C engine “Minimal Man” – you can shoot rockets from a rocket launcher, for example, rob a store by firing a rocket at a seller. In the game, all missiles explode.

App Store game Minimal Man
App Store game Minimal Man

I chose the Creality Ender-5 3D printer, but the Creality Ender-5 Pro version with quiet drivers is now available. My stepper motor drivers squeaked when printing, but I bought an updated board from Aliexpress and manually pumped the printer to the “Pro” version. Now it works silently.

Creality Ender-5 Pro
Creality Ender-5 Pro

Oh, the first thing I print in my life – and already a rocket that I want to land !!! Well, let’s launch the SketchUP program and design a 3D model.

SketchUP 3D model
SketchUP 3D model

According to my idea, all the details of the rocket should be printed on a 3D printer, including the levers of the servomotors, assembled with a screwdriver, without the use of glue, wires or other parts, like a regular constructor. For the frame, I bought a pack of aluminum tubes with a diameter of 6mm, but of course in the future I want to replace them with lighter plastic from the CNC machine.

"Three ring system"
“Three-ring system”

As you can see on the 3D model of the lower part of the rocket – for the thrust vector deflection, I use the cheapest SG90 servomotors from Aliexpress, which, of course, it is desirable to replace with more elite ones. I ordered expensive analogs of these servomotors from the HobbyKing website – but unfortunately they were never delivered to me, they returned the money. Now I’m still looking for high-quality servos, if you can advise anything, write it down in the comments, I will be very glad to the advice.

Trying to print a 3D model of the lower part of the rocket, which I call the “Three Rings System” or “Engine Nagibator”

Mobile app "Rocket"
Raketa mobile application

Naturally, I made the Rocket mobile application to control the rocket via iPad, iPhone, from a PlayStaton joystick or any other bluetooth button, connected the servomotors and tested everything. Despite the fact that I print for the first time, it was very easy to print everything, and in just a few minutes I was able to assemble the test model with a screwdriver. I highly recommend the Xiaomi rechargeable screwdriver, it was very pleasant to assemble with it, the details are assembled simply like a designer.

I immediately printed adapters for different types of motors, including solid state.

Solid rocket engine
Solid rocket engine

Then I hooked up the coaxial motors to the “three rings” deflection system through cheap Chinese 30A brushless motor ESCs and tested the iPad and joystick thrust and made sure there was thrust.

Motor test
Motor test

We assemble our model with a screwdriver, fasten the holders for the Arduino Nano and the battery.

The assembly was successful, it remains to download the firmware
The assembly was successful, it remains to download the firmware

Why did I decide to do everything on the Italian Arduino microcontroller, and even on the Arduino Nano version? The thing is that many developers of drones and copters from Russia in all their articles write that you do not need to develop a flight controller yourself, you need to buy ready-made ones. Let me remind you that the flight controller is the so-called “brains” of the device, that is, in other words, everyone is advised to buy ready-made “brains” (foreign production).

Well, well, well, that is, everyone thinks that developing your own flight controller “from scratch” is very difficult. From the arguments – “it is difficult to implement a PID controller there”. In general, in order to find out what the difficulty is, I decided to start with the Arduino board, after all, this is my hobby – building a rocket, why not try it on Arduino. If its power is not enough, I can replace it with a more powerful board. If you know which board it can be replaced with, please advise something suitable in the comments.

What is a PID regulator and why are they so afraid? The proportional-integral-differentiating (PID) controller, according to Wikipedia, has only one purpose – to maintain a given value r some value y by changing another value u

Let’s see the formula:

PID controller
PID controller

So, well, yes, apparently the integral in the formula looks quite frightening, flashbacks from lectures on mathematical analysis come to mind right away, when you rewrite squiggles from the board at speed, at first delving into it, but at some point you just let go of all thoughts and redraw everything from the board, like hieroglyphs, hoping you can figure it out later.

But the fact is that there are many ready-made implementations of the PID controller classes on the Internet, which look just like a ready-made function, to which you pass the deflection of the rocket and it simply returns the angle by which you need to turn the rocket! Just!

So, let’s define two parameters of our rocket, the numbers “input_x” and “input_y”:

«input_x» - отклонение ракеты влево-вправо от вертикального положения

«input_y» - отклонение ракеты взад-вперед от вертикального положения

If “input_x” is greater than zero, then the rocket has tilted to the right by “input_x” degrees, if it is less than zero, then the rocket has been deflected to the left. The same goes for “input_y”. This means that if “input_x” and “input_y” are zero, the rocket is standing vertically.

These values ​​are obtained from the IMU sensor using the IMU.readAcceleration function, which is already built into my version of the Arduino Nano (also my Arduino Nano already has a built-in barometer to determine the altitude, a temperature sensor, a bluetooth module, a microphone and other sensors. And that’s all this is on a tiny board):

IMU.readAcceleration(input_z, input_x, input_y);

Now that we have the missile deflection values, we can initialize the PID controller:

double P = 1.0, I = 0.05, D = 0.03;

double refresh_time = 10;

PID xPID(P, I, D, refresh_time);

PID yPID(P, I, D, refresh_time);

xPID.setpoint = 0; // Ноль - для вертикальной стабилизации по оси X

yPID.setpoint = 0; // Ноль - для вертикальной стабилизации по оси Y

When creating a PID controller, three numbers are needed:

P – Proportional component

I – Integrating component

D – Differentiating component

refresh_time is the interval at which we will poll our PID controller and get a value for the servo motor, for example, once every 10 milliseconds.

These coefficients are selected manually or using a special PIDtuner library at the stand, I will try to explain a little what these coefficients affect:

P – Proportional component to obtain an output signal that counteracts the deviation of the controlled value from the specified value (in our case, zero), observed at a given time. Suppose we set the coefficient P = 1, then when the rocket deflects to the right by 15 degrees, the servo motor will deflect the motor in the opposite direction by 15 degrees so that the rocket can restore its vertical position. If we set the coefficient to the value P = 2, then when the rocket deflects by 15 degrees, the servo motor would deflect the thrust vector by 30 degrees in the opposite direction.

I – Integrating component, the coefficient due to which the rocket “sausage left-right” less while it tries to stabilize in a vertical position. A coefficient that tries to extinguish the wave of left-right deviations as quickly as possible.

D – Differentiating component, a coefficient that predicts that while the rocket is sausage “left-right” it can be skidded by inertia, that is, this coefficient allows the rocket to be decelerated before it takes a vertical position, that is, to avoid the rocket drifting. Drift coefficient, that’s what I call it.

Naturally, I gave these descriptions of these coefficients in my simplified interpretation, you can read more on Wikipedia yourself. In a real project, of course, there are many nuances, for example, because of the “I” value inside the PID controller function, an integral error accumulates, which must be reset to zero before starting, or the error must be stored in an array of numbers and deleted old values ​​using the FIFO method (English first in, first out – “first came – first left”), but these are all experimental functions, for a general understanding, you can not think about it yet.

We figured out the coefficients, it’s just three numbersthat we are trying to pick up, nothing complicated.

Now every 10 milliseconds we need to get the value for the rejection of the servos “output_x” and “output_y”:

// Получение значений отклонения для сервомоторов из PID-регулятора:

xPID.input = input_x;

yPID.input = input_y;

output_x = xPID.getResultTimer();

output_y = yPID.getResultTimer();

At this stage, we have the values “Output_x” and “Output_y” – turn our servos to this value.

Everything!!! So easy, just fun !!! Of course, in a real project, I also filtered the values ​​from the accelerometer through the Kalman filter in order to eliminate noise in the graph, but even without filters, fairly accurate deviation values ​​come from modern accelerometers, and some IMU sensors already contain a built-in Kalman filter.

In order to get the values ​​of P, I, D coefficients automatically, I printed out a test bench on which the rocket can rotate freely, then connected the PIDtuner library, launched it, the rocket swayed a little back and forth, and at the output of PIDtuner I got the coefficients in the log:

double P = 0.55, I = 0.05, D = 0.03;

Test bench for calculating PID coefficients
Test bench for calculating PID coefficients

Now we enter these coefficients into the mobile application and try to launch the rocket

Test run at home
Test run at home

The first launch showed that there really was a thrust, the rocket was capable of flying, but I still launched the rocket in the room, so I really didn’t want to break it, I didn’t press the trigger with full force. Also, apparently, you need to more carefully select the PID coefficients, having watched the launch video, you will notice that the rocket still falls a little.

I recorded the assembly of the rocket on video (link below), the video shows that the rocket spins a little clockwise in flight, it’s all about the Chinese motor regulators, which spin one motor a little faster than the other. But nothing, in the next updates I will try to replace the regulators or add another PID regulator for “turns” – and if the rocket starts to spin, you can try using the value from the PID regulator to lower the speed of the motor, which is spinning faster than the other.

In theory – you can attach a wing to this rocket – and try to land the rocket horizontally. Or attach a balloon with hydrogen – and you get an airship with thrust vector control. Well, either you can try instead of electric motors to try to design a rocket on a turbojet thrust (there are good engines for sale for jet aircraft models), although you will have to move to the garage.

You can watch the full assembly video at the link:

I also quickly recorded a video about the assembly of the “wireless sword-flamethrower”, you can also find this video on the YouTube channel:

https://www.youtube.com/c/MaximGeymdev

And in general, I wrote this article to find like-minded people, if you are also fond of robotics or drone development, throw off your projects in the comments or write what you would like to see in the next posts.

Thanks a lot in advance for the feedback and criticism 🙂

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *