Quaternion Normalize — Robotics/Orientation 3D
Robotics/Orientation_3D/Quaternion_Normalize · 1 input / 1 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.
Quaternion Normalize
Robotics / Orientation 3D
Scales a quaternion to unit length, keeping its direction:
- y = q / |q|, where |q| = √(w² + x² + y² + z²)
This is the step a quaternion integrator needs every sample. The product of two unit quaternions is unit in exact arithmetic; over a long chain of Quaternion Multiply blocks, rounding walks the modulus away from 1 and the rotation slowly stops being a rotation. Putting this block at the end of the chain puts it back.
The result is always unit (to within one rounding), whatever the input magnitude – so it is also the block to use when a quaternion has been assembled from measured components and its length means nothing.
Ports
- q – the quaternion to scale, a [4,1] column [w x y z]T. The size is fixed: a quaternion is four numbers.
- y – the unit quaternion, also [4,1], pointing the same way as q.
Parameters
- 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. There is no tunable parameter, because the block has no parameter at all – the quaternion arrives on a port.
Every backend takes one square root and one reciprocal, then multiplies all four components by that same reciprocal. Four independent divisions would be arithmetically equivalent and would round differently, so the shared reciprocal is part of the contract rather than an optimisation.
On the three HDL targets the block is offered as simulation-only, and the whole computation is what leaves fixed point, not just part of it: a Q16.16 datapath has neither a square root nor a division. Values are quantized at the port boundary and the arithmetic in between is real – the same choice Recursive IIR and Variable Transport Delay make. The core simulates correctly; it is not offered as synthesizable.
Simulink bridge
Both directions, onto
aerolibutil/Quaternion Normalize in the Aerospace
Blockset. The block has no configuration, so no parameter pairs cross.
Its name is drawn on two lines, so the real library path carries an
embedded newline between Quaternion and
Normalize; the flattened one-line spelling resolves to nothing. And
the block defines no SampleTime parameter, so the rate stays
on the ICore side and a block configured with an explicit positive rate reports
that the rate did not cross.
Notes
- Algebraic and stateless: the output depends only on the current input, so the block cannot break an algebraic loop.
- The zero quaternion has no answer, and the backends do not all give the same non-answer. The six software targets divide by zero and produce NaN; the three HDL targets produce zero, because fixed point has no NaN to produce. Nothing upstream is checked and no error is logged: a zero quaternion is a broken signal rather than a mode this block supports.
- Sign is preserved, not canonicalized. q and −q are the same rotation but different quaternions, and this block returns whichever hemisphere it was given. If a chain needs a canonical sign, that is a separate decision and a separate block.
- Deliberately no state space – the map is not linear, so there is no linear form to fabricate, and model reduction refuses a block whose feed-through is nonlinear.
Code facts#
| Fact | Value |
|---|---|
| registered type | Robotics/Orientation_3D/Quaternion_Normalize |
| family | Robotics/Orientation_3D |
| solver environment class | ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Normalize |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Quaternion_Normalize/ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Normalize.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Quaternion_Normalize/ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Normalize.h |
| default size on canvas | 112 × 70 px |
| ports at insert | 1 in, 1 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreDouble | q |
| 2 | out | ICoreDouble | y |
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#
No config variable beyond the Sampling Time (s) every block carries.
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.
Simulink bridge#
| support | Support::Both |
| Simulink path | aerolibutil/Quaternion\nNormalize |
| port-count rule | PortsParam::None |
SampleTime parameter | no — the counterpart defines none; the rate stays on the ICore side |
Caveat (shown to the user): the Aerospace Blockset block is a masked subsystem with no dialog parameters, so nothing but the signal crosses. Note it defines no SampleTime parameter: an ICore rate set explicitly stays on this side and is reported
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:
B0no sample under docs/generated/samples/ — nothing to cross-check (P8.1)
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).
Quaternion Normalize — y = q / |q|, scalar-first [4,1] The unit quaternion pointing the same way. MEASURED against aerolibutil/Quaternion Normalize (R2026a, 2026-09-09): q = [0.3 0.5 -0.7 0.2] answers [0.32163376045133846 0.53605626741889745 -0.75047877438645638 0.21442250696755899] = q / sqrt(0.87), to the last bit.
⚠ ONE ROOT AND ONE RECIPROCAL, NOT FOUR DIVISIONS. Every backend computes the sum of squares once, roots it once, and then multiplies the four components by the SAME reciprocal. Four independent divisions would be arithmetically equivalent and would round differently, which is a row that moves for a reason having nothing to do with the export. The reference does it this way and so does every one of the ten.
⚠ AT THE ZERO QUATERNION the six software targets divide by zero and produce NaN, exactly as the C++ reference does; the three HDL targets answer zero, because a fixed-point datapath has no NaN. That asymmetry is the Divide block's convention, and it is documented rather than papered over: a zero quaternion is a broken signal, not a mode this block supports.
⚠ SIMULATION-ONLY on the three HDL targets, and here the whole computation leaves fixed point rather than just the root: Q16.16 has neither a square root nor a division.
⚠ The Simulink counterpart has NO SampleTime parameter and its library path carries an EMBEDDED NEWLINE; both are measured, and both are written up on the catalog entry below.
Sample results#
No sample run is committed for this block. Samples come from the headless harness (DOCS_PLAN.md P8.1) into docs/generated/samples/; until one exists this block's behaviour is witnessed by the parity and export-verification suites, not by a plot here.