Skip to content

Repository files navigation

Spacecraft Attitude Control: Mars Nanosatellite Mission

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.


Mission Overview

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 Parameterization: Modified Rodrigues Parameters (MRPs)

Attitude is represented using Modified Rodrigues Parameters (MRPs):

$$\boldsymbol{\sigma} = \hat{e} \tan(\Phi/4)$$

where $\Phi$ is the principal rotation angle and $\hat{e}$ is the rotation axis. MRPs are a minimal 3-parameter representation derived from quaternions.

Singularity handling: MRPs are singular at $\Phi = 360°$ (where $|\boldsymbol{\sigma}| \to \infty$). This is avoided by switching to the shadow set whenever $|\boldsymbol{\sigma}| &gt; 1$:

$$\boldsymbol{\sigma}^* = \frac{-\boldsymbol{\sigma}}{|\boldsymbol{\sigma}|^2}$$

The shadow set represents the same physical rotation but with $|\boldsymbol{\sigma}^*| &lt; 1$, keeping the parameterization well-conditioned throughout all maneuvers.


Control Architecture

PD Control Law

$$\mathbf{u} = -K \boldsymbol{\sigma}_{B/R} - P , {}^B\boldsymbol{\omega}_{B/R}$$

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.

Gain Selection

Gains are selected for critically damped response with decay time constant $\tau = 120$ s:

$$P = \frac{2 , I_{max}}{\tau}, \qquad K = \frac{P^2}{I_{min}}$$

This guarantees all three attitude error components are either critically damped or underdamped (Schaub & Junkins, Ch. 8).

For this spacecraft ($I = \text{diag}(10, 5, 7.5)$ kg m²):

$$P = 0.1667 \text{ N·m·s/rad}, \qquad K = 0.00556 \text{ N·m/rad}$$

Tracking Error Computation

For each active mode, the DCM from body frame B to reference frame R is:

$$[BR] = [BN][RN]^T$$

The MRP and angular velocity errors are:

$$\boldsymbol{\sigma}_{B/R} = \text{C2MRP}([BR])$$

$${}^B\boldsymbol{\omega}_{B/R} = {}^B\boldsymbol{\omega}_{B/N} - [BN] , {}^N\boldsymbol{\omega}_{R/N}$$


Equations of Motion

Euler's rotational equation (no external disturbance torques):

$$[I] \dot{\boldsymbol{\omega}} = -[\tilde{\boldsymbol{\omega}}][I]\boldsymbol{\omega} + \mathbf{u}$$

MRP kinematic differential equation:

$$\dot{\boldsymbol{\sigma}} = \frac{1}{4}\left[(1 - |\boldsymbol{\sigma}|^2)\mathbf{I}_3 + 2[\tilde{\boldsymbol{\sigma}}] + 2\boldsymbol{\sigma}\boldsymbol{\sigma}^T\right]\boldsymbol{\omega}$$

Both are integrated simultaneously using 4th-order Runge-Kutta (RK4) with $\Delta t = 1$ s.


Results

Full Mission Scenario (6500 seconds)

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

Pointing History

MRP Attitude Error convergence after each mode switch

Sigma BR

Angular Rate Error convergence after each mode switch

Omega BR

Control Torque History (torque spikes correspond to mode transitions)

Control Torque

Angular Momentum (converges to near-zero in each mode after settling)

Angular Momentum

Rotational Kinetic Energy (minimal during sun-pointing due to low residual rates)

Kinetic Energy


Repository Structure

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

How to Run

  1. Clone the repository
  2. Open MATLAB and navigate to the repo root
  3. Run the full mission scenario:
    task11_mission_scenario
  4. Or run individual pointing mode simulations:
    task08_sun_pointing
    task09_nadir_pointing
    task10_gmo_pointing

No additional toolboxes required.


Key Technical Concepts Demonstrated

  • 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

Reference

Schaub, H. and Junkins, J. L., Analytical Mechanics of Space Systems, 4th ed., AIAA Education Series, 2018.

About

6-DOF spacecraft attitude dynamics and control simulation for a Mars nanosatellite with autonomous mode switching

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages