Here’s how we completed the thrust-vectoring rocket project we proposed in 2021, along with our plans to open-source it. We’d welcome feedback and discussion from fellow enthusiasts.
In 2021, I had just started my final year of high school and was new to the rocketry community. I wanted to build a rocket with an onboard control system. After a lot of thought, we settled on a method called “thrust vectoring.” We’ve made the code and mechanical design documents discussed here open source so fellow enthusiasts can share what they learn.
Stage One
We had just started our final year of high school and used our spare time to draw and work on the design. We weren’t familiar with professional modeling tools like SolidWorks (SW) or CAD software, so we drew everything by hand. Our earliest drawings, shown in Figure 1.1, were pretty amateurish:

Figure 1.1 Early hand-drawn plans
I was mainly responsible for electronics and controls. We released the original software on GitHub. The first prototype used an Arduino Uno and an MPU6050 attitude sensor. Its controller was simple and had no parachute deployment routine.
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <Servo.h>
Adafruit_MPU6050 mpu;
int x = 0;
int y = 0;
int z = 0;
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
int value = 0;
void setup(void) {
Serial.begin(115200);
// 尝试初始化
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
// 将加速度计范围设置为 +-8G
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
// 将陀螺仪范围设置为 +- 500 度/秒
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
// 将滤波器带宽设置为 21 Hz
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
delay(100);
servo1.attach(8);
//servo2.attach(6);
//servo3.attach(5);
servo4.attach(6);
servo1.write(90);
servo2.write(0);
servo3.write(0);
servo4.write(90);
}
void loop() {
/* 使用读数获取新的传感器事件 */
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);
}
}
The controller worked in theory. During testing, sensor readings fluctuated and the servo overcorrected, so the rocket rose along an S-shaped path. The airframe was still a cardboard tube, and we had yet to finish a complete set of drawings.https://pan.baidu.com/s/1KOF_xN1g44SiT1ISCOHRIQ?pwd=r1ll
All the rocket motors discussed in this article used the same type of solid propellant.
Stage Two
In later versions, I added sensor filtering and revised the feedback controller to address the first prototype’s problems.
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <I2Cdev.h>
#include <Servo.h>
#include <MPU6050.h>
#include <Math.h>
MPU6050 accelgyro;
unsigned long now, lastTime = 0;
float dt; //微分时间
int16_t ax, ay, az, gx, gy, gz; //加速度计陀螺仪原始数据
float aax=0, aay=0,aaz=0, agx=0, agy=0, agz=0; //角度变量
long axo = 0, ayo = 0, azo = 0; //加速度计偏移量
long gxo = 0, gyo = 0, gzo = 0; //陀螺仪偏移量
float pi = 3.1415926;
float AcceRatio = 16384.0; //加速度计比例系数
float GyroRatio = 131.0; //陀螺仪比例系数
uint8_t n_sample = 8; //加速度计滤波算法采样个数
float aaxs[8] = {0}, aays[8] = {0}, aazs[8] = {0}; //x,y轴采样队列
long aax_sum, aay_sum,aaz_sum; //x,y轴采样和
float a_x[10]={0}, a_y[10]={0},a_z[10]={0} ,g_x[10]={0} ,g_y[10]={0},g_z[10]={0}; //加速度计协方差计算队列
float Px=1, Rx, Kx, Sx, Vx, Qx; //x轴卡尔曼变量
float Py=1, Ry, Ky, Sy, Vy, Qy; //y轴卡尔曼变量
float Pz=1, Rz, Kz, Sz, Vz, Qz; //z轴卡尔曼变量
float num1=1;
float num2=1;
float num3=1;
float num4=1;
Servo servo1;
Servo servo2;
Servo servo_pin_2; //开伞舵机
/**
* 矢量pid部分
*/
double kp = 0.3,ki = 0.15,kd = 0.1;
/*
Kp:比例增益,是调适参数;
Ki:积分增益,也是调适参数;
Kd:微分增益,也是调适参数;
取增量pid
采用恒定的采样周期 T,一旦确定Kp、Ki、Kd参数,只要使用前后三次测量的偏差值,就可以由增量式PID公式求出控制量。
现在设置的参数是我瞎蒙的,不一定准确
*/
double sumerror_x,sumerror_y;//x轴和y轴总计误差
double lasterror_x,lasterror_y;//上一时刻误差值
double output_x,output_y;//累加修正结果
void setup() {
servo1.attach(8);
servo2.attach(6);
servo_pin_2.attach(9);
servo1.write(90);
servo2.write(90);
servo_pin_2.write( 180 );
Wire.begin();
Serial.begin(115200);
accelgyro.initialize(); //初始化
unsigned short times = 200; //采样次数
for(int i=0;i<times;i++)
{
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); //读取六轴原始数值
axo += ax; ayo += ay; azo += az; //采样和
gxo += gx; gyo += gy; gzo += gz;
}
axo /= times; ayo /= times; azo /= times; //计算加速度计偏移
gxo /= times; gyo /= times; gzo /= times; //计算陀螺仪偏移
}
void loop() {
unsigned long now = millis(); //当前时间(ms)
dt = (now - lastTime) / 1000.0; //微分时间(s)
lastTime = now; //上一次采样时间(ms)
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); //读取六轴原始数值
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轴的夹角
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; // 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;
/**
* 矢量控制部分
*/
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)
{
//servo2.write(num3*agy);
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)
{
//servo2.write(num4*(90-agy));
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);
Serial.print("开伞agx>70");
while(1)
{
}
}
if(agy>70)//开伞角度
{
//digitalWrite(8,1);
servo_pin_2.write( 0 );
delay(2000);
Serial.print("开伞agy>70");
while(1)
{
}
}
if(agy<-70)//开伞角度
{
//digitalWrite(8,1);
servo_pin_2.write( 0 );
delay(2000);
Serial.print("开伞agy<-70");
while(1)
{
}
}
if(agx<-70)//开伞角度
{
//digitalWrite(8,1);
servo_pin_2.write( 0 );
delay(2000);
Serial.print("开伞agx<-70");
while(1)
{
}
}
// Serial.print(agx);Serial.print(",");
// Serial.print(agy);Serial.print(",");
// Serial.print(agz);Serial.println();
}
I found a description of the filtering algorithm that went roughly like this: a Kalman filter efficiently estimates the state of a dynamic system from multiple sources of information in the presence of uncertainty. It updates its estimates recursively in real time and is widely used in target tracking, pattern recognition, and navigation. For an extended Kalman filter (EKF), the state equation of a dynamic system can be written as:
X(t)=F(t)·X(t-1)+w(t)
The measurement equation can be written as:
Z(t)=H(t)·X(t)+v(t)
Here, X(t) is the system state vector at time t, F(t) is the state transition matrix at time t, Z(t) is the measurement vector at time t, H(t) is the measurement matrix at time t, w(t) is process noise, and v(t) is observation noise.
For attitude estimation, the article introduces a state vector based on an attitude quaternion:
X(t)=[q0 q1 q2 q3 bgx bgy bgz]T
Here, q=[q0 q1 q2 q3]T is the quaternion representing attitude, and b=[bgx bgy bgz]T is the bias in the gyroscope’s angular velocity measurements.
Figure 2.1 shows the rocket’s control flow:

Figure 2.1 Rocket control flow
I covered the PID algorithm in an earlier post, so I’ll keep it brief here. We switched to a truss-and-skin airframe and redesigned the motor assembly to make it more stable and easier to assemble.
(1) Mechanical linkage
We made a custom linkage to transfer motion from the servo to the thrust-vectoring assembly. Figure 2.2 shows the servo linkage and pushrod.

Figure 2.2 Servo pushrod assembly
(2) Parachute deployment mechanism
We designed a split nose cone with one fixed half and one movable half so the parachute could deploy. Figure 2.3 shows the inside of the fixed half. An onboard controller triggered the release mechanism to open the movable half and let the parachute deploy.

Figure 2.3 Fixed side of the nose cone
(3) Motor assembly
The motor assembly included a casing, insulation, a nozzle, seals, and mechanical fasteners. The team designed the assembly to limit leaks and hold the motor together. Figure 2.4 shows the assembly before all the fasteners were fitted.

Figure 2.4 Motor assembly diagram
(4) Motor bay design
The motor bay was designed to hold the motor in place. It also accommodated the thrust-vectoring system and held the fins in position to maintain the rocket’s aerodynamic shape. Figures 2.5–2.9 show the front and rear flanges, the upper and lower sections of the motor bay, and the fin retaining ring. The retaining features keep the motor from sliding out, the bay accommodates the control linkage, and the outer ring holds the fins in place.

Figure 2.5 Front flange

Figure 2.6 Rear flange

Figure 2.7 Upper motor bay

Figure 2.8 Lower motor bay (internal clips keep the motor from sliding out)

Figure 2.9 Fin retaining ring (holds the fins in place)
(5) Flight controller mounting bracket
The bracket had four tiers for the servos, the flight controller’s power supply, the flight controller PCB, and the inertial navigation module, in that order from bottom to top. The top tier held the IMU for monitoring the rocket’s attitude. A wireless serial module enabled real-time telemetry. Figure 2.10 shows the bracket.

Figure 2.10 Flight controller mounting bracket
(6) Thrust-vectoring nozzle design
The nozzle had a fixed section and a movable section. The movable section changed the direction of the exhaust for thrust vectoring. Figures 2.11 and 2.12 show the two sections.

Figure 2.11 Fixed nozzle section

Figure 2.12 Movable nozzle section
At this point we also 3D-printed a complete rocket model, assembled it, and tested it. Figure 2.13 shows the assembled rocket.
Figure 2.13 Fully assembled rocket
We now had a working prototype, with details such as parachute deployment and the fins still to refine.
Stage Three
At this stage I rewrote most of the software. Building on my earlier post, I refined how the program handles each phase of flight. I also worked on actuator calibration, software limits, and sending data to the ground station.
void setup() {
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
Wire.setClock(400000); // 400kHz的I2C
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
Servo1.attach(8);
Servo2.attach(6);
Servo_KS.attach(9);
Servo1.write(90);
Servo2.write(90);
Servo_KS.write(Servo_KS_ANGLE1);
Serial.begin(115200);
//while (!Serial); //当串口监视打开以后程序运行,方便调试,上箭之前记得注释掉
Serial.println(F("加载I2C设备..."));
mpu.initialize();
pinMode(INTERRUPT_PIN, INPUT);
Serial.println(F("测试设备连接中..."));
Serial.println(mpu.testConnection() ? F("MPU6050连接成功") : F("MPU6050连接失败"));
Serial.println(F("调用 DMP..."));
devStatus = mpu.dmpInitialize();
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
mpu.setZAccelOffset(1788);
if (devStatus == 0) {
mpu.CalibrateAccel(6);
mpu.CalibrateGyro(6);
mpu.PrintActiveOffsets();
//打开DMP
Serial.println(F("Enabling DMP..."));
mpu.setDMPEnabled(true);
Serial.print(F("Enabling interrupt detection (Arduino external interrupt "));
Serial.print(digitalPinToInterrupt(INTERRUPT_PIN));
Serial.println(F(")..."));
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING);
mpuIntStatus = mpu.getIntStatus();
Serial.println(F("DMP ready! Waiting for first interrupt..."));
dmpReady = true;
packetSize = mpu.dmpGetFIFOPacketSize();
} else {
// ERROR!
// 1 = 初始内存加载失败
// 2 = DMP 配置更新失败
Serial.print(F("DMP配置失败 (代码 "));
Serial.print(devStatus);
Serial.println(F(")"));
}
}
void loop() {
// put your main code here, to run repeatedly:
if (!dmpReady) return;
// 从FIFO读取包
if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer)) {
#ifdef OUTPUT_READABLE_YAWPITCHROLL
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
acc_z=aaReal.z;
angle_x=ypr[2] * 180/M_PI;
angle_y=ypr[1] * 180/M_PI;
angle_z=ypr[0] * 180/M_PI;
angle_x_ano = ypr[2] * 180/M_PI;
angle_y_ano = ypr[1] * 180/M_PI;
angle_z_ano = ypr[0] * 180/M_PI;
Send_Data_Attitude(angle_x_ano, angle_y_ano, angle_z_ano); //发送欧拉角
#endif
PID_control();
sample_valid = 0;
sample_ready = 1;
sample_cnt = sample_cnt + 1;
}
For this generation’s avionics, we designed our own PCB around an ATmega328P microcontroller and a CH340N USB-to-TTL interface. I traced the USB detection issue mentioned in the earlier post to a poorly soldered USB-C connector and fixed it by resoldering the pins. Thanks to everyone who helped. The team’s notes identify a 74HC244D buffer on the power board. The author reports that the board handled three servos in testing and struggled with four.
We also refined the parachute deployment mechanism and the fin shape. Figure 3.1 shows the new deployment mechanism:

Figure 3.1 Diagram of the new parachute deployment mechanism
When triggered, the release mechanism opened the nose cone and let the parachute deploy, as shown in Figure 3.2:

Figure 3.2 Parachute deployment
Figure 3.3 shows the fully assembled rocket.

Figure 3.3 Fully assembled rocket
We then carried out a test launch and recovered the rocket successfully by parachute. Smoke from the motor obscured the moment the parachute opened, so the photo here shows the rocket descending. We launched at a large abandoned airfield. The telephoto lens may be why the houses look so close.

I learned a lot through this project, including things I’d never worked on before. I’m grateful to everyone on the team for their hard work and to all the friends who guided and helped us. I hope we keep working toward our dreams in the years ahead. That’s the story of how the team and I pursued ours. Some of my terminology may be off, so I’d welcome corrections. Thanks again for all your help.
