# Architecture

## System Overview

Project Aleph is split into three cooperating layers:

1. Embedded flight computer firmware on Teensy 4.1.
2. Ground dashboard for live monitoring, command uplink, and replay.
3. Desktop telemetry simulator for software-only integration tests.

## Firmware Data Flow

1. Sensor reads:
   - Barometer altitude and temperature.
   - IMU acceleration and angular velocity.
2. Navigation update:
   - Position estimated from altitude.
   - Vertical velocity estimated from altitude delta and dt.
3. Event management:
   - Liftoff/ascent detection.
   - Apogee detection with consecutive-frame confirmation.
   - Drogue and main deployment decisions.
4. Control:
   - Reaction wheel control (manual or computed).
   - Rogallo deployment sequence in MAIN phase when enabled.
5. Outputs:
   - Telemetry stream over serial.
   - Logging to SD.
   - Pyro manager updates each loop.

## State Machine

Primary states:

- NOT_READY
- IDLE
- ARMED
- ASCENDING
- DROGUE
- MAIN
- LANDED

Transition highlights:

- IDLE -> ASCENDING when altitude exceeds BARO_ASCENDING_TRIGGER.
- ASCENDING -> DROGUE when altitude drop exceeds BARO_DROP for 3 consecutive checks.
- DROGUE -> MAIN when altitude <= BARO_MAIN_DEPLOY and time gate elapsed.
- MAIN -> LANDED when low altitude and vertical rate indicate terminal descent completion.

## Timing

- Main loop target: 100 Hz via timeStepUpdate().
- Telemetry period: 1000/FPS ms.
- Logging period: 1000/FAST_LOG_RATE ms.

## Communications

- Inbound command path: serial line parser in firmware.
- Outbound telemetry format:
  altitude;baro_apogee;acc_x;acc_y;acc_z;gyro_x;gyro_y;gyro_z;battery;temperature;state;rogallo;rw

## Reliability Controls Added

- Consecutive-frame confirmation before drogue deployment.
- Main deployment guard with minimum post-drogue delay.
- Millis rollover-safe comparisons for pyro/cansat timing manager logic.
- Replay/live separation and clean shutdown in dashboard runtime.

## Gaps and Future Work

- Replace blocking stepper operations in rogallo driver with non-blocking state machine.
- Integrate robust sensor fusion (EKF/complementary filter) and explicit attitude pipeline.
- Add automated validation for state transitions and deployment gating.
