Model Rocket Stabilizer
This guide will walk you through creating a 3D-printed stabilizer for a model rocket. With this project, your rocket will be able to maintain stable trajectories and resist disruptions caused by external forces. The design is straightforward, utilizing a Seeeduino XIAO microcontroller, 9G servos, and a selection of 3D-printed components.
Supplies
Materials:
Electrical Components:
- 10x24 Printed Prototype Board
- Prototype Board - 40cm Single Gauge Breadboard Wire
- Prototype Board - Red LED
- Prototype Board - 220Ω/330Ω Resistor (x4)
- Prototype Board - Toggle Switch
- Prototype Board - Seeeduino XIAO, 1st Edition
- Prototype Board - Power Header
- Prototype Board - Male Dupont Header Pins (x14)
- 4-pin Common Cathode RGB LED
- GY-521 Gyroscope/Accelerometer Module
- FITEC Servo Motors (x2)
- Tin Solder
Hardware:
- Flanged Head Servo Screws (x7)
- 40mm M3 Bolt (x2)
- 15mm M3 Bolts (x6)
- M3 Nuts (x3)
- PLA/PETG Filament (55.5g)
Tools:
- Soldering Iron
- Needle Nose Pliers
- Phillips Head Screwdriver
- USB-C Cable (Seeeduino XIAO programmer)
- Arduino IDE/Visual Studio Code
- PrusaSlicer or equivalent
- 3D printer
3D Printing
You will need to print 7 different parts for this project
Below are the drawings and STL files for the parts. These parts were printed out of PLA filament, using the below print settings within the chosen slicer. These parts could also be made from metal, so drawings are provided below along with the STL files. Every file should be printed once, and no post-processing is required except for the removal of supports. Print settings are as follows.
- Generate Supports: Everywhere
- Infill: 60%
- Bed Adhesion Type: Brim or Raft
- Layer Height: 0.15mm
- First Layer Height: 0.2mm
- Perimeters: 2
- Speed: 80mm/s
Making the Circuit
- MPU6050 Gyro:
- VCC: Seeeduino 5V
- GND: Seeeduino GND
- SCL: Seeeduino SCL pin (A4)
- SDA: Seeeduino SDA pin (A5)
- Servo Motor X:
- Signal: Seeeduino D10
- Power: External 5V
- Ground: External GND & Seeeduino GND
- Servo Motor Y:
- Signal: Seeeduino D3
- Power: External 5V
- Ground: External GND & Seeeduino GND
- RGB LED (Listed left to right):
- Red Signal Pin: Seeeduino D5
- Common Cathode: Seeeduino GND (Longest Leg)
- Green Signal Pin: Seeeduino D6
- Blue Signal Pin: Seeeduino D7
- Use a 220Ω OR 330Ω resistor for a., c., and d.
Code
The code for this project can be found here
How to tune a PID:
- Set Initial Values
- Start with:
- Kp = 1.0
- Ki = 0.0
- Kd = 0.0
- Tuning Steps
- Increase KP:
- Gradually increase KP to improve response speed.
- Stop increasing when the system starts to oscillate around the target angle.
- Adjust KD:
- Increase KD to reduce overshooting and oscillation.
- This helps stabilize the system by dampening rapid changes.
- Tune KI:
- Increase KI if there is a steady-state error (i.e., the system doesn't reach the exact target).
- Be cautious: too high KI can cause oscillations or instability.
- Trial and Error
- Test the system by tilting it and observing the behavior.
- Adjust KP, KD, and KI iteratively.
- Adjust Recovery Thresholds
- The recovery and stabilization thresholds (recoveryThreshold and stabilizeThreshold) define when the system switches between modes. Adjust these to your liking.
How to tune the PID in practice:
- Open the serial monitor and type ‘K’ without quotes and hit enter.
- Enter the new values. For example, if you want to set KP = 2.5, KI = 0.6, and KD = 1.2, type: 2.5 0.6 1.2.
- The system will print back out your new PID values in this format:
- New KP: 2.5
- New KI: 0.6
- New KD: 1.2
Code Features & Explanation
MPU6050 Sensor Integration:
- Uses the MPU6050 IMU/Gyro (Inertial Measurement Unit) to get accelerometer and gyroscope data.
- This sensor is used to measure the pitch and roll angles of the system.
PID Control for Stabilization:
- Uses a PID control loop to maintain system stability.
- Adjusts the servo positions to stabilize the pitch and roll of the system based on the calculated PID outputs.
- Allows real-time tuning of PID parameters (Kp, Ki, Kd) via serial input.
Control Modes:
- STABILIZE Mode: This is the regular operation mode, where the system uses smooth, small motions to attempt to keep the pitch and roll angles as near the target values as possible.
- RECOVERY Mode: Activated if the pitch or roll exceeds a tilt threshold, initiates harsher, faster recovery motions to return the system to a stable state, where STABILIZE mode is reengaged.
Gyro Calibration:
- Calibrates the gyroscope offsets to ensure accurate rotation readings.
- Calibration performed by averaging sensor readings over a defined number of samples.
Homing Sequence:
- Moves both servos (servoX and servoY) to extreme positions and then back to the center to ensure they are in their default position.
Pre-flight Check:
- Checks the status of the accelerometer and gyroscope readings to ensure the system is functioning correctly.
- If the readings are invalid (e.g., 0 values), the system enters an error state and stops.
Filtered Orientation Calculation:
- Uses accelerometer and gyroscope data to calculate the system's pitch and roll.
- Employs a Kalman filter to combine accelerometer and gyroscope data for accurate and noise-reduced orientation angles.
PID Computation:
- The PID controller computes the necessary adjustments for pitch and roll based on the error values (difference between target and actual angles).
- Integrates error over time, takes into account the rate of change of error, and adjusts the system output accordingly.
Servo Control:
- The pitch and roll adjustments are converted into servo commands to control the movement of two servos (servoX and servoY).
- The servo positions are constrained to a range between 0 and 180 degrees.
Real-time PID Parameter Tuning via Serial Interface:
- The user can input new PID parameters (Kp, Ki, Kd) through the serial monitor by sending the 'K' command.
- The system listens for PID tuning commands and updates the PID values accordingly.
Real-time Setpoint Adjustment:
- The user can input new X and Y setpoints through the serial monitor by sending the 'T' command.
- The system listens for X and Y tuning commands and updates the setpoint values accordingly.
Emergency Stop:
- The user can activate the emergency stop on the servos and gyro by sending the ‘E’ command, and deactivate it by sending the ‘R’ command.
Filtering and History:
- Implements a history buffer to filter the gyroscope data for smoother measurements.
- Applies a moving average filter to gyroscope data for noise reduction.
Timed Updates:
- Updates control outputs every 10 milliseconds, ensuring the system responds quickly to changes in orientation.
- Uses millis() for time-based calculations, ensuring that the system doesn't rely on blocking delays.
System Initialization:
- Initializes the MPU6050 sensor, serial communication, servos, and RGB LED.
- Performs pre-flight checks and homing sequences at startup.
Downloads
Assembling X and Y-Gimbals
Attach the GY-521 Gyroscope/Accelerometer Module to the Rocket Holder using two Flanged Head Servo Screws and as seen above. This will allow the rocket to get Y data on where it is and where it has to move to fix its Y position. This should be assembled using another 2 Flanged Head Servo Screws. Then connect the Y-Gimbal to the inside of the X-Gimbal using two 15mm M3 bolts.
Outer Shell Attachment
Attach the entire subassembly you created in the previous step into the inside of the Outer shell using two 40mm M3 bolts, so that the X and Y can rotate independently.
Mounting Servos
Mount the two 9G Servos into their mounts by sliding the 3-wire dupont cable through the routing hole and then press-fitting the servos in after it. Make sure the the wires do not break during this process, and be careful with the thin servo holder frame. After both servos are mounted, you can use three Flanged Head Servo Screws to hold them in place.
Setting Up the Servo Motors
The X connection Beams should be connected to the X-gimbal and the Y connection beam should be connected to the Y-gimbal. If this is not done correctly the code that is shown above will not work. There is a distinct difference between the X and Y connection beam. The Y connection beam requires that the part have a curved edge opposed to a straight edge like the X connection beam. This should all be screwed in with Flanged Head Servo Screws. You will have to cut down the one way arms the come with the servos to make sure that they fit inside the movement arms for the gimbal.
Enjoy!
Well done! We hope our project was able to help you.
This project is just a simple solution and neither the code, nor the design is fully optimized. That being said, it is a excellent proof of concept, and we hope that it can serve as an inspiration for more complicated versions of the same thing, or spark the same passion for creating and making that was sparked within us.