Generated reference › Attitude Dynamics — Robotics/Spacecraft Dynamics
kind: generated#block#robotics-spacecraft-dynamics

Attitude Dynamics — Robotics/Spacecraft Dynamics

Robotics/Spacecraft_Dynamics/Attitude_Dynamics · 3 input / 2 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Description#

The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.

Attitude Dynamics

Robotics / Spacecraft Dynamics

A spacecraft's rotation in inertial (ICRF) axes: its attitude quaternion and body rates, driven by the applied body moments and, optionally, the central body's gravity-gradient torque. With q the attitude (ICRF to body, scalar first), ω the body rates and I the inertia, q′ = ½Ω(ω)q and ω′ = I−1(M + Mgg − ω × Iω), where Mgg = 3μ/|X|5 (Xb × IXb) and Xb is the position in body axes. Unlike 6DOF (Quaternion) there is no translation here and no normalization term in the quaternion kinematics, and the torque depends on where the spacecraft is.

Ports

  • X – the position from the central body's centre, [3,1], ICRF, in the chosen Units. Only the gravity gradient reads it, and it must be nonzero while that is on.
  • V – the velocity, [3,1], ICRF. It moves nothing in this frame and is there so the port list matches the Simulink block's.
  • M – the applied moments in body axes, [3,1], in units consistent with the inertia (N·m with kg·m²).
  • q – [4,1]: the attitude quaternion, ICRF to body, scalar first, in the Aerospace Toolbox's convention (quat2dcm(q) maps ICRF vectors into body axes).
  • w – [3,1]: the body rates, in the Angle Units per second.

Parameters

  • Inertia – the inertia tensor, a [3,3] with a nonzero determinant. Defaults to Simulink's diag(0.2273, 0.2273, 0.004).
  • Initial Attitude – the starting quaternion, four numbers, normalized before use. Defaults to [1 0 0 0]. Give a unit quaternion: Simulink normalizes a non-unit one for its first output, but its first integration step then departs from the normalized start by a small constant offset (measured: 3.3×10−7 in q for |q0| = 0.88), which this block, starting from q0/|q0|, does not reproduce.
  • Initial Attitude Rate – the starting body rates, three numbers in the Angle Units per second. Defaults to [0 0 0].
  • Gravity Gradient – on (the default) adds the central body's gravity-gradient torque; off leaves only M.
  • Central Body – whose μ the gradient uses: Earth (3.986004418×1014 m³/s², the default), Moon, Mercury, Venus, Mars, Jupiter, Saturn, Uranus, Neptune, Sun, or Custom.
  • Custom Gravitational Parameter – μ for a Custom body, in the chosen length unit cubed per second squared, taken as given. Defaults to 4.2828314258067×1013.
  • Units – the length unit of X (and V):
    • Metric (m/s) – metres. The default.
    • Metric (km/s) – kilometres.
    • Metric (km/h) – kilometres.
    • English (ft/s) – feet.
    • English (kts) – nautical miles.
    A named body's μ is converted to the unit, so the unit changes nothing but how X is read.
  • Angle Units – Degrees (the default) or Radians, for the initial rate and the w output.
  • Integration Substeps – M, how many fourth-order Runge-Kutta steps a sample is integrated with on the discrete solver and in exported code, a whole number from 1 to 100000. Defaults to 100. No Simulink counterpart.
  • Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.

Code export

All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text. A core holds the seven states, publishes the two outputs from them, and integrates one sample with the inputs held and M Runge-Kutta substeps – with M = 100, the same computation as Simulink's fixed-step ode4 at one hundredth of the sample time. The inertia's inverse and 3μ in the chosen unit are folded to constants.

The three HDL targets are simulation-only real arithmetic, quantized at the port. Q16.16 ports hold nothing beyond about ±32767, so with the gravity gradient on give X in kilometres or nautical miles, never metres or feet.

Simulink bridge

Import and export, mapped to Aerospace Blockset's aerolibsatdyn/Attitude Dynamics: Inertia → inertia, Initial Attitude → attitude, Initial Attitude Rate → attitudeRate, Gravity Gradient → useGravGrad, Central Body → centralBody, Custom Gravitational Parameter → customMu, Units → units and Angle Units → angleUnits, all 1:1 and lossless. Always written, with no configuration behind them: momentsIn on, dateOut off, stateFrame and attitudeFrame ICRF, attitudeFormat Quaternion, massType Fixed, outputTransform off and cbPoleSrc Dialog (so a Custom body does not add a port). The Fixed-frame, NED and LVLH frames, the DCM and Euler-angle formats and the variable-mass models do not cross: each needs a date, the central body's rotation or a mass flow, which this block does not model. Mass does not cross either – a fixed mass does not enter the rotation. The Simulink block is continuous and defines no SampleTime.

Notes

  • Stateful, continuous and nonlinear: seven continuous states. The outputs are states, so the block has no direct feedthrough and a loop through it is not an algebraic loop.
  • No normalization term: Simulink's block integrates the plain quaternion kinematics (measured: adding the 6DOF block's K(1 − |q|²)q makes the comparison 500 times worse), so |q| drifts at the integrator's truncation level, as it does there.
  • A non-unit initial attitude is the one known difference: see Initial Attitude.
  • Verified against R2026a: under the same fourth-order Runge-Kutta map, this block's derivative follows the Simulink block to 2.4×10−15 in q and 2.7×10−15 deg/s in w over 200 steps with a non-diagonal inertia, time-varying moments, a moving position and the gravity gradient on.

Code facts#

FactValue
registered typeRobotics/Spacecraft_Dynamics/Attitude_Dynamics
familyRobotics/Spacecraft_Dynamics
solver environment classICoreBlock_0_Robotics_1_Spacecraft_Dynamics_2_Attitude_Dynamics
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Spacecraft_Dynamics/Attitude_Dynamics/ICoreBlock_0_Robotics_1_Spacecraft_Dynamics_2_Attitude_Dynamics.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Spacecraft_Dynamics/Attitude_Dynamics/ICoreBlock_0_Robotics_1_Spacecraft_Dynamics_2_Attitude_Dynamics.h
default size on canvas150 × 100 px
ports at insert3 in, 2 out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDoubleX
2inICoreDoubleV
3inICoreDoubleM
4outICoreDoubleq
5outICoreDoublew

Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.

Configuration variables#

Config variableDefaultSimulink parameter
Inertia[0.2273 0 0; 0 0.2273 0; 0 0 0.004]inertia
Initial Attitude[1 0 0 0]attitude
Initial Attitude Rate[0 0 0]attitudeRate
Gravity Gradienton%~%off~~onuseGravGrad
Central BodycomboOf(bodies, 11, "Earth")centralBody
Custom Gravitational Parameter4.2828314258067e13customMu
UnitscomboOf(units, 5, "Metric (m/s)")units
Angle UnitsDegrees%~%Radians~~DegreesangleUnits
Integration Substeps100not crossed

Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.

supportSupport::Both
Simulink pathaerolibsatdyn/Attitude Dynamics
port-count rulePortsParam::None
SampleTime parameterno — the counterpart defines none; the rate stays on the ICore side
deliberately not crossedIntegration Substeps
always setmomentsIn = on, dateOut = off, stateFrame = ICRF, attitudeFrame = ICRF, attitudeFormat = Quaternion, massType = Fixed, outputTransform = off, cbPoleSrc = Dialog
ICore configSimulink parameterValue translation
Inertiainertiapasses through
Initial Attitudeattitudepasses through
Initial Attitude RateattitudeRatepasses through
Gravity GradientuseGravGradon → on, off → off
Central BodycentralBodyEarth → Earth, Moon → Moon, Mercury → Mercury, Venus → Venus, Mars → Mars, Jupiter → Jupiter, Saturn → Saturn, Uranus → Uranus, Neptune → Neptune, Sun → Sun, Custom → Custom
Custom Gravitational ParametercustomMupasses through
UnitsunitsMetric (m/s) → Metric (m/s), Metric (km/s) → Metric (km/s), Metric (km/h) → Metric (km/h), English (ft/s) → English (ft/s), English (kts) → English (kts)
Angle UnitsangleUnitsDegrees → Degrees, Radians → Radians

Caveat (shown to the user): rotation only, in ICRF: stateFrame and attitudeFrame are always ICRF and the attitude a quaternion, because the other frames and formats need a date or the central body's rotation. momentsIn on and dateOut off fix the ports at X, V, M in and q, w out; cbPoleSrc is Dialog so a Custom body does not add a port. A fixed mass does not enter the rotation, so mass does not cross; the variable-mass models do not either. "Integration Substeps" is how this block integrates a sample and has no counterpart. The Simulink block is continuous and has no SampleTime

Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h

Description vs code#

The checker has a blind spot here — it could not resolve something (a grouped port bullet, a computed config name), which is reported and never counted as a pass. A reader has to settle it:

  • B0 every stimulus in the sample errored — cross-checks skipped

The verdict above is tools/docs/check_block_descriptions.py (P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.

File banner (developer view)#

The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).

Attitude Dynamics -- a spacecraft's rotation in inertial axes States: the attitude quaternion q = [q0 q1 q2 q3] (ICRF to body, scalar first) and the body rates w = [p q r] in rad/s. Inputs: the position X (ICRF, from the central body's centre), the velocity V (ICRF; unused in this frame) and the applied body moments M.

q' = 0.5 * Omega(w) q (Hamilton; NO normalization term) w' = I^-1 (M + Mgg - w x (I w)) Mgg = 3 mu / |X|^5 * (Xb x (I Xb)), Xb = quat2dcm(q) X (gravity gradient, optional)

MEASURED AGAINST R2026a's aerolibsatdyn/Attitude Dynamics, 2026-09-11 (a built-in block, so measured, not read), with fixed-step ode4 and inputs held over the step:

  • this derivative under the same RK4 map follows the block to 2.4e-15 in q and 2.7e-15 deg/s

in w over 200 steps with a non-diagonal inertia, a non-trivial attitude, time-varying moments and a moving position, gravity gradient on, Earth and Moon;

  • ⚠ NO NORMALIZATION TERM. The 6DOF (Quaternion) block's K(1 - |q|^2) q is NOT here: with it

the same comparison is 1.25e-12 in q, 500 times worse; without it, rounding.

  • the gravitational parameters are the Orbit Propagator's (EGM2008 Earth 3.986004418e14, and

so on -- the same toolbox tables, confirmed body by body through a strong gradient);

  • Units only scale the position, so for a named body mu is converted to the length unit and

the dynamics are unchanged (km against m: identical to the last bit); a Custom body's mu is taken in the chosen length unit cubed per second squared, as given (measured in km and ft);

  • the initial attitude's FIRST OUTPUT is normalized (a [0.9 0.1 0.2 -0.1] starts at |q| = 1

exactly), but ⚠ a non-unit one is not simply normalized: the block's first integration step then leaves the normalized path by a constant offset -- 3.3e-7 in q for |q0| = 0.88, 1.1e-6 for |q0| = 1.77, the same at every later sample, w untouched -- which no normalization, renormalization or K(1 - |q|^2) gain reproduces (K from 0 to 1e4 scanned). This block starts from q0/|q0|; a unit q0 makes the two identical;

  • the initial rate and the w output are in the Angle Units per second;
  • V moves nothing in the ICRF frame (a doubled velocity changes w by exactly 0).

NOT A DUPLICATE OF 6DOF (Quaternion) (Equations_Of_Motion/EOM_6DOF_Quaternion): that block is body-axis translation AND rotation from force and moment, with no torque that depends on where the vehicle is. This one is rotation only, in inertial axes, with the central body's gravity gradient; it reuses that family's integrator (ICoreEomRk4) and its direction-cosine and inverse-inertia arithmetic.

CONTINUOUS, STATEFUL, NONLINEAR; no direct feedthrough.

Sample results#

No stimulus produced a sampled output in this rig — Invalid input size at Attitude Dynamics block: ICore Blocks/Home/Attitude Dynamics. That is a fact about the single-block rig, not a verdict on the block: an offline batch fit, a block whose output only appears at onSolverFinish, or one that needs a driven environment cannot be exercised alone.

Category unsampled · sample time 0.1 · 60 steps · commit 93133d604 · produced by docsSample --out <folder> --blocks Gain_Scheduled_Lead_Lag Controller_1D Controller_Blend_1D Controller_2D Controller_3D Observer_Form_1D Self_Conditioned_1D Line_Of_Sight_Access Orbit_Propagator_Kepler Attitude_Dynamics Attitude_Profile_Nadir_Pointing Attitude_Profile_Geographic_Pointing Multitaper_PSD Cross_Power_Spectral_Density Transfer_Function_Estimate Envelope_Spectrum Compose_String Scan_String --steps 60

Sample data: docs/generated/samples/Robotics__Spacecraft_Dynamics__Attitude_Dynamics.json