Quaternion Norm — Robotics/Orientation 3D
Robotics/Orientation_3D/Quaternion_Norm · 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 Norm
Robotics / Orientation 3D
The squared norm of a quaternion stored scalar-first as [w x y z]T:
- n = w² + x² + y² + z²
There is no square root. That is the companion block, Quaternion Modulus, which answers √n. The two names are used the other way round in plenty of textbooks, so it is worth being blunt: on a quaternion [0.3 0.5 −0.7 0.2] this block answers 0.87 and Quaternion Modulus answers 0.9327….
This is the quantity an inverse divides by – q⁻¹ = q* / n – and the one a unit-quaternion check compares against 1. It is deliberately the cheaper of the pair: taking a root and squaring it back would cost precision for nothing.
Ports
- q – the quaternion, a [4,1] column [w x y z]T. The size is fixed: a quaternion is four numbers.
- n – the squared norm, a [1,1] scalar. Always non-negative, and zero only for the zero quaternion.
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.
The three HDL targets are genuinely synthesizable Q16.16, not simulation-only: four multiplies and three adds, with no division, square root or trigonometry anywhere. Verilog and SystemVerilog accumulate the four squares in a double-width register and shift back to Q16.16 once; VHDL accumulates in the shared Q16.16 process variable, so each square is resized as it is added and VHDL is the one that rounds soonest. The three therefore agree to within the low bits rather than bit-exactly.
One thing to size before exporting to hardware: n grows as the square of the quaternion's magnitude, so a quaternion of magnitude 180 already reaches the top of the Q16.16 range. Unit quaternions – the usual case – sit at 1 and have enormous headroom.
Simulink bridge
Both directions, onto aerolibutil/Quaternion Norm 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 Norm;
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.
- Insensitive to the scalar-first convention, and it is the only block in this family that is: a sum of four squares does not care which slot holds the scalar part, so a quaternion arriving under the JPL (scalar-last) order still gets the right answer here. Its siblings do not have that luxury.
- Deliberately no state space. The map is quadratic in the input, so there is no linear form to fabricate, and model reduction refuses a block whose feed-through is nonlinear.
- Never negative, in every backend including the fixed-point ones: it is a sum of squares. A negative reading is a saturated Q16.16 accumulator, not arithmetic.
Code facts#
| Fact | Value |
|---|---|
| registered type | Robotics/Orientation_3D/Quaternion_Norm |
| family | Robotics/Orientation_3D |
| solver environment class | ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Norm |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Quaternion_Norm/ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Norm.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Quaternion_Norm/ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Norm.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 | n |
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\nNorm |
| 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. It computes the SQUARED norm; its Modulus block, which takes the root, is a different Simulink block and a different ICore one. 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 Norm — n = w^2 + x^2 + y^2 + z^2, the SQUARED norm A [4,1] scalar-first quaternion in, a [1,1] scalar out. No square root: that is the sibling block, Quaternion_Modulus.
MEASURED against aerolibutil/Quaternion Norm (R2026a, 2026-09-09): q = [0.3 0.5 -0.7 0.2] answers 0.87, and 0.3^2 + 0.5^2 + 0.7^2 + 0.2^2 = 0.09 + 0.25 + 0.49 + 0.04 = 0.87. The same probe put Quaternion Modulus at 0.93273790530888145 = sqrt(0.87), which is what settles which of the two words the Aerospace Blockset attaches to which operation.
⚠ THE SUMMATION ORDER IS THE CONTRACT. Floating-point addition is not associative, so all ten backends accumulate w, then x, then y, then z, left to right, exactly as the reference does. It costs nothing to keep them identical, so they are kept identical -- a backend that grouped the four squares differently would disagree in the last ulp on most samples, which is a row that moves for a reason having nothing to do with the export.
⚠ 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.