5 min read
Interactive CubeSat 3D ADCS Simulator
A real-time 3D spacecraft orientation simulator built in pure base MATLAB with zero external toolboxes. Features quaternion-based attitude kinematics, realistic reaction wheel torque limits, tumble recovery, and live telemetry scopes.
- MATLAB
- Robotics & Control
- Spacecraft Dynamics
- ADCS
- Quaternion Kinematics
1. Overview & Motivation
In the vacuum of space, satellites cannot rely on aerodynamic surfaces like fins or rudders to steer. Instead, they depend on an Attitude Determination and Control System (ADCS)—using spinning internal motor flywheels (reaction wheels) to orient the spacecraft via the conservation of angular momentum.
Most aerospace simulations require heavy, expensive proprietary toolboxes like Simulink or Aerospace Blockset. I wanted to create a lightweight, accessible, and interactive simulation that runs on 100% standard base MATLAB (R2018b+) with zero external dependencies.
This simulator (ADCS_simulator.m) provides an immediate, visual platform to experiment with 3D spacecraft orientation, test closed-loop control laws, and see firsthand how physical motor limitations impact pointing accuracy.
2. System Architecture & Workflow
The simulator operates as a continuous closed-loop dynamical system stepping forward at 30 ms intervals (time step dt = 0.03 seconds):
[ User Input (Sliders) ] ──> [ Target Quaternion ]
│
▼
[ Current Attitude (q) ] ──> [ Error Calculation ]
│
▼
[ Gyro Telemetry ] ──> [ PD Control Law ]
│
▼
[ Torque Clamp (±4 mN·m) ]
│
▼
[ Euler Rotational Dynamics ]
│
▼
[ 3D Visualizer & Scopes ]
The Step-by-Step Flow:
- Target Generation: The user adjusts Yaw, Pitch, and Roll sliders in real time, immediately updating the commanded target frame.
- Attitude Error Computation: Converts Euler setpoints into target quaternions and calculates the 3D rotational angular error relative to the satellite's current orientation.
- PD Controller: Calculates required steering torque using proportional error feedback and derivative rate damping.
- Actuator Saturation: Clamps commanded torque to real-world CubeSat reaction wheel limits (maximum 4 mN·m).
- Rigid-Body Dynamics: Computes angular acceleration based on 3U CubeSat mass properties and chassis dimensions.
- Kinematic Integration: Updates orientation quaternions smoothly across 3D space without gimbal lock.
- Real-time Rendering: Live updates for dual 3D coordinate triads (target vs. actual) and rolling telemetry scopes.
3. Interactive Features & Controls
The simulator pairs high-fidelity numerical physics with an intuitive graphical interface:
- Real-Time Dragging: Adjust Yaw (-180° to +180°), Pitch (-90° to +90°), or Roll (-180° to +180°) sliders on the fly. The target reference frame updates instantly, and the satellite actively slews to acquire the target.
- Dual 3D Coordinate Triads:
- Solid RGB Axes (X, Y, Z): Represents the actual physical body frame of the CubeSat.
- Dashed RGB Axes: Represents the commanded target orientation the satellite is pursuing.
- Realistic Reaction Wheel Physics: Models real-world brushless DC motor limits with a strict ±4 mN·m torque clamp, mirroring commercial 3U nanosatellite actuators.
- Disturbance Injection & Tumble Recovery:
- "Disturb (Tumble)" Button: Injects a sudden angular rate spike (±35°/s) to simulate deployment tip-off or collisions. The controller autonomously stabilizes the tumble and re-locks onto the target.
- "Randomize Target" Button: Snaps the target frame to unpredictable orientations to benchmark multi-axis slewing performance.
- "Reset" Button: Instantly re-centers the satellite, cancels residual body rates, and resets telemetry buffers.
- Live Rolling Telemetry: Real-time strip charts track 3-axis angular rates (wx, wy, wz), total attitude error magnitude, and pointing lock confirmation.
4. Physics & Control Logic Explained Simply
A. Singularity-Free Quaternions
Euler angles are intuitive for humans, but they suffer from gimbal lock—a mathematical singularity where one degree of freedom is lost when pitch reaches ±90°.
To ensure continuous, crash-free 3D rotations, orientation is tracked using unit quaternions with 4 components (w, x, y, z). Quaternion kinematics propagate orientation smoothly as the satellite spins without any mathematical singularities.
B. Rigid-Body Rotational Dynamics
The satellite chassis is modeled on a standard 3U CubeSat (4.0 kg mass, 10 x 10 x 30 cm dimensions) with a 3x3 moment of inertia matrix. Rotational acceleration follows standard rigid-body dynamics equations, balancing applied motor torque against gyroscopic cross-coupling torques.
C. Saturated PD Control Law
To track commanded orientations without severe overshoots, the control system applies a Proportional-Derivative (PD) control law:
- Proportional Action (Kp = 0.015): Acts as a virtual rotational spring pulling the satellite toward the desired target orientation.
- Derivative Action (Kd = 0.050): Acts as a rotational damper, dissipating kinetic energy to suppress oscillations and settling time.
- Torque Saturation Clamp (±0.004 N·m): Restricts commanded torque to 4 mN·m so the satellite behaves like actual hardware in orbit rather than having unrealistic infinite power.
5. Technical Stack
| Category | Details |
|---|---|
| Language & Runtime | MATLAB (R2018b or later) |
| Dependencies | 100% Base MATLAB (Zero external toolboxes required) |
| Mathematical Models | Quaternion kinematics, Rigid-body dynamics, Saturated PD control |
| UI & Graphics | Native MATLAB uifigure, handle graphics, 3D patch transforms |
6. How to Run
- Open MATLAB (R2018b+).
- Navigate to the project root directory.
- In the MATLAB Command Window, execute:
ADCS_simulator - The interactive window will open immediately. Try adjusting the attitude sliders or triggering a tumble disturbance to see the closed-loop recovery in action.
7. Key Engineering Takeaways
- Numerical Stability in Real-Time Loops: Balancing integration accuracy with smooth 30 fps GUI updates required lean matrix operations and lightweight graphical handle transforms.
- Actuator Saturation Dynamics: Modeling torque limits revealed how control authority changes during large slews versus fine pointing maneuvers.
- Stand-Alone Portability: Writing the entire simulation in base MATLAB proved that high-performance engineering tools can be built without heavy external software dependencies.