Generated reference › Cartesian To Keplerian Elements — Robotics/Spacecraft Dynamics
kind: generated#block#robotics-spacecraft-dynamics

Cartesian To Keplerian Elements — Robotics/Spacecraft Dynamics

Robotics/Spacecraft_Dynamics/Cartesian_To_Keplerian_Elements · 0 input / 0 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.

Cartesian To Keplerian Elements

Robotics / Spacecraft Dynamics

A position r and velocity v in a planet-centred equatorial frame, turned into the orbit they lie on. With h = r × v, the node vector n = k̂ × h and the eccentricity vector e = ((|v|² − μ/|r|)·r − (r·v)·v)/μ:

  • a = −μ/(2·ε), ε = |v|²/2 − μ/|r|
  • ecc = |e|, incl = acos(hz/|h|), RAAN = acos(nx/|n|)
  • argp = the angle from n to e, nu = the angle from e to r, arglat = the angle from n to r, truelon = the angle from the x-axis to r, lonper = the angle from the x-axis to e

Every angle is folded into [0, 2π) by testing a sign (ny, ez, r·v, rz, ry, ey) – the textbook algorithm, transcribed from measurements of the Simulink block rather than from a book, because where the two differ the block is what a model is compared against.

Ports

  • Position – r, a [3,1] column in the chosen length unit.
  • Velocity – v, a [3,1] column in the chosen speed unit.
  • a – the semi-major axis, [1,1], in the length unit. Negative on a hyperbola; on a parabola, the periapsis radius p/2.
  • ecc – the eccentricity, [1,1]. Reported as exactly 0 on a circular orbit and exactly 1 on a parabolic one (see Tolerance).
  • incl – the inclination, [1,1]. Reported as exactly 0 or π (180) on an equatorial orbit.
  • RAAN – the right ascension of the ascending node, [1,1].
  • argp – the argument of periapsis, [1,1]; elliptical inclined orbits only.
  • nu – the true anomaly, [1,1]; every non-circular orbit.
  • truelon – the true longitude, [1,1]; circular equatorial orbits only.
  • arglat – the argument of latitude, [1,1]; circular inclined orbits only.
  • lonper – the longitude of periapsis, [1,1]; non-circular equatorial orbits only.

An element that does not exist for the orbit's class is NaN – exactly what the Simulink block reports, in either of its port configurations; it substitutes nothing.

Parameters

  • Units – the length and speed units of r, v and a:
    • Metric (m/s) – metres, metres per second
    • Metric (km/s) – kilometres, kilometres per second
    • Metric (km/h) – kilometres, kilometres per hour
    • English (ft/s) – feet, feet per second
    • English (kts) – nautical miles, knots
    The inputs are converted to SI first, the arithmetic runs in SI, and a is converted back.
  • Angle Units – Degrees or Radians, for all seven angle outputs.
  • Central Body – Earth, Moon, Mercury, Venus, Mars, Jupiter, Saturn, Uranus, Neptune, Sun or Custom. Each named body carries its gravitational parameter μ, the same double the Simulink block uses (Earth 3.986004418e14 m³/s²).
  • Gravitational Parameter – μ, used only when Central Body is Custom, in the Units' own length cubed per second squared: m³/s² for Metric (m/s), km³/s² for both Metric (km/s) and Metric (km/h), and ft³/s² for both English units – so under English (kts) it is in feet while positions are in nautical miles. Measured; the Simulink dialog relabels its prompt the same way. Default 42828314258067, the Simulink dialog's own.
  • Tolerance – the band that decides the orbit's class, default 1e-12: circular when ecc < Tolerance, equatorial when incl or π − incl is below it (radians), parabolic when |ecc − 1| is below it. It ALSO decides RAAN: RAAN is reported only when |n| > Tolerance, and |n| is in SI units (m²/s) – an absolute test, not the inclination test, measured.
  • Open Or Undefined Orbit Action – None, Warning or Error, for a parabolic or hyperbolic orbit and for r and v with |r × v| ≤ 1e-6 m²/s (all nine outputs NaN). Warning reports each kind once per run; Error stops the run.
  • 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. Every parameter is baked into the arithmetic at export.

The three HDL targets are simulation-only: nine arccosines, five square roots and a division by μ do not belong in a Q16.16 datapath, so they compute in real and quantize only at the ports – which also bounds what can cross a port, ±32768, so rig or model an HDL export in kilometres or nautical miles. HDL and PLC Structured Text have no NaN: where the other targets write NaN they write 0.0, and the action config does not travel into any export.

Simulink bridge

Import and export, mapped to Aerospace Blockset's aerolibsatdyn/Cartesian State Vectors to Keplerian Orbital Elements (its library path carries an embedded newline before Keplerian). Units → units, Angle Units → angleUnits, Central Body → centralBody, Gravitational Parameter → customMu, Tolerance → tolerance and Open Or Undefined Orbit Action → action; every combo is Simulink's own list, so the mapping is lossless. outputPortConfiguration is always written as All – the nine ports this block has. The Simulink block has no SampleTime (measured), so the rate stays on the ICore side.

Notes

  • Algebraic and stateless; nonlinear, so no state space.
  • Measured, and bit-exact against R2026a on about 5000 state vectors over all five units, both angle units, all eleven bodies and five tolerances.
  • A parabola reports a = p/2 and ecc = 1, and its argp and nu then divide by 1 rather than by |e|. When a Tolerance is so wide that an orbit is both circular and parabolic, ecc reads 1.
  • A retrograde equatorial orbit reports truelon = 2π − acos(rx/|r|) and lonper = 2π − acos(ex/|e|) whatever the sign of ry or ey – ONE fold, where the textbook applies two. Measured on 128 samples.
  • Wide tolerances are how the special classes are reached on purpose: the verification rigs set Tolerance to 0.25 or 0.3 to put a whole run on the circular, equatorial or parabolic branch.

Code facts#

FactValue
registered typeRobotics/Spacecraft_Dynamics/Cartesian_To_Keplerian_Elements
familyRobotics/Spacecraft_Dynamics
solver environment classICoreBlock_0_Robotics_1_Spacecraft_Dynamics_2_Cartesian_To_Keplerian_Elements
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Spacecraft_Dynamics/Cartesian_To_Keplerian_Elements/ICoreBlock_0_Robotics_1_Spacecraft_Dynamics_2_Cartesian_To_Keplerian_Elements.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Robotics/Spacecraft_Dynamics/Cartesian_To_Keplerian_Elements/ICoreBlock_0_Robotics_1_Spacecraft_Dynamics_2_Cartesian_To_Keplerian_Elements.h
default size on canvas170 × 200 px
ports at insert? in, ? out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDoublePosition
2inICoreDoubleVelocity
3outICoreDoublea
4outICoreDoubleecc
5outICoreDoubleincl
6outICoreDoubleRAAN
7outICoreDoubleargp
8outICoreDoublenu
9outICoreDoubletruelon
10outICoreDoublearglat
11outICoreDoublelonper

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
UnitsOE::comboValue(OE::unitOptions(), "Metric (m/s)")units
Angle UnitsOE::comboValue(OE::angleUnitOptions(), "Degrees")angleUnits
Central BodyOE::comboValue(OE::centralBodyOptions(), "Earth")centralBody
Gravitational ParameterOE::DEFAULT_CUSTOM_MU_TEXTcustomMu
Tolerance1e-12tolerance
Open Or Undefined Orbit ActionOE::comboValue(OE::actionOptions(), "Warning")action

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/Cartesian State Vectors to\nKeplerian Orbital Elements
port-count rulePortsParam::None
SampleTime parameterno — the counterpart defines none; the rate stays on the ICore side
always setoutputPortConfiguration = All
ICore configSimulink parameterValue translation
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
Central BodycentralBodyEarth → Earth, Moon → Moon, Mercury → Mercury, Venus → Venus, Mars → Mars, Jupiter → Jupiter, Saturn → Saturn, Uranus → Uranus, Neptune → Neptune, Sun → Sun, Custom → Custom
Gravitational ParametercustomMupasses through
Tolerancetolerancepasses through
Open Or Undefined Orbit ActionactionNone → None, Warning → Warning, Error → Error

Caveat (shown to the user): outputPortConfiguration is always written as All: this block has all nine element ports, and Simulink's six-port Keplerian configuration reports the same numbers on the first six, undefined elements NaN in both (measured). The library path carries an embedded newline before 'Keplerian'. The block has no SampleTime, so the rate stays on the ICore side

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

Description vs code#

The lists agree. check_block_descriptions.py finds no disagreement between the description's Ports, Parameters, Code export and Simulink bridge lists and the code's.

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).

Cartesian State Vectors to Keplerian Orbital Elements A position r and velocity v, in a planet-centred equatorial frame, to the nine orbital elements Aerospace Blockset reports in its "All" port configuration: a, ecc, incl, RAAN, argp, nu, truelon, arglat, lonper.

MEASURED against R2026a's aerolibsatdyn block, which is a built-in block type whose source does not ship. The arithmetic is Vallado's rv2coe; the rules that make it BIT-EXACT against the Simulink block over every captured sample are in ICoreOrbitalElementsSupport.h, and the ones a user can see are on the description below.

⚠ THE PORT LIST IS SIMULINK'S "All" CONFIGURATION, FIXED. Simulink's default "Keplerian" configuration shows the first six ports only and reports the SAME numbers on them -- the undefined elements are NaN in both, measured -- so this block carries all nine and pins outputPortConfiguration = All on export. A model imported with six links lands on ports 1 to 6 unchanged.

⚠ THE THREE HDL TARGETS ARE SIMULATION-ONLY real arithmetic, quantized only at the ports, and HDL and PLC Structured Text write 0.0 where the other targets write NaN.

Sample results#

Cartesian To Keplerian Elements — Sine Wave, [3,1]: amplitudes 1/2/3 at 2 rad/s (tried only because every scalar stimulus was refused)Cartesian To Keplerian Elements — Sine Wave, [3,1]: amplitudes 1/2/3 at 2 rad/s (tried only because every scalar stimulus was refused)-1-0.500.51012345t (s)in ICoreDouble-Out-0 [3x1] entry 0in ICoreDouble-Out-0 [3x1] entry 0

180 sample(s) were non-finite (nan/inf) and are absent from the plot; they are in the table below and in the JSON.

tin ICoreDouble-Out-0 [3x1] entry 0in ICoreDouble-Out-0 [3x1] entry 0out ICoreDouble-Out-0out ICoreDouble-Out-1out ICoreDouble-Out-2
0[0, 0, 0][0, 0, 0]nannannan
0.4[0.7174, 1.435, 2.152][0.7174, 1.435, 2.152]nannannan
0.8[0.9996, 1.999, 2.999][0.9996, 1.999, 2.999]nannannan
1.2[0.6755, 1.351, 2.026][0.6755, 1.351, 2.026]nannannan
1.6[-0.05837, -0.1167, -0.1751][-0.05837, -0.1167, -0.1751]nannannan
2[-0.7568, -1.514, -2.27][-0.7568, -1.514, -2.27]nannannan
2.4[-0.9962, -1.992, -2.988][-0.9962, -1.992, -2.988]nannannan
2.8[-0.6313, -1.263, -1.894][-0.6313, -1.263, -1.894]nannannan
3.2[0.1165, 0.2331, 0.3496][0.1165, 0.2331, 0.3496]nannannan
3.6[0.7937, 1.587, 2.381][0.7937, 1.587, 2.381]nannannan
4[0.9894, 1.979, 2.968][0.9894, 1.979, 2.968]nannannan
4.4[0.5849, 1.17, 1.755][0.5849, 1.17, 1.755]nannannan
4.8[-0.1743, -0.3487, -0.523][-0.1743, -0.3487, -0.523]nannannan
5.2[-0.8278, -1.656, -2.483][-0.8278, -1.656, -2.483]nannannan

Every 4th of 60 samples, from the vector stimulus.

Plotted: vector — Sine Wave, [3,1]: amplitudes 1/2/3 at 2 rad/s (tried only because every scalar stimulus was refused)

Category dynamic · sample time 0.1 · 60 steps · commit 383c0ecf1501cf1d43d89b8f688fc2fcad5e9b52 · produced by docsSample --out <folder> --blocks Ideal_Airspeed_Correction WGS84_Gravity_Model Linear_Regression_Predictor Linear_Classifier_Predictor Crossover_Pilot_Model Precision_Pilot_Model Tustin_Pilot_Model FIR_Least_Squares_Design FIR_Equiripple_Design Cartesian_To_Keplerian_Elements Keplerian_Elements_To_Cartesian --steps 60 · data docs/generated/samples/Robotics__Spacecraft_Dynamics__Cartesian_To_Keplerian_Elements.json · the SVG is generated from those numbers by tools/docs/plot_svg.py, so it is a run and not a drawing (R-D10).