Model Rocket Stabilizer

by gabrielli in Circuits > Arduino

238 Views, 1 Favorites, 0 Comments

Model Rocket Stabilizer

unnamed (2).jpg

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:

  1. 10x24 Printed Prototype Board
  2. Prototype Board - 40cm Single Gauge Breadboard Wire
  3. Prototype Board - Red LED
  4. Prototype Board - 220Ω/330Ω Resistor (x4)
  5. Prototype Board - Toggle Switch
  6. Prototype Board - Seeeduino XIAO, 1st Edition
  7. Prototype Board - Power Header
  8. Prototype Board - Male Dupont Header Pins (x14)
  9. 4-pin Common Cathode RGB LED
  10. GY-521 Gyroscope/Accelerometer Module
  11. FITEC Servo Motors (x2)
  12. Tin Solder

Hardware:

  1. Flanged Head Servo Screws (x7)
  2. 40mm M3 Bolt (x2)
  3. 15mm M3 Bolts (x6)
  4. M3 Nuts (x3)
  5. PLA/PETG Filament (55.5g)

Tools:

  1. Soldering Iron
  2. Needle Nose Pliers
  3. Phillips Head Screwdriver
  4. USB-C Cable (Seeeduino XIAO programmer)
  5. Arduino IDE/Visual Studio Code
  6. PrusaSlicer or equivalent
  7. 3D printer

3D Printing

3D prints.jpg

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.

  1. Generate Supports: Everywhere
  2. Infill: 60%
  3. Bed Adhesion Type: Brim or Raft
  4. Layer Height: 0.15mm
  5. First Layer Height: 0.2mm
  6. Perimeters: 2
  7. Speed: 80mm/s

Making the Circuit

Ciurcuit.jpg
Screenshot 2024-12-19 at 1.06.40 PM.png
Screen Shot 2024-12-18 at 9.55.48 PM.png
Servo-Motor-Wires.png
MPU6050-Module-Pinout.jpg
  1. MPU6050 Gyro:
  2. VCC: Seeeduino 5V 
  3. GND: Seeeduino GND
  4. SCL: Seeeduino SCL pin (A4)
  5. SDA: Seeeduino SDA pin (A5)
  6. Servo Motor X:
  7. Signal: Seeeduino D10
  8. Power: External 5V
  9. Ground: External GND & Seeeduino GND
  10. Servo Motor Y:
  11. Signal: Seeeduino D3
  12. Power: External 5V
  13. Ground: External GND & Seeeduino GND
  14. RGB LED (Listed left to right):
  15. Red Signal Pin: Seeeduino D5
  16. Common Cathode: Seeeduino GND (Longest Leg)
  17. Green Signal Pin: Seeeduino D6
  18. Blue Signal Pin: Seeeduino D7
  19. Use a 220Ω OR 330Ω resistor for a., c., and d.

Code

Screenshot 2024-12-19 at 12.08.50 AM.png
Screenshot 2024-12-19 at 12.09.25 AM.png

The code for this project can be found here


How to tune a PID:

  1. Set Initial Values
  2. Start with:
  3. Kp = 1.0
  4. Ki = 0.0 
  5. Kd = 0.0
  6. Tuning Steps
  7. Increase KP:
  8. Gradually increase KP to improve response speed.
  9. Stop increasing when the system starts to oscillate around the target angle.
  10. Adjust KD:
  11. Increase KD to reduce overshooting and oscillation.
  12. This helps stabilize the system by dampening rapid changes.
  13. Tune KI:
  14. Increase KI if there is a steady-state error (i.e., the system doesn't reach the exact target).
  15. Be cautious: too high KI can cause oscillations or instability.
  16. Trial and Error
  17. Test the system by tilting it and observing the behavior.
  18. Adjust KP, KD, and KI iteratively.
  19. Adjust Recovery Thresholds
  20. 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:

  1. Open the serial monitor and type ‘K’ without quotes and hit enter.
  2. 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.
  3. The system will print back out your new PID values in this format: 
  4. New KP: 2.5
  5. New KI: 0.6
  6. New KD: 1.2


Code Features & Explanation 


MPU6050 Sensor Integration:

  1. Uses the MPU6050 IMU/Gyro (Inertial Measurement Unit) to get accelerometer and gyroscope data.
  2. This sensor is used to measure the pitch and roll angles of the system.

PID Control for Stabilization:

  1. Uses a PID control loop to maintain system stability.
  2. Adjusts the servo positions to stabilize the pitch and roll of the system based on the calculated PID outputs.
  3. Allows real-time tuning of PID parameters (Kp, Ki, Kd) via serial input.

Control Modes:

  1. 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.
  2. 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:

  1. Calibrates the gyroscope offsets to ensure accurate rotation readings.
  2. Calibration performed by averaging sensor readings over a defined number of samples.

Homing Sequence:

  1. 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:

  1. Checks the status of the accelerometer and gyroscope readings to ensure the system is functioning correctly.
  2. If the readings are invalid (e.g., 0 values), the system enters an error state and stops.

Filtered Orientation Calculation:

  1. Uses accelerometer and gyroscope data to calculate the system's pitch and roll.
  2. Employs a Kalman filter to combine accelerometer and gyroscope data for accurate and noise-reduced orientation angles.

PID Computation:

  1. The PID controller computes the necessary adjustments for pitch and roll based on the error values (difference between target and actual angles).
  2. Integrates error over time, takes into account the rate of change of error, and adjusts the system output accordingly.

Servo Control:

  1. The pitch and roll adjustments are converted into servo commands to control the movement of two servos (servoX and servoY).
  2. The servo positions are constrained to a range between 0 and 180 degrees.

Real-time PID Parameter Tuning via Serial Interface:

  1. The user can input new PID parameters (Kp, Ki, Kd) through the serial monitor by sending the 'K' command.
  2. The system listens for PID tuning commands and updates the PID values accordingly.

Real-time Setpoint Adjustment:

  1. The user can input new X and Y setpoints through the serial monitor by sending the 'T' command.
  2. The system listens for X and Y tuning commands and updates the setpoint values accordingly.

Emergency Stop:

  1. 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:

  1. Implements a history buffer to filter the gyroscope data for smoother measurements.
  2. Applies a moving average filter to gyroscope data for noise reduction.

Timed Updates:

  1. Updates control outputs every 10 milliseconds, ensuring the system responds quickly to changes in orientation.
  2. Uses millis() for time-based calculations, ensuring that the system doesn't rely on blocking delays.

System Initialization:

  1. Initializes the MPU6050 sensor, serial communication, servos, and RGB LED.
  2. Performs pre-flight checks and homing sequences at startup.

Downloads

Assembling X and Y-Gimbals

Middle.jpg

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

IMG_0279.JPG
IMG_0277.JPG

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

IMG_0275.JPG
IMG_0280.JPG
IMG_0283.JPG

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

20241217_132406.jpg
20241217_132419.jpg

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!

unnamed (2).jpg

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.