Quaternion-Based Nonlinear Control — Attitude Stabilization Without Euler-Angle Singularities

Euler angles are intuitive, but spacecraft attitude control needs a representation that works globally. Quaternions avoid singularities and allow nonlinear attitude stabilization in full 3D.

This is the first full 3D attitude-control problem in the control progression.
Problem Setup

3D Spacecraft Attitude Stabilization

A spacecraft can rotate about all three body axes at the same time. Earlier control problems used simplified single-axis models, but real attitude stabilization requires a representation that remains valid for large rotations.

Goal:
stabilize the spacecraft from an arbitrary initial attitude to a desired target attitude.

The controller must reduce both attitude error and angular velocity:

$$ q \rightarrow q_{target} $$ $$ \omega \rightarrow 0 $$
Euler Limitation

Why Euler Angles Become Limiting

Roll, pitch, and yaw are useful for visualization, but they are not ideal for global spacecraft attitude control. Near certain rotations, Euler-angle descriptions can become singular.

Euler angles are intuitive for humans.
Quaternions are safer for control.
Quaternion State

Representing Attitude with a Unit Quaternion

A quaternion stores the spacecraft attitude using one scalar part and one vector part:

$$ q = [q_0, q_1, q_2, q_3] $$ $$ ||q|| = 1 $$

The quaternion evolves according to angular velocity:

$$ \dot{q} = \frac{1}{2}\Omega(\omega)q $$

In this page, the simulation integrates quaternion motion directly and normalizes the quaternion at every time step to preserve the unit constraint.

Quaternion Error

The Rotation Needed to Reach the Target

Quaternion control uses the error quaternion:

$$ q_e = q_{target}^{-1} \otimes q_{current} $$

The vector part of the error quaternion gives the correction direction. The scalar part helps represent the size of the rotation.

Nonlinear PD Control

Quaternion-Based Control Law

The nonlinear PD controller applies torque based on quaternion attitude error and angular velocity:

$$ \tau = -K_q q_{e,vec} - K_\omega \omega $$

The first term corrects orientation. The second term damps rotational motion.

Quaternion control = 3D attitude correction + angular velocity damping
Angular Velocity Damping

Why Damping Is Needed

Quaternion error tells the controller which direction to rotate, but angular velocity damping controls how smoothly the spacecraft stops rotating.

Without damping:
oscillation in 3D → continuous tumbling
With damping:
smooth convergence → physically realistic
Interactive Demo

Simulate 3D Quaternion Attitude Control

Adjust the initial attitude, target attitude, and gains. The simulation converts roll–pitch–yaw inputs into quaternions, computes quaternion error, applies nonlinear PD torque, and plots the attitude error, angular velocity, torque demand, and quaternion components.

Initial Attitude

Target Attitude

Control Gains

Engineering Metrics

Automatic Diagnostics

These metrics summarize whether the controller is smooth, aggressive, or too slow for the selected gains and attitude command.

Initial Rotation Error

Waiting...

Final Error Norm

Waiting...

Max Angular Velocity

Waiting...

Max Torque Demand

Waiting...

Settling Time

Waiting...

Takeaway

What This Problem Shows

Euler Angles

Useful for display, but not ideal for global spacecraft attitude control.

Quaternions

Represent 3D attitude without Euler-angle singularities.

Nonlinear PD

Uses quaternion error and angular velocity damping to stabilize orientation.

Euler angles are useful for visualization.
Quaternions are required for robust 3D control.
Control progression:
PD → PID → LQR → actuator limits → quaternion nonlinear control → MPC