# How the Apollo Guidance Computer Handles Inertial Measurement Unit (IMU) Data: A Deep Dive into AGC Assembly Code

> Explore how the Apollo Guidance Computer processes IMU data through alignment and drift compensation using Comanche055 flight software and gyroscope counters. Learn AGC assembly code details.

- Repository: [Chris Garry/Apollo-11](https://github.com/chrislgarry/Apollo-11)
- Tags: deep-dive
- Published: 2026-03-04

---

**The Apollo Guidance Computer processes IMU data through a real-time pipeline of zeroing, coarse alignment, fine alignment, and continuous drift compensation, using three gyroscopic rate counters (CDUX, CDUY, CDUZ) managed by the Comanche055 flight software.**

The Apollo Guidance Computer (AGC) served as the digital brain of the Apollo 11 mission, processing critical sensor data to navigate to the Moon and back. Central to this capability was how the AGC handles Inertial Measurement Unit (IMU) data—a continuous stream of gyroscopic measurements that required real-time zeroing, alignment, and error compensation. This analysis examines the actual assembly source code from the **chrislgarry/Apollo-11** repository to reveal the precise mechanisms governing IMU data processing in the Comanche055 (Colossus 2A) flight software.

## IMU Architecture and Data Registers

The AGC treats the Inertial Measurement Unit as a set of three gyroscopic rate counters designated **CDUX**, **CDUY**, and **CDUZ** (Control Display Unit X, Y, Z). These registers reside in the AGC's erasable memory and represent the raw pulse counts from the IMU's gyroscopes. The system also monitors the **ICDU** (Inertial Control Data Unit) counters and **PIPAX/Y/Z** channels for pulse-integrating pendulum accelerometer data during alignment phases.

## The IMU Data Pipeline: From Zeroing to Torque Commands

Processing IMU data follows a strict state machine implemented across three primary assembly modules. The pipeline moves from initial zeroing through coarse and fine alignment stages, applying continuous drift compensation before generating final torque commands for spacecraft control.

### Mode Switching and Safety Checks

The `IMU_MODE_SWITCHING_ROUTINES.agc` file contains the central state machine that governs all IMU operations. Before processing any data, the AGC checks the **gimbal-lock** status bit (`DSPTAB +11D`) and the **IMUFAIL** flag (`IMODES30`). If the IMU is caged or faulted, the routine `ENDIMU` forces an alarm and aborts the operation.

Key routines in this module include:
- `IMUZERO` – Clears gyro counters and initializes the system
- `IMUCOARS` – Executes coarse alignment using star-tracker data
- `IMUFINE` – Performs fine alignment with drift compensation
- `IMUPULSE` – Generates torque command pulse trains
- `IMUSTALL` – Blocks execution until pulse completion

### Zeroing and Initialization

The `IMUZERO` routine establishes the baseline for all subsequent IMU data processing. When invoked, it disables interrupts with `INHINT` to ensure atomic operation, then checks for gimbal-lock conditions. If safe, it clears the **ICDU** counters via `ZEROICDU`, masks out error counters, and writes to channel 12 to disable coarse mode.

The routine then schedules a 320 ms wait using the `WAITLIST` mechanism to allow the AGS (Abort Guidance System) pulse train to settle before completing the zero operation. This timing-critical sequence ensures that subsequent gyro counts start from a known, stable zero reference.

### Coarse Alignment

During `IMUCOARS`, the AGC reads pulse counts from the **PIPAX**, **PIPAY**, and **PIPAZ** channels representing star-tracker observations. The routine scales these values using fixed-point multiplication (`MP BIT6` etc.) and constructs a provisional orientation matrix stored in the erasable bank `POSITON`.

This coarse alignment provides the initial attitude estimate required for fine alignment. The routine operates on pages 1423-1425 of the source and represents the first mathematical transformation of raw IMU data into spacecraft orientation.

### Fine Alignment

The `IMUFINE` routine refines the coarse attitude estimate by continuously sampling the gyro counters (`CDUX`, `CDUY`, `CDUZ`) and applying drift compensation. Implemented on pages 1427-1429, this routine integrates gyro rates over the alignment period, comparing the accumulated drift against the 2-degree tolerance threshold (`CORSCHK2`).

Fine alignment represents the most computationally intensive phase of IMU data processing, requiring double-precision arithmetic and careful management of the `GCOMPSW` and `DRIFTSUB` compensation routines to maintain attitude accuracy during the mission.

## Drift Compensation and Calibration

Raw gyro counts contain systematic errors from temperature variations, manufacturing tolerances, and mechanical drift. The `IMU_COMPENSATION_PACKAGE.agc` module addresses these errors through the `IMUCOMP` and `GCOMPSUB` routines.

The compensation process applies scale factors, removes bias terms, and corrects for drift using pre-computed coefficients stored as `NBDX`, `NBDY`, and `NBDZ`. The `GCOMPSUB` routine performs fixed-point multiplication of gyro pulse counts against these drift terms, then adds the correction to the attitude vector before it enters the navigation filter.

This continuous calibration ensures that accumulated gyro errors remain bounded during long-duration missions, preventing the attitude estimate from diverging over time.

## Torque Command Generation

When the guidance system commands a spacecraft maneuver, the AGC must convert the desired torque vector into physical gyro precession. The `IMUPULSE` routine (pages 1430-1432) handles this conversion by generating three separate pulse trains for the X, Y, and Z gyros.

The routine masks and scales the commanded torque values using `MP BIT8` and `MP BIT12`, then writes the resulting pulse counts to the gyro command channel (`CHAN14`). Each pulse train represents a specific angular impulse that precesses the gyroscope to align the IMU with the desired attitude.

Following pulse generation, `IMUSTALL` monitors the `LGYRO` busy flag to block program execution until the hardware completes the torque application. This synchronization ensures that subsequent IMU data reflects the new orientation before the guidance algorithm proceeds.

## Mathematical Transformation

The `IMU_CALIBRATION_AND_ALIGNMENT.agc` module contains the vector algebra routines that transform raw gyro counts into spacecraft attitude angles (θ, φ, ψ). Implemented across pages 423-455, these routines maintain the direction cosine matrix representing the spacecraft's orientation relative to inertial space.

The module uses double-precision arithmetic (utilizing the AGC's `EXTEND` mode) to compute attitude updates from integrated gyro rates. It implements the navigation filter that combines IMU data with optical sightings to produce the final state vector used for guidance computations.

## Summary

- The AGC processes IMU data through a dedicated pipeline in `Comanche055/IMU_MODE_SWITCHING_ROUTINES.agc`, treating the IMU as three gyroscopic rate counters (CDUX, CDUY, CDUZ).
- **Zeroing** via `IMUZERO` establishes a baseline by clearing ICDU counters and waiting 320 ms for hardware stabilization.
- **Coarse alignment** (`IMUCOARS`) uses star-tracker PIPA data to build an initial attitude matrix, while **fine alignment** (`IMUFINE`) refines this estimate by integrating compensated gyro rates.
- **Drift compensation** in `IMU_COMPENSATION_PACKAGE.agc` applies bias correction using coefficients NBDX, NBDY, and NBDZ to prevent attitude divergence.
- **Torque generation** via `IMUPULSE` converts navigation commands into gyro precession pulses written to `CHAN14`, synchronized by `IMUSTALL`.
- **Mathematical transformation** in `IMU_CALIBRATION_AND_ALIGNMENT.agc` implements the vector algebra converting gyro counts to spacecraft attitude angles using double-precision arithmetic.

## Frequently Asked Questions

### What are CDUX, CDUY, and CDUZ in the AGC?

CDUX, CDUY, and CDUZ are the Control Display Unit registers representing the three gyroscopic rate counters of the Inertial Measurement Unit. These 16-bit registers store raw pulse counts from the IMU's gyroscopes along the X, Y, and Z axes, serving as the primary input data for the AGC's attitude determination algorithms.

### How does the AGC prevent gimbal lock during IMU alignment?

The AGC prevents gimbal lock by checking the `DSPTAB +11D` status bit before initiating any alignment sequence. In `IMUZERO` and related routines, the code masks bits 4 and 6 to detect if the IMU is caged or in gimbal lock; if detected, the system triggers alarm 00206 and aborts the operation via `ENDIMU` to prevent erroneous attitude calculations.

### What is the difference between coarse and fine alignment in Apollo's IMU?

Coarse alignment (`IMUCOARS`) uses star-tracker pulse data (PIPAX, PIPAY, PIPAZ) to compute an initial rough attitude matrix stored in the `POSITON` erasable bank, providing an approximate orientation within several degrees. Fine alignment (`IMUFINE`) then refines this estimate by continuously sampling the gyro counters (CDUX, CDUY, CDUZ), applying drift compensation via `GCOMPSUB`, and integrating rates until the residual error falls below the 2-degree tolerance threshold (`CORSCHK2`).

### How does the AGC compensate for gyro drift during spaceflight?

The AGC compensates for gyro drift through the `IMU_COMPENSATION_PACKAGE.agc` module, specifically via the `GCOMPSUB` and `DRIFTSUB` routines. These routines apply pre-computed bias coefficients (`NBDX`, `NBDY`, `NBDZ`) to the raw gyro pulse counts using fixed-point multiplication, removing systematic errors caused by temperature variations and mechanical imperfections before the data enters the navigation filter.