This post is about my experience developing a rocket flight controller. If you spot anything that’s off, please let me know.
P.S. I study chemical engineering, so the technologies I used here were outside my field. Some of my terminology may be off. I’d appreciate any corrections…
I’m a member of the Nebula Technology team, where I’ve been responsible for the flight controller. Our first prototype used an Arduino Uno and an MPU6050. Its servo controller was simple and the software had no parachute deployment routine.
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
x = a.acceleration.x;
y = a.acceleration.y;
z = a.acceleration.z;
Serial.print(x);Serial.print(" ");
Serial.println(y);Serial.print(" ");
Serial.println(z);Serial.print("\n");
if (x < 10 && x > 0 && y < 4 && y > -4){
Serial.println("up");
value = map(x, 0, 10, 0, 180);
servo1.write(value);
Serial.print(value);
}
else if (x > -10 && x < 0 && y < 4 && y > -4){ //2
Serial.println("down");
value = map(x, -10, 0, 180, 0);
servo1.write(180-value);
Serial.print(value);
}
if (y < 10 && y > 0 && x < 4 && x > -4){ //3
Serial.println("Right");
value = map(y, 0, 10, 0, 180);
servo4.write(180-value);
Serial.print(value);
}
else if (y > -10 && y < 0 && x < 4 && x > -4){
Serial.println("left");
value = map(y, -10, 0, 180, 0);
servo4.write(value);
Serial.print(value);
}
We released the code on the Nebula Technology website. It had quite a few problems, including servo jitter and overcorrection. I later revised the control software, and for the second iteration we switched from the Arduino Uno to a Seeeduino XIAO. The XIAO had fewer pins available for servo outputs, but it was smaller and had a more capable microcontroller than the ATmega328P.
In a later version, an unresolved issue sometimes caused the servo to lock up as the correction accumulated. I suspected the correction was increasing too quickly and going out of range.
float accx = ax / AcceRatio; //x轴加速度
float accy = ay / AcceRatio; //y轴加速度
float accz = az / AcceRatio; //z轴加速度
aax = atan(accy / accz) * (-180) / pi; //y轴对于z轴的夹角
aay = atan(accx / accz) * 180 / pi; //x轴对于z轴的夹角
aaz = atan(accz / accy) * 180 / pi; //z轴对于y轴的夹角
float gyrox = - (gx-gxo) / GyroRatio * dt; //x轴角速度
float gyroy = - (gy-gyo) / GyroRatio * dt; //y轴角速度
float gyroz = - (gz-gzo) / GyroRatio * dt; //z轴角速度
agx += gyrox; //x轴角速度积分
agy += gyroy; //y轴角速度积分
agz += gyroz;
if(agx > 0)
{
Serial.print("up ");
Serial.print(agx);
Serial.println("度");
sumerror_x += agx;
output_x = kp*agx + ki*sumerror_x + kd*(lasterror_x - agx);
lasterror_x = agx;
agx += output_x;
servo1.write(agx);
}
if(agx < 0)
{
Serial.print("down ");
Serial.print(agx);
Serial.println("度");
sumerror_x += agx;
output_x = kp*agx + ki*sumerror_x + kd*(lasterror_x - agx);
lasterror_x = agx;
agx += output_x;
servo1.write(agx);
//servo1.write(num2*(90-agx));
}
if(agy > 0)
{
Serial.print("left ");
Serial.print(agy);
Serial.println("度");
sumerror_y += agy;
output_y = kp*agy + ki*sumerror_y + kd*(lasterror_y - agy);
lasterror_y = agy;
agy += output_y;
servo2.write(agy);
}
if(agy < 0)
{
Serial.print("right ");
Serial.print(agy);
Serial.println("度");
sumerror_y += agy;
output_y = kp*agy + ki*sumerror_y + kd*(lasterror_y - agy);
lasterror_y = agy;
agy += output_y;
servo2.write(agy);
}
if(agx>70)//开伞角度,后面省略,免得文章太长
{
//digitalWrite(8,1);
servo_pin_2.write( 0 );
delay(2000);
}
The servo angle still jittered with the gyroscope level. The MPU6050 readings were fluctuating as well, so I suspected that sensor noise was making the servo jitter and tried filtering the readings.
aax_sum = 0; // 对于加速度计原始数据的滑动加权滤波算法
aay_sum = 0;
aaz_sum = 0;
for(int i=1;i<n_sample;i++)
{
aaxs[i-1] = aaxs[i];
aax_sum += aaxs[i] * i;
aays[i-1] = aays[i];
aay_sum += aays[i] * i;
aazs[i-1] = aazs[i];
aaz_sum += aazs[i] * i;
}
aaxs[n_sample-1] = aax;
aax_sum += aax * n_sample;
aax = (aax_sum / (11*n_sample/2.0)) * 9 / 7.0; //角度调幅至0-90°
aays[n_sample-1] = aay; //此处用实验取得合适的系数
aay_sum += aay * n_sample; //本例系数为9/7
aay = (aay_sum / (11*n_sample/2.0)) * 9 / 7.0;
aazs[n_sample-1] = aaz;
aaz_sum += aaz * n_sample;
aaz = (aaz_sum / (11*n_sample/2.0)) * 9 / 7.0;
float gyrox = - (gx-gxo) / GyroRatio * dt; //x轴角速度
float gyroy = - (gy-gyo) / GyroRatio * dt; //y轴角速度
float gyroz = - (gz-gzo) / GyroRatio * dt; //z轴角速度
agx += gyrox; //x轴角速度积分
agy += gyroy; //y轴角速度积分
agz += gyroz;
/* 卡尔曼滤波算法部分 */
Sx = 0; Rx = 0;
Sy = 0; Ry = 0;
Sz = 0; Rz = 0;
for(int i=1;i<10;i++)
{ //测量值平均值运算
a_x[i-1] = a_x[i]; //即加速度平均值
Sx += a_x[i];
a_y[i-1] = a_y[i];
Sy += a_y[i];
a_z[i-1] = a_z[i];
Sz += a_z[i];
}
a_x[9] = aax;
Sx += aax;
Sx /= 10; //x轴加速度平均值
a_y[9] = aay;
Sy += aay;
Sy /= 10; //y轴加速度平均值
a_z[9] = aaz;
Sz += aaz;
Sz /= 10;
for(int i=0;i<10;i++)
{
Rx += sq(a_x[i] - Sx);
Ry += sq(a_y[i] - Sy);
Rz += sq(a_z[i] - Sz);
}
Rx = Rx / 9; //得到方差
Ry = Ry / 9;
Rz = Rz / 9;
Px = Px + 0.0025;
Kx = Px / (Px + Rx); //计算卡尔曼增益
agx = agx + Kx * (aax - agx); //陀螺仪角度与加速度计速度叠加
Px = (1 - Kx) * Px; //更新p值
Py = Py + 0.0025;
Ky = Py / (Py + Ry);
agy = agy + Ky * (aay - agy);
Py = (1 - Ky) * Py;
Pz = Pz + 0.0025;
Kz = Pz / (Pz + Rz);
agz = agz + Kz * (aaz - agz);
Pz = (1 - Kz) * Pz;
I struggled to learn these algorithms. I hadn’t studied linear algebra at the time, and the code had all kinds of problems I didn’t know how to fix. The filter still had room for improvement, so please point out any mistakes you find.
For this hardware revision, I replaced the loose Dupont jumper wires with a simple PCB. At the time I suspected a supply-voltage mismatch on the particular MPU6050 module I had used. Some signal traces also looked too thin. Please let me know if you spot anything else I missed.

For the latest generation of the thrust-vectoring rocket, which we’re still working on, I designed a new PCB to replace the development board and 6050 module. It uses an ATmega328P as the main microcontroller and replaces the MPU6050 with a WitMotion JY901B. The JY901B has built-in filtering and a barometric altimeter, which saved me from rewriting the Kalman filter. This version added hardware self-tests, flight logging, GPS positioning, two-way Zigbee communication, and provision for a future staging feature. The PCB is shown below:

The two ribbon-cable connectors on the PCB connect it to the power board. I kept the controller and power boards separate to reduce the risk of excess current burning out the controller. The six-pin connector on the controller board is for GPS and Zigbee communications. The power board is shown below:

You’ll probably spot the large buzzer on the power PCB. It’s part of the startup self-test. If the checks pass, a MOSFET switches on the buzzer so it beeps.
While designing this PCB, I learned how important it is to handle analog and digital grounds carefully. My approach was to reference the analog supply to analog ground and the digital supply to digital ground, and to avoid referencing a different layer unless necessary. I also avoided routing traces across the analog and digital regions. For example, I kept analog ground out from under digital traces. I grouped analog and digital components separately and put the boundary through the A/D converter. I used an analog ground pour for analog signals and a single-point connection through an inductor or ferrite bead between the analog ground or supply and the digital supply.
I wrote up a few other lessons as well. Once I’ve finished the document, I’ll upload it to the forum.
For this iteration, I revised the attitude controller for the three Euler angles.
eng1a = Kp * (-anglex) + Kd * (-Gyrox);
I also learned how to detect and switch between phases of flight, from startup tests to descent and parachute recovery. I used two sensor-based checks to decide when to deploy the parachute.
case S_1ST_ENGINE_WORK: //第一级发动机工作, 为二级留冗余
{
if (acc_z==LAUNCH_ACC_Z)//开伞条件1:加速度反向
{
delay(3500);//惯性飞行时间
state_change(S_1ST_FALL, RECORD_LOG);
}
else if (judige_1st_angle(anglex, angley) == 2)//开伞条件2:判断XY轴合偏转角度
{
state_change(S_1ST_FALL, RECORD_LOG);
}
break;
}
If you know of better ways to decide when to deploy the parachute, I’d appreciate your advice. I want the recovery system to be as reliable as possible.
To make it easier to see the rocket’s attitude, I used the ANO flight-control ground station and its protocol to monitor attitude, altitude, and other data.
I ran into plenty of pitfalls during the build. Here are a few things I wish I’d known when I started working on rocket flight electronics:
1. Don’t use a development board’s 5V or 3.3V rail to power other components. My Seeeduino XIAO board above is an example of what can go wrong. A high-power component can reset the development board, with serious consequences.
2. High-current devices such as servos need their own supply. A dedicated regulated 5V supply for the servos can help keep their current draw from affecting the other electronics.
3. Don’t use a battery with too high a voltage. Connect a battery delivering more than 7V to a 5V input and you really might see smoke.
4. Avoid soldering the JY901B directly to the board by its castellated pads. Repeated hot-air heating can damage the built-in barometric altimeter.
5. Use plenty of silkscreen labels: connector pinouts, board name, date, version number, and any other notes. They’re like comments in code! This is especially important when one person designs the board and someone else assembles it.
6. Keep components away from the edge of the board, where they can get knocked off. This matters especially for the crystal oscillator, since edge placement can also cause EMI problems. Keep the crystal as close to the chip as possible, avoid routing traces underneath it, and use a ground pour there. When distributing a clock to multiple devices, route it as a clock tree.
7. Lay out the PCB in functional blocks. First, make each block compact and optimize its vias, traces, and copper pours. Use vias to fan out power and ground connections where possible, so you can route around them later. Minimize layer changes on signal traces to keep the via count down.
8. Place vias close to power and ground pins. Keep the traces between the pins and vias as short as possible to limit inductance. Make power and ground traces as wide as possible to reduce impedance.
9. The 0402 package is about as small as I can solder by hand. I strongly recommend larger components to make assembly easier.
10. The 3.3V rail is usually the main supply. With a dedicated power plane, it’s easy to use vias to distribute it across the board.
The 5V rail may only serve as the power input, in which case you only need a copper pour in a small area. Keep it as wide as you can.
11. I recommend VS Code for development. Pairing it with Copilot really speeds things up.

One last preview: we plan to finish building our latest thrust-vectoring rocket over winter break.
