Quaternion To Euler — Robotics/Orientation 3D
Robotics/Orientation_3D/Quaternion_To_Euler · 1 input / 3 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 To Euler
Robotics / Orientation 3D
Converts a scalar-first quaternion [w x y z]T into the three ZYX intrinsic Euler angles – yaw, pitch, roll, in radians:
- pitch = asin(clamp(2(w·y − z·x), −1, +1))
- roll = atan2(2(w·x + y·z), 1 − 2(x² + y²))
- yaw = atan2(2(w·z + x·y), 1 − 2(y² + z²))
This is the exact inverse of Euler To Quaternion and reads the same convention: yaw about Z first, then pitch about the new Y, then roll about the new X.
Ports
- q – the orientation as a [4,1] column [w x y z]T, scalar-first. Assumed to be a unit quaternion; see the Notes for what a non-unit one does.
- yaw – rotation about Z, [1,1] radians in (−π, π].
- pitch – rotation about the new Y, [1,1] radians in [−π/2, π/2].
- roll – rotation about the new X, [1,1] radians in (−π, π].
The port order is (yaw, pitch, roll), matching Euler To Quaternion's inputs, so the two chain straight through.
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 orientation arrives on the port.
The three HDL targets are simulation-only real
arithmetic, not synthesizable Q16.16: there is no fixed-point asin or
atan2 to call. Quantization happens only at the port boundary.
PLC Structured Text has no atan2, so both of the atan2 angles
are rebuilt from ATAN with the quadrant reconstruction – the
same one Cartesian To Spherical uses, and it returns the identical value
including at the origin.
Simulink bridge
None, and the reason is measured rather than assumed: Simulink's
quaternion-to-Euler conversions ship in the Aerospace Blockset and the
Robotics System Toolbox, and neither is installed on this machine
(aero, aeroblks, robotics,
nav and fusion are all absent from
matlabroot/toolbox). A model carrying this block exports with the
block reported rather than silently dropped.
Notes
- Algebraic and stateless: the output depends only on the current input, so the block cannot break an algebraic loop.
- The round trip returns the WRAPPED angles, not the original numbers. Euler To Quaternion accepts any real angle, while the ranges above are what asin and atan2 can return – so a yaw of 3.4 rad comes back as 3.4 − 2π. That is the same orientation under a different representative, not a loss of accuracy.
- The asin argument is clamped to [−1, +1], by specification. For an exactly unit quaternion it already lies there; rounding in any backend, and Q16.16 quantization in the HDL ones, push it outside as |pitch| approaches π/2. Unclamped that is NaN in most targets, a complex number in MATLAB, and an assertion that aborts the simulation in VHDL. Clamped it is ±π/2, which is the correct answer.
- Gimbal lock is a property of Euler angles, not of this block. At |pitch| = π/2 only yaw ± roll is determined and the split between the two is arbitrary; near it, a small change in q swings both by a large amount. Whatever the formulas return there is convention. Keep a quaternion – or a rotation matrix, via Quaternion To Rotation Matrix – if the application passes through ±90° pitch.
- A non-unit quaternion is accepted and the formula as written is the contract. The 1 − 2(…) terms assume ‖q‖ = 1; for a scaled q the angles are those of the formula rather than of any rotation. Normalize with Normalizer (L2) if a long product chain has let the norm drift.
- Nonlinear, so deliberately no state space – a fabricated linear form would let model reduction merge matrices that do not describe this block.
Code facts#
| Fact | Value |
|---|---|
| registered type | Robotics/Orientation_3D/Quaternion_To_Euler |
| family | Robotics/Orientation_3D |
| solver environment class | ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_To_Euler |
| source | src/ICoreSDK/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Quaternion_To_Euler/ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_To_Euler.cpp |
| header | src/ICoreSDK/ICoreBlockLibrary/Blocks/Robotics/Orientation_3D/Quaternion_To_Euler/ICoreBlock_0_Robotics_1_Orientation_3D_2_Quaternion_To_Euler.h |
| default size on canvas | 132 × 96 px |
| ports at insert | 1 in, 3 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 | yaw |
| 3 | out | ICoreDouble | pitch |
| 4 | out | ICoreDouble | roll |
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::None |
| Simulink path | — |
| port-count rule | PortsParam::None |
SampleTime parameter | yes |
Caveat (shown to the user): no Simulink equivalent available: the quaternion-to-Euler conversions ship in the Aerospace Blockset and the Robotics System Toolbox, neither of which is installed. Rebuild the conversion on the Simulink side from Trigonometric Function blocks, keeping the ZYX-intrinsic order and the scalar-first (w, x, y, z) Hamilton convention this block uses, and clamp the arcsine argument as this block does
Catalog contract: src/ICoreSDK/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:
B0every 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).
Quaternion To Euler — scalar-first [4,1] quaternion to ZYX-intrinsic (yaw, pitch, roll) pitch = asin(clamp(2*(w*y - z*x), -1, +1)) roll = atan2(2*(w*x + y*z), 1 - 2*(x*x + y*y)) yaw = atan2(2*(w*z + x*y), 1 - 2*(y*y + z*z))
The exact inverse of Euler_To_Quaternion, written with it as one job: the pair shares ONE convention, and the worth of either is its agreement with the other. See the header for the clamp (which is specification, not repair), the conventions, and the output ranges.
⚠ THE FIVE EXPRESSIONS BELOW ARE THE CONTRACT and are built ONCE, in eulerExprs(), from a caller-supplied spelling of the four components. Every one of the ten backends interpolates the SAME parenthesisation and the SAME term order; only the way a component is read and the way asin/atan2 are named differ. Floating-point arithmetic is not associative, so a backend that regrouped
2.0 * (w * y - z * x)would disagree in the last ulp on most samples -- a row that moves for a reason having nothing to do with the export.⚠ THE CLAMP IS SPELLED PER TARGET BUT IS THE SAME TOTAL FUNCTION. min/max where the language has them on doubles, a nested conditional where a header would otherwise be needed (C, C++), and a three-way branch in VHDL -- which is required there anyway, MATH_REAL.ARCSIN asserting rather than returning outside [-1, 1]. asin(+1) is exactly +pi/2 in IEEE double, so the branch that answers with the literal and the branch that calls ARCSIN(1.0) agree bit for bit.
⚠ atan2 IS GUARDED WHERE THE TARGET NEEDS IT. VHDL's MATH_REAL.ARCTAN(Y, X) asserts at the origin, and IEC 61131-3 has no atan2 at all -- both handled exactly as Cartesian_To_Spherical handles them, reused rather than re-derived. Both arguments reach (0, 0) only at gimbal lock, where 0 is as good an answer as any other; the other eight targets return 0 there natively.
No config of any kind, so no loadBlockConfig() call is needed anywhere: the generators bake in no constant and read no config map (§3's rule bites only blocks whose generators do).
Sample results#
No stimulus produced a sampled output in this rig — Invalid input size at Quaternion To Euler block: ICore Blocks/Home/Quaternion To Euler. 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 ccf005c8 · produced by docsSample --out <folder> --steps 60
Sample data: docs/generated/samples/Robotics__Orientation_3D__Quaternion_To_Euler.json