Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches: [main, cleanup]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Lint with ruff
run: ruff check .

- name: Run tests
run: pytest -v
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
**/build/
**/.cache/
**/sdkconfig
**/sdkconfig.old
**/*.a
**/*.bin
**/*.map
Expand All @@ -21,7 +22,36 @@ __pycache__/
.venv/
venv/
*.egg-info/
*.egg
dist/
build/
*.whl

# Pytest / Ruff
.pytest_cache/
.ruff_cache/

# OS
.DS_Store
Thumbs.db

# Generated simulation output (not reference data)
# Reference CSVs in scenarios/data/ are tracked
*.csv.tmp

# Private agent configuration (OpenCode skills, agents, config)
.opencode/

# Secrets and credentials
.env
.env.*
*.secret
*.key
*.pem
secrets/
credentials.json
service-account*.json

# Simulation scratch / local state
*.npz
data/*.csv.tmp
162 changes: 114 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,140 @@
## Mission Control Suite `/mission-control`
# Project Aphelion

| Module | Status | Description |
|---|---|---|
| `propagator/` | In Progress | 3DOF RK4 trajectory propagator with drag and gravity models |
| `state-estimator/` | Planned | Extended Kalman Filter for 6-DOF state estimation |
| `monte-carlo/` | Planned | Dispersion analysis — 1000+ runs, landing footprint scatter plots |
| `ground-station/` | Planned | Flask dashboard, MQTT telemetry receiver, real-time visualisation |
A flight dynamics testbed for trajectory simulation, numerical methods, and embedded flight hardware.

### 3DOF Trajectory Propagator Engine
Project Aphelion is an evolving engineering project. It currently combines a Python suborbital trajectory simulator with an ESP32 flight computer prototype. The long-term plan runs from suborbital propagation through orbital mechanics, telemetry, and hardware-in-the-loop testing, but the near-term work is about getting the numerical core solid and validated.

The core analytical engine of the Mission Control Suite predicts suborbital flight profiles by evaluating instantaneous flight dynamics. Instead of assuming constant acceleration, the solver evaluates changing force boundaries across discrete time steps ($\Delta t = 0.01\text{s}$) using a 4th-Order Runge-Kutta numerical integrator.
## Current Status

For a given kinematic state vector $\mathbf{x} = [x, y, z, v_x, v_y, v_z]^T$, the solver computes four distinct intermediate derivative vectors ($k_1, k_2, k_3, k_4$) to approximate the state update with high-order local accuracy with local accuracy of $\mathcal{O}(\Delta t^5)$:
**Level 0: Foundations** (September 2026)

$$k_1 = f(t, \mathbf{x})$$
$$k_2 = f\left(t + \frac{\Delta t}{2}, \mathbf{x} + \frac{\Delta t}{2}k_1\right)$$
$$k_3 = f\left(t + \frac{\Delta t}{2}, \mathbf{x} + \frac{\Delta t}{2}k_2\right)$$
$$k_4 = f(t + \Delta t, \mathbf{x} + \Delta t k_3)$$
What exists now:

$$\mathbf{x}_{n+1} = \mathbf{x}_n + \frac{\Delta t}{6}(k_1 + 2k_2 + 2k_3 + k_4)$$
- A 3DOF suborbital trajectory propagator using RK4 integration
- Atmospheric drag and propellant mass depletion modelling
- YAML scenario configuration
- A Python package (`aphelion`) with a CLI
- A unit and validation test suite
- CI on GitHub Actions (Python 3.10 through 3.13)
- An ESP32 MPU6050 IMU driver, working on physical hardware

#### Active Vector Force Models
The propagator has validation tests against analytical solutions, but treat those as a work in progress. Full propagator validation is the Level 1 milestone.

1. **Gravitational Vector** ($\mathbf{F}_g$): Acts downwards along the local vertical axis:
### Baseline Scenario Statistics

$$\mathbf{F}_g = \begin{bmatrix} 0 \\ 0 \\ -m \cdot g_0 \end{bmatrix}$$
| Metric | Value |
|---|---|
| Apogee altitude | ~655 m |
| Flight time | ~25 s |
| Downrange distance | ~476 m |

2. **Aerodynamic Drag Vector** ($\mathbf{F}_D$): Directed exactly opposite to the instantaneous velocity unit vector ($\hat{v}$). It references an exponential atmospheric density decay model based on altitude:
These come from `scenarios/suborbital-baseline.yaml`, which describes a small suborbital flight.

$$\mathbf{F}_D = -\frac{1}{2} \rho(z) \\|\mathbf{v}\\|^2 C_D A \cdot \left(\frac{\mathbf{v}}{\\|\mathbf{v}\\|}\right)$$
## Quick Start

$$\rho(z) = \rho_0 \cdot e^{-z/h_{scale}}$$
```bash
pip install -e ".[dev]"

3. **Mass Depletion Curve ($\dot{m}$):** During the powered phase ($t < 3.5\text{s}$), vehicle mass updates continuously as propellant is exhausted ($m(t) = m_{dry} + m_{prop} - \dot{m}t$). Because the nominal thrust remains constant while the vehicle mass strips away, the rocket experiences an escalating thrust-to-weight ratio, causing a characteristic spike in acceleration immediately prior to motor burnout.
# Run the baseline simulation
aphelion run --scenario scenarios/suborbital-baseline.yaml

---
# Or equivalently
python -m aphelion --scenario scenarios/suborbital-baseline.yaml

### Verification and Operational Profiles
# Run tests
pytest

Below are the analytical outputs generated from a baseline sounding rocket profile configuration (Dry Mass: 1.0 kg, Propellant: 0.3 kg, Nominal Thrust: 80 N, Burn Time: 3.5s) launches at an initial pitch angle of $85^\circ$.
| 1. Altitude Telemetry Matrix | 2. Downrange Spatial Profile (X vs Z) |
|---|---|
| ![Altitude Profile](media/plots/altitude_profile.png) | ![Spatial Profile](media/plots/spatial_profile.png) |
| **Analysis:** Tracks transition from active booster burn to a ballistic coast phase. Peak operational apogee of **~700 meters** is achieved at $t \approx 11.5\text{s}$. | **Analysis:** Maps the actual 2D path across the range. Tilted lift-off vectors result in a terminal impact coordinate **~460 meters** downrange from the launch pad. |
# Run linting
ruff check .
```

---
## Architecture

## Flight Computer Firmware `/firmware`
```
aphelion/ # Python package
├── core/ # Physical constants (constants.py)
├── dynamics/ # Numerical + propagator code
│ ├── integrators.py # RK4 integrator
│ └── suborbital.py # 3DOF suborbital propagator
└── __main__.py # CLI entry point

**Active development:** `firmware/flight-computer/`
- Custom MPU6050 driver (ESP-IDF v5.2 Master Bus API, I2C at 400kHz)
- I2C integrity validation via WHO_AM_I handshake (`0x68` signature)
- Voltage divider ($1k\Omega / 2.2k\Omega$) for 5V→3.3V HC-SR04 logic level protection
- StateMachine: `IDLE → PRE_FLIGHT → ACTIVE → DESCENT → LANDED`
- Custom Vector3D class using zero dynamic memory allocation
scenarios/ # YAML simulation configs
tests/ # Unit + validation tests
firmware/ # ESP32 embedded code
├── flight-computer/
│ └── mpu6050-driver/ # Working MPU6050 I2C driver
└── archive/ # Historical learning exercises
docs/ # Docs, ADRs, dev logs
media/ # Plots and demo assets
```

`mission-control/propagator/targeter.py`
- iterative root-finding target to adjust launch angle
See [docs/architecture.md](docs/architecture.md) for details.

**Archived experiments:** `firmware/archive/` — early drivers and learning exercises
## Propagator

## Tech Stack
The propagator is a 3DOF trajectory model for suborbital launch vehicles:

- **Integration:** fixed-step 4th-order Runge-Kutta
- **Gravity:** constant g0, flat-Earth approximation
- **Atmosphere:** exponential density model
- **Drag:** quadratic aerodynamic drag with configurable Cd and area
- **Thrust:** constant thrust during the powered phase, aligned with velocity
- **Mass:** linear propellant depletion during the burn

### Limitations

These are intentional for the current level:

- Flat-Earth geometry (valid below ~100 km altitude)
- Constant gravitational field (no 1/r² variation)
- No wind model
- Thrust aligned with the velocity vector, not the body frame
- 3DOF, no rotational dynamics
- No orbital mechanics yet

## Hardware Prototype

An ESP32-WROOM board with an MPU6050 IMU:

**Flight Computer:** Embedded C++ · ESP-IDF v5.2 · FreeRTOS · ESP32-WROOM
**Mission Control:** Python · NumPy/SciPy · Matplotlib · Paho MQTT · Flask
**Hardware:** ESP32-WROOM · MPU6050 · BMP280 · HC-SR04 · Raspberry Pi 5
- I2C at 100 kHz (SDA: GPIO 21, SCL: GPIO 22)
- Reads 6-axis accelerometer + gyroscope + temperature
- Verified on physical hardware

This is a learning prototype, not flight software. It is the first piece of the flight computer, far from the eventual telemetry and ground-station system. See `firmware/flight-computer/mpu6050-driver/` and [docs/hardware.md](docs/hardware.md).

## Validation

The physics tests check the propagator against analytical results:

- Vertical free-fall: velocity and altitude match v(t) = v₀ - gt and h(t) = v₀t - ½gt²
- RK4 convergence: error drops at the expected 4th-order rate
- Energy conservation: specific mechanical energy is conserved in ballistic flight

All tests pass with relative tolerance ≤ 0.1%.

## Roadmap

| Level | Description | Status |
|---|---|---|
| 0 | Foundations: package, tests, CI | **Current** |
| 1 | Validated suborbital propagator | Planned |
| 2 | Two-body orbital propagator | Planned |
| 3 | Perturbation models (J2, drag, SRP) | Planned |
| 4 | Maneuver and mission modelling | Planned |
| 5 | Telemetry protocol and ground station | Planned |
| 6 | Mission control visualization | Planned |
| 7 | Attitude dynamics | Planned |
| 8 | Extended Kalman filter | Planned |
| 9 | Monte Carlo dispersion analysis | Planned |
| 10 | Hardware-in-the-loop | Planned |

## Tech Stack

## Dev Logs
- **Simulation:** Python 3.10+, NumPy, SciPy, Matplotlib, PyYAML
- **Testing:** pytest, ruff
- **Firmware:** C++, ESP-IDF v5.2, FreeRTOS
- **Hardware:** ESP32-WROOM-32D, MPU6050 IMU

Session notes in `/docs/dev-logs/` — tracking progress, debugging decisions,
and physics derivations as the project grows.
## License

---
MIT
3 changes: 3 additions & 0 deletions aphelion/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Project Aphelion: flight dynamics and spacecraft mission simulation/testbed."""

__version__ = "0.1.0"
Loading
Loading