Quaternion Modulus — Robotics/Orientation 3D
Robotics/Orientation_3D/Quaternion_Modulus · 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 Modulus
Robotics / Orientation 3D
The modulus – the length – of a quaternion stored scalar-first as [w x y z]T:
- |q| = √(w² + x² + y² + z²)
This is the block with the square root. The companion, Quaternion Norm, stops at the sum of squares and answers |q|². 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.9327… and Quaternion Norm answers 0.87.
A quaternion carrying a rotation should have modulus 1; this is the block that checks it, and Quaternion Normalize is the one that restores it. Where the square is what is wanted – dividing by it, as an inverse does – reach for Quaternion Norm instead, which is exact where this one takes a root.
Ports
- q – the quaternion, a [4,1] column [w x y z]T. The size is fixed: a quaternion is four numbers.
- |q| – the modulus, 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.
On the three HDL targets the block is offered as simulation-only, and the limitation is narrower than that phrase usually means: the sum of squares is genuine synthesizable Q16.16, and it is the square root alone that is taken by converting to a real, rooting, and converting back. A Q16.16 datapath has no square root, and a CORDIC one is a hardware design rather than something a code generator should invent. This is the same choice the Sqrt block makes, for the same reason. The exported core simulates correctly; it is not offered as synthesizable.
Simulink bridge
Both directions, onto aerolibutil/Quaternion Modulus
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
Modulus; 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, like Quaternion Norm and unlike the rest of the family: a sum of four squares does not care which slot holds the scalar part.
- 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.
- The root is exact only where the sum is. Over a long chain of products the sum of squares carries the rounding of every one of them; comparing |q| against 1 to decide whether a quaternion is still unit should use a tolerance, never equality.
Code facts#
| Fact | Value |
|---|---|
| registered type | Robotics/Orientation_3D/Quaternion_Modulus |
| family | Robotics/Orientation_3D |
| solver environment class | ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Modulus |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Quaternion_Modulus/ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Modulus.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Quaternion_Modulus/ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_Modulus.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 | \|q\| |
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\nModulus |
| 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 takes the square ROOT of the sum of squares; its Norm block, which stops at the sum, 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 Modulus — |q| = sqrt(w^2 + x^2 + y^2 + z^2) A [4,1] scalar-first quaternion in, a [1,1] scalar out. WITH the square root: the block that stops at the sum of squares is Quaternion_Norm.
MEASURED against aerolibutil/Quaternion Modulus (R2026a, 2026-09-09): q = [0.3 0.5 -0.7 0.2] answers 0.93273790530888145, and sqrt(0.87) = 0.93273790530888145 to the last bit. The same probe put Quaternion Norm at 0.87 exactly, which is what settles which word the Aerospace Blockset attaches to which operation -- the two are used the other way round often enough that guessing was never an option.
⚠ THE SUMMATION ORDER IS THE CONTRACT, as on Quaternion_Norm: all ten backends accumulate w, x, y, z left to right and take the root once, at the end. Rooting a differently grouped sum would disagree in the last ulp on most samples.
⚠ SIMULATION-ONLY ON THE ROOT, in the three HDL targets only. The sum of squares is genuine Q16.16; the root converts to real, calls the language's sqrt and converts back -- the Sqrt block's choice, made for the same reason. Exactly one operation is not synthesizable, and the description says so where a user will read it.
⚠ 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.