6-DOF spacecraft attitude dynamics and control simulation for a nanosatellite orbiting Mars. Implements three autonomous pointing modes with a PD control law, MRP attitude parameterization, and RK4 numerical integration.
Built as a course project for ASEN 5010: Spacecraft Attitude Dynamics and Control, University of Colorado Boulder.
A nanosatellite in Low Mars Orbit (LMO) must autonomously switch between three operational modes based on its position relative to Mars, the sun, and a mother spacecraft in Geosynchronous Mars Orbit (GMO):
| Mode | Objective | Pointing Axis | Condition |
|---|---|---|---|
| 1: Sun Pointing | Power generation | +b3 (solar panels) toward +n2 (sun) | rN_LMO(2) >= 0 (sunlit side) |
| 2: Nadir Pointing | Science data collection | +b1 (sensor) toward Mars center | Dark side, GMO not in view |
| 3: GMO Pointing | Data downlink | -b1 (antenna) toward mother spacecraft | Angle to GMO < 35 deg |
Orbit parameters:
| Parameter | LMO (Nanosatellite) | GMO (Mother Spacecraft) |
|---|---|---|
| Radius | 3796.19 km | 20424.2 km |
| Inclination | 30 deg | 0 deg (equatorial) |
| RAAN | 20 deg | 0 deg |
| theta(t0) | 60 deg | 250 deg |
| Orbit rate | 0.000885 rad/s | 0.0000709 rad/s |
Attitude is represented using Modified Rodrigues Parameters (MRPs):
where
Singularity handling: MRPs are singular at
The shadow set represents the same physical rotation but with
where $\boldsymbol{\sigma}{B/R}$ is the MRP attitude error and ${}^B\boldsymbol{\omega}{B/R}$ is the angular velocity error, both expressed relative to the active reference frame.
Gains are selected for critically damped response with decay time constant
This guarantees all three attitude error components are either critically damped or underdamped (Schaub & Junkins, Ch. 8).
For this spacecraft (
For each active mode, the DCM from body frame B to reference frame R is:
The MRP and angular velocity errors are:
Euler's rotational equation (no external disturbance torques):
MRP kinematic differential equation:
Both are integrated simultaneously using 4th-order Runge-Kutta (RK4) with
The simulation captures three complete mode transitions. The spacecraft starts in sun-pointing mode, transitions to nadir-pointing as it enters Mars's shadow, briefly enters GMO-pointing when the mother spacecraft comes into view, then returns to sun-pointing.
Spacecraft Pointing Mode History
MRP Attitude Error convergence after each mode switch
Angular Rate Error convergence after each mode switch
Control Torque History (torque spikes correspond to mode transitions)
Angular Momentum (converges to near-zero in each mode after settling)
Rotational Kinetic Energy (minimal during sun-pointing due to low residual rates)
spacecraft-attitude-control-mars/
|
|-- task11_mission_scenario.m # Full 6500s mission with mode switching (START HERE)
|-- task08_sun_pointing.m # Sun-pointing control (400s)
|-- task09_nadir_pointing.m # Nadir-pointing control (400s)
|-- task10_gmo_pointing.m # GMO-pointing control (400s)
|
|-- utils/
| |-- Euler3132C.m # 3-1-3 Euler angles to DCM
| |-- MRP2C.m # MRP vector to DCM
| |-- C2MRP.m # DCM to MRP (Sheppard's method)
| |-- LMO_Inertial_Vectors.m # LMO inertial position and velocity
| |-- GMO_Inertial_Vectors.m # GMO inertial position and velocity
| |-- Sun_Pointing_Frame.m # Sun-pointing DCM and angular velocity
| |-- Nadir_Pointing_Frame.m # Nadir-pointing DCM and angular velocity
| |-- GMO_Pointing_Frame.m # GMO-pointing DCM and angular velocity (numerical)
|
|-- figures/ # Simulation output plots
|-- README.md
- Clone the repository
- Open MATLAB and navigate to the repo root
- Run the full mission scenario:
task11_mission_scenario - Or run individual pointing mode simulations:
task08_sun_pointing task09_nadir_pointing task10_gmo_pointing
No additional toolboxes required.
- MRP attitude kinematics and shadow set singularity avoidance
- DCM composition for relative frame tracking error
- PD control gain selection via linearized closed-loop eigenvalue placement
- Orbit frame construction from 3-1-3 Euler angles (3-1-3 sequence for RAAN, inclination, true latitude)
- Numerical DCM differentiation for time-varying reference frame angular velocity (GMO mode)
- RK4 integration of coupled kinematic and dynamic equations of motion
- Autonomous mode switching based on geometric visibility conditions
Schaub, H. and Junkins, J. L., Analytical Mechanics of Space Systems, 4th ed., AIAA Education Series, 2018.





