A complete Python implementation of satellite attitude determination and control system simulation, including space environment models, rigid-body satellite dynamics, and attitude determination algorithms.
This project implements Assignment 3 requirements for a complete ADCS simulation environment. The system integrates:
- Space environment models: Sun vector calculation, IGRF-14 magnetic field model
- Rigid-body satellite dynamics: Quaternion kinematics, angular rate dynamics, gravity gradient torque
- Attitude Determination: TRIAD algorithm, Extended Kalman Filter (EKF), Weighted Least Squares (WLS) star tracker
- Attitude Control: PID controller for reaction wheel control
leo/
├── src/ # Source code
│ ├── attitude/ # Attitude determination algorithms
│ │ ├── triad.py # TRIAD algorithm
│ │ ├── ekf.py # Extended Kalman Filter
│ │ └── wls_startracker.py # Weighted Least Squares star tracker
│ ├── dynamics/ # Satellite dynamics and control
│ │ ├── rigid_body.py # Rigid body dynamics
│ │ ├── gravity_gradient.py # Gravity gradient torque
│ │ └── controller.py # PID controller
│ ├── environment/ # Space environment models
│ │ ├── sun_model.py # Sun vector calculation
│ │ └── igrf.py # IGRF-14 magnetic field model
│ └── utils/ # Utility functions
│ ├── quaternion.py # Quaternion operations
│ ├── coordinate_transforms.py # Coordinate transformations
│ └── numerical.py # Numerical methods (RK4, etc.)
├── tests/ # Test suite
│ ├── test_utils.py # Utility tests
│ ├── test_environment.py # Environment model tests
│ ├── test_dynamics.py # Dynamics tests
│ ├── test_attitude.py # Attitude algorithm tests
│ └── test_main.py # Integration tests
├── data/ # Data files
│ └── igrf14coeffs.txt # IGRF-14 coefficients
├── main.py # Main entry point with CLI
├── requirements.txt # Python dependencies
└── README.md # This file
- Python 3.8 or higher
- pip (Python package manager)
-
Clone or navigate to the project directory:
cd leo -
Install dependencies:
pip install -r requirements.txt
-
Ensure IGRF coefficient file is present:
- The file
igrf14coeffs.txtshould be in thedata/directory or project root - If missing, the IGRF model will raise an error with instructions
- The file
The main entry point supports running individual simulations or all simulations:
# Run TRIAD attitude estimation simulation
python main.py triad
# Run Extended Kalman Filter simulation
python main.py ekf
# Run WLS star tracker simulation
python main.py wls
# Run all simulations sequentially
python main.py allEach simulation generates:
- Console output: Summary statistics (RMS errors, etc.)
- Plot files: PNG images with results visualization
triad_results.png,triad_comparison.pngfor TRIADekf_attitude_error.png,ekf_quaternion.png,ekf_rates.pngfor EKFwls_angles.png,wls_errors.pngfor WLS
You can also import and use modules directly in Python:
from src.attitude.triad import run_triad_simulation
from src.attitude.ekf import run_ekf_simulation
from src.attitude.wls_startracker import run_wls_simulation
# Run TRIAD simulation
results = run_triad_simulation(noise_sigma_deg=2.0)
print(f"RMS error: {results['rms_deg']:.3f} deg")
# Run EKF simulation
results = run_ekf_simulation(t_end=600.0)
print(f"Final attitude error: {results['att_err_deg'][-1]:.3f} deg")
# Run WLS simulation
results = run_wls_simulation(dt=0.01, T_end=600.0)
print(f"Roll RMS: {results['stats']['phi_rms_deg']:.5f} deg")Run the test suite using pytest:
# Run all tests
pytest
# Run specific test file
pytest tests/test_utils.py
# Run with verbose output
pytest -v
# Run with coverage
pytest --cov=src- TRIAD: Two-vector attitude determination using gravity and magnetic field measurements
- Extended Kalman Filter: Full state estimation (quaternion, rates, gyro bias) with gyroscope and star tracker
- Weighted Least Squares: Small-angle attitude estimation from star tracker measurements
- Rigid Body Dynamics: Quaternion-based kinematics with Euler's equations
- Gravity Gradient: Torque computation for circular equatorial orbits
- PID Controller: Reaction wheel attitude control with anti-windup
- Sun Vector: Simplified solar position model in ECI frame
- IGRF-14: International Geomagnetic Reference Field model for magnetic field computation
- Quaternions: Hamilton convention, scalar-first format: q = [w, x, y, z]
- Rotation: DCM maps from inertial to body frame: v_body = R * v_inertial
- Euler Angles: 3-2-1 (ZYX) convention: R = Rz(yaw) * Ry(pitch) * Rx(roll)
- Coordinate Frames:
- ECI: Earth-Centered Inertial
- Body: Satellite body-fixed frame
- NED: North-East-Down (local geodetic)
- numpy: Numerical computations
- scipy: Advanced numerical methods (matrix exponentials, etc.)
- matplotlib: Plotting and visualization
- pytest: Testing framework
- All simulations use fixed random seeds for reproducibility
- The EKF implementation uses numerical Jacobian computation for robustness
- IGRF model supports both WIDE and LONG coefficient file formats
- Quaternion normalization is performed automatically to maintain unit quaternions
See LICENSE file for details.
- IGRF-14: International Geomagnetic Reference Field
- TRIAD algorithm: Classic two-vector attitude determination
- Crassidis, J. L., & Junkins, J. L. (2011). Optimal Estimation of Dynamic Systems
- Sidi, M. J. (1997). Spacecraft Dynamics and Control: A Practical Engineering Approach