Skip to main content

sim_components/
shapes.rs

1//! What a machine is, beside what it does: its modes with their shapes (from the machine, or from its elastic model
2//! linearised at a pose) and the stiffness each mode lives in; how well it moves its tool at a place of its workspace;
3//! and the envelope of traces. For the app's views and `sim-cli modes --shapes` and `workspace`. No machine is named:
4//! everything comes through the `Machine` interface and the config.
5
6use sim_core::{Config, ConfigError, Machine, MachineEntry};
7
8/// A complex number as [re, im].
9type C = [f64; 2];
10
11fn mul(a: C, b: C) -> C {
12    [a[0] * b[0] - a[1] * b[1], a[0] * b[1] + a[1] * b[0]]
13}
14fn sub(a: C, b: C) -> C {
15    [a[0] - b[0], a[1] - b[1]]
16}
17fn div(a: C, b: C) -> C {
18    let d = b[0] * b[0] + b[1] * b[1];
19    [(a[0] * b[0] + a[1] * b[1]) / d, (a[1] * b[0] - a[0] * b[1]) / d]
20}
21fn abs(a: C) -> f64 {
22    a[0].hypot(a[1])
23}
24
25/// The machine at rest at `pose` (`Machine::equilibrium`) and its small-motion matrix there: A = d(derivatives) /
26/// d(state), n x n row after row, by central differences with the motor torques held at those that hold it at rest.
27/// The motors are free in it, as on a machine with its drives off: no control loop holds them.
28pub fn linearised(machine: &dyn Machine, pose: &[f64]) -> (Vec<f64>, Vec<f64>) {
29    let n = machine.state_len();
30    let (mut rest, mut torque) = (Vec::new(), vec![0.0; machine.motors().len()]);
31    machine.equilibrium(pose, &mut rest, &mut torque);
32    let (mut a, mut up, mut down, mut state) = (vec![0.0; n * n], vec![0.0; n], vec![0.0; n], rest.clone());
33    for j in 0..n {
34        // A step of 1e-7 of the state's size: forces of 0.05 N on a belt of 5e5 N per unit strain, far above rounding.
35        let h = 1e-7 * rest[j].abs().max(1.0);
36        state[j] = rest[j] + h;
37        machine.derivatives(&state, &torque, &mut up);
38        state[j] = rest[j] - h;
39        machine.derivatives(&state, &torque, &mut down);
40        state[j] = rest[j];
41        (0..n).for_each(|i| a[i * n + j] = (up[i] - down[i]) / (2.0 * h));
42    }
43    (rest, a)
44}
45
46/// The machine at rest at `pose` with its rotors held, as `Machine::modes` has its modes (motors held by their loops):
47/// `linearised`'s matrix over the states that move neither a motor's angle nor its speed (`Machine::motor_state`), and
48/// those states' indices. A state that moves a motor's angle (a rotor's, or on a rigid drive the joint's own) is held
49/// with the state that moves its speed. The rest, the stand at `pose`.
50pub fn linearised_held(machine: &dyn Machine, pose: &[f64]) -> (Vec<f64>, Vec<f64>, Vec<usize>) {
51    let (rest, a) = linearised(machine, pose);
52    let (n, k) = (rest.len(), machine.motors().len());
53    let motors = |s: &[f64]| {
54        let (mut p, mut v) = (vec![0.0; k], vec![0.0; k]);
55        machine.motor_state(s, &mut p, &mut v);
56        (p, v)
57    };
58    let (p0, v0) = motors(&rest);
59    let moved = |a: &[f64], b: &[f64]| a.iter().zip(b).any(|(a, b)| (a - b).abs() > 1e-9);
60    let keep: Vec<usize> = (0..n)
61        .filter(|&i| {
62            let mut s = rest.clone();
63            s[i] += 1e-3;
64            let (p, v) = motors(&s);
65            !moved(&p, &p0) && !moved(&v, &v0)
66        })
67        .collect();
68    let m = keep.len();
69    let held = (0..m * m).map(|rc| a[keep[rc / m] * n + keep[rc % m]]).collect();
70    (rest, held, keep)
71}
72
73/// The eigenvalue of the n x n matrix `a` nearest `shift` and its eigenvector, by inverse iteration: (A - shift I) is
74/// factorised (LU with partial pivoting) and solved fifty times, each solve multiplying the part of the nearest
75/// eigenvector by 1 / |lambda - shift| more than any other; then once more from the eigenvalue found, as Rayleigh's
76/// iteration does, since another eigenvalue (a free machine's rigid motion at 0) may lie nearly as near the shift and
77/// fade slowly. The vector is scaled so that its largest entry is 1 (real). `None` where the matrix holds a number that
78/// is not finite.
79pub fn eigen_near(a: &[f64], n: usize, shift: [f64; 2]) -> Option<([f64; 2], Vec<[f64; 2]>)> {
80    if n == 0 || a.iter().any(|x| !x.is_finite()) {
81        return None;
82    }
83    // A start with a part of every eigenvector: no entry zero, and not all in phase.
84    let start: Vec<C> = (0..n).map(|i| [1.0, 0.37 * (i as f64 + 1.0).sin()]).collect();
85    let (lambda, x) = inverse_iteration(a, n, shift, start, 50)?;
86    inverse_iteration(a, n, lambda, x, 10)
87}
88
89/// `count` solves of (A - shift I) y = x from `x`, each scaled so that its largest entry is 1, and the eigenvalue at the
90/// end: (A x)_k / x_k at that entry.
91fn inverse_iteration(a: &[f64], n: usize, shift: C, mut x: Vec<C>, count: usize) -> Option<(C, Vec<C>)> {
92    let mut m: Vec<C> = a.iter().map(|&x| [x, 0.0]).collect();
93    (0..n).for_each(|i| m[i * n + i] = sub(m[i * n + i], shift));
94    let mut order: Vec<usize> = (0..n).collect();
95    for k in 0..n {
96        let p = (k..n).max_by(|&i, &j| abs(m[i * n + k]).total_cmp(&abs(m[j * n + k])))?;
97        if p != k {
98            (0..n).for_each(|c| m.swap(k * n + c, p * n + c));
99            order.swap(k, p);
100        }
101        // A shift that is an eigenvalue exactly: the solve then gives that eigenvector at once.
102        if abs(m[k * n + k]) == 0.0 {
103            m[k * n + k] = [1e-300, 0.0];
104        }
105        for i in k + 1..n {
106            let f = div(m[i * n + k], m[k * n + k]);
107            m[i * n + k] = f;
108            for c in k + 1..n {
109                m[i * n + c] = sub(m[i * n + c], mul(f, m[k * n + c]));
110            }
111        }
112    }
113    let solve = |b: &[C]| -> Vec<C> {
114        let mut y: Vec<C> = order.iter().map(|&p| b[p]).collect();
115        for i in 0..n {
116            for c in 0..i {
117                y[i] = sub(y[i], mul(m[i * n + c], y[c]));
118            }
119        }
120        for i in (0..n).rev() {
121            for c in i + 1..n {
122                y[i] = sub(y[i], mul(m[i * n + c], y[c]));
123            }
124            y[i] = div(y[i], m[i * n + i]);
125        }
126        y
127    };
128    let largest = |x: &[C]| (0..n).max_by(|&i, &j| abs(x[i]).total_cmp(&abs(x[j]))).unwrap_or(0);
129    for _ in 0..count {
130        x = solve(&x);
131        let top = x[largest(&x)];
132        if !(abs(top) > 0.0 && abs(top).is_finite()) {
133            return None;
134        }
135        x.iter_mut().for_each(|v| *v = div(*v, top));
136    }
137    let k = largest(&x);
138    let ax = (0..n).fold([0.0, 0.0], |sum: C, c| [sum[0] + a[k * n + c] * x[c][0], sum[1] + a[k * n + c] * x[c][1]]);
139    Some((div(ax, x[k]), x))
140}
141
142/// An eigenvalue as a mode: its undamped natural frequency |lambda| / 2 pi in Hz and its damping ratio -Re / |lambda|.
143pub fn as_mode(lambda: [f64; 2]) -> sim_core::Mode {
144    let w = abs(lambda);
145    sim_core::Mode { hz: w / std::f64::consts::TAU, damping: if w > 0.0 { -lambda[0] / w } else { 0.0 } }
146}
147
148/// The eigenvalue of a mode of `hz` and `damping` with its positive imaginary part, where inverse iteration starts.
149fn shift_of(hz: f64, damping: f64) -> C {
150    let w = std::f64::consts::TAU * hz;
151    [-damping.clamp(0.0, 0.99) * w, w * (1.0 - damping.clamp(0.0, 0.99).powi(2)).sqrt()]
152}
153
154/// The kinds of stiffness a mode can live in, each with the label key `ui-modes-stiffness-<kind>`.
155pub const STIFFNESS_KINDS: [&str; 6] = ["belt", "gearbox", "guide", "frame", "base", "link"];
156
157/// The kind of stiffness a config value is, by its path: a number whose key names a stiffness (`*stiffness*`, or a
158/// Young's modulus), in a table of belts, gearboxes, guides and what runs on them (friction contacts, racks, screws,
159/// slides), the frame, the base or the links. End stops and a payload's swing are left out: they hold nothing at rest.
160pub fn stiffness_kind(path: &str) -> Option<&'static str> {
161    let (table, key) = (path.split('.').next()?, path.rsplit('.').next()?);
162    let named = key.contains("stiffness") || key.contains("youngs_modulus");
163    if !named || ["stop", "swing", "_t1", "_t2", "scale", "coefficient"].iter().any(|w| key.contains(w)) {
164        return None;
165    }
166    Some(match table {
167        t if t.starts_with("belt") => "belt",
168        "gearbox" => "gearbox",
169        t if t.starts_with("friction") || ["guide", "rack", "screw", "slide"].contains(&t) => "guide",
170        "frame" => "frame",
171        "base" => "base",
172        t if t.starts_with("link") || t == "arm" => "link",
173        _ => return None,
174    })
175}
176
177/// A shape shown swinging in the 3D view (`session::mode_scene`): the pose the machine rests at, the mode's frequency
178/// and its shape as a complex direction in the state, re and im. The state swings as rest + a (re sin wt + im cos wt).
179#[derive(Debug, Clone, PartialEq)]
180pub struct ShownMode {
181    pub pose: Vec<f64>,
182    pub hz: f64,
183    pub re: Vec<f64>,
184    pub im: Vec<f64>,
185}
186
187/// One mode of the machine at a pose, for the mode list.
188#[derive(Debug, Clone)]
189pub struct ModeView {
190    /// As the machine reports it (`Machine::modes`): Hz and damping ratio.
191    pub hz: f64,
192    pub damping: f64,
193    /// The oscillation of the linearised model nearest it, with the motors free or the rotors held (`mode_views`),
194    /// whose shape is shown where the machine gives none; `None` where the linearisation found none.
195    pub linear: Option<sim_core::Mode>,
196    /// The shape is the machine's own (`Machine::mode_shape`), not the linearised model's.
197    pub from_machine: bool,
198    pub shape: ShownMode,
199    /// The share of the mode's strain energy in each kind of stiffness (`STIFFNESS_KINDS`), largest first: twice the
200    /// change of ln f of the reported mode over that of ln k when the kind's stiffnesses in the config grow by 10 %
201    /// (Rayleigh: d(w^2) / dk_i is the energy in k_i over the modal mass). The shares add up to 1 where every
202    /// stiffness the mode lives in is one of the kinds.
203    pub stiffness: Vec<(&'static str, f64)>,
204}
205
206/// The machine `config` builds, with its parts in.
207pub fn build(entry: &MachineEntry, config: &Config) -> Result<Box<dyn Machine>, ConfigError> {
208    (entry.build)(&crate::catalog::resolve(entry, config)?)
209}
210
211/// The modes the machine reports at `pose`, lowest first, each with a shape: the machine's own for the mode it gives one
212/// of, else that of the oscillation nearest the reported one of its linearised model with the motors free (`linearised`)
213/// or with the rotors held (`linearised_held`, as `Machine::modes` has them), a real eigenvalue never (`eigen_near`;
214/// a held 694.28 Hz mode was paired with a roller friction pole, 101.8 Hz, until 21 November), scaled so
215/// that the tool moves by at most 1 m per unit (or, where it does not move, the largest entry is 1).
216pub fn mode_views(entry: &MachineEntry, config: &Config, pose: &[f64]) -> Result<Vec<ModeView>, ConfigError> {
217    let machine = build(entry, config)?;
218    let modes = machine.modes(pose);
219    if modes.is_empty() {
220        return Ok(Vec::new());
221    }
222    let n = machine.state_len();
223    let (rest, a) = linearised(machine.as_ref(), pose);
224    let (_, held, keep) = linearised_held(machine.as_ref(), pose);
225    let own = machine.mode_shape(pose);
226    let mut shares = shares(entry, config, pose, &stiffness_leaves(config), &modes).into_iter();
227    // An oscillation only: a real eigenvalue (a friction's slope at rest, a free axis's drift) is no mode's partner.
228    let oscillates = |(lambda, _): &(C, Vec<C>)| lambda[1].abs() > 1e-6 * abs(*lambda);
229    let views = modes.iter().map(|mode| {
230        // The partner: the nearest oscillation of the model with the motors free (a single joint's two-mass mode) or
231        // held (the modes of `Machine::modes`' convention), its held states at rest in the shape.
232        let shift = shift_of(mode.hz, mode.damping);
233        let free = eigen_near(&a, n, shift).filter(oscillates);
234        let held = eigen_near(&held, keep.len(), shift).filter(oscillates).map(|(lambda, x)| {
235            let mut full = vec![[0.0; 2]; n];
236            keep.iter().zip(x).for_each(|(&i, v)| full[i] = v);
237            (lambda, full)
238        });
239        let off = |found: &Option<(C, Vec<C>)>| found.as_ref().map_or(f64::INFINITY, |(l, _)| abs(sub(*l, shift)));
240        let found = if off(&held) < off(&free) { held } else { free };
241        let own = own.as_ref().filter(|(hz, _)| (hz - mode.hz).abs() <= 1e-9 * mode.hz);
242        let shape = match (own, &found) {
243            (Some((_, shape)), _) => {
244                ShownMode { pose: pose.to_vec(), hz: mode.hz, re: shape.clone(), im: vec![0.0; n] }
245            }
246            (None, Some((lambda, x))) => scaled(machine.as_ref(), pose, &rest, x, as_mode(*lambda).hz),
247            (None, None) => ShownMode { pose: pose.to_vec(), hz: mode.hz, re: vec![0.0; n], im: vec![0.0; n] },
248        };
249        let stiffness = shares.next().unwrap_or_default();
250        ModeView {
251            hz: mode.hz,
252            damping: mode.damping,
253            linear: found.map(|(lambda, _)| as_mode(lambda)),
254            from_machine: own.is_some(),
255            shape,
256            stiffness,
257        }
258    });
259    Ok(views.collect())
260}
261
262/// The shape `x` of the linearised model as a `ShownMode`, scaled by how far it moves the tool (see `mode_views`).
263fn scaled(machine: &dyn Machine, pose: &[f64], rest: &[f64], x: &[C], hz: f64) -> ShownMode {
264    let axes = machine.axes().len();
265    let tool = |part: usize| -> Vec<f64> {
266        let state: Vec<f64> = rest.iter().zip(x).map(|(r, v)| r + 1e-6 * v[part]).collect();
267        let (mut pos, mut vel) = (vec![0.0; axes], vec![0.0; axes]);
268        machine.tool_state(&state, &mut pos, &mut vel);
269        pos
270    };
271    let (at_rest, re, im) = (
272        {
273            let (mut pos, mut vel) = (vec![0.0; axes], vec![0.0; axes]);
274            machine.tool_state(rest, &mut pos, &mut vel);
275            pos
276        },
277        tool(0),
278        tool(1),
279    );
280    let moved = (0..axes).map(|i| (re[i] - at_rest[i]).hypot(im[i] - at_rest[i]) / 1e-6).fold(0.0, f64::max);
281    let scale = if moved > 1e-9 { 1.0 / moved } else { 1.0 };
282    ShownMode {
283        pose: pose.to_vec(),
284        hz,
285        re: x.iter().map(|v| v[0] * scale).collect(),
286        im: x.iter().map(|v| v[1] * scale).collect(),
287    }
288}
289
290/// The config's stiffness values by kind (`stiffness_kind`): positive numbers only.
291fn stiffness_leaves(config: &Config) -> Vec<(&'static str, Vec<(String, f64)>)> {
292    let mut kinds: Vec<(&'static str, Vec<(String, f64)>)> = Vec::new();
293    for (path, value) in config.leaves() {
294        let (Some(kind), Some(k)) = (stiffness_kind(&path), value.as_float().filter(|k| *k > 0.0)) else { continue };
295        match kinds.iter_mut().find(|(have, _)| *have == kind) {
296            Some((_, leaves)) => leaves.push((path, k)),
297            None => kinds.push((kind, vec![(path, k)])),
298        }
299    }
300    kinds
301}
302
303/// Per mode the machine reports at `pose` (`reported`, lowest first) the share of its strain energy in each kind of
304/// stiffness, largest first (see `ModeView`): each kind's stiffnesses grow by 10 % in a machine of its own, and the
305/// mode of the same place in its list moves.
306fn shares(
307    entry: &MachineEntry,
308    config: &Config,
309    pose: &[f64],
310    kinds: &[(&'static str, Vec<(String, f64)>)],
311    reported: &[sim_core::Mode],
312) -> Vec<Vec<(&'static str, f64)>> {
313    const STEP: f64 = 1.1;
314    let mut out = vec![Vec::new(); reported.len()];
315    for (kind, leaves) in kinds {
316        let mut stiffer = config.clone();
317        if leaves.iter().any(|(path, k)| crate::analysis::set_bounded(&mut stiffer, path, k * STEP).is_err()) {
318            continue;
319        }
320        let Ok(machine) = build(entry, &stiffer) else { continue };
321        let moved = machine.modes(pose);
322        for ((shares, mode), stiffer) in out.iter_mut().zip(reported).zip(&moved) {
323            shares.push((*kind, 2.0 * (stiffer.hz / mode.hz).ln() / STEP.ln()));
324        }
325    }
326    out.iter_mut().for_each(|shares| shares.sort_by(|a, b| b.1.total_cmp(&a.1)));
327    out
328}
329
330/// The largest acceleration the motors can give the tool at `pose` in its worst direction, m/s^2: with T = A a + g the
331/// rigid model's motor torques (`Machine::feedforward_torque`, linear in the acceleration a of the axes in metres) and
332/// `peak` each motor's peak torque, motor k holds |g_k| + |A_k . d| a <= peak_k for a direction d; its worst is d along
333/// its row A_k, so a = min over k of (peak_k - |g_k|) / |A_k|. 0 where a motor cannot even hold the tool there.
334pub fn worst_acceleration(machine: &dyn Machine, pose: &[f64], peak: &[f64]) -> f64 {
335    let (axes, motors) = (machine.axes(), machine.motors().len());
336    let mut hold = vec![0.0; motors];
337    machine.feedforward_torque(pose, &vec![0.0; axes.len()], &mut hold);
338    let mut rows = vec![0.0; motors];
339    let mut torque = vec![0.0; motors];
340    for (j, _) in axes.iter().enumerate().filter(|(_, axis)| axis.unit == "m") {
341        let mut acc = vec![0.0; axes.len()];
342        acc[j] = 1.0;
343        machine.feedforward_torque(pose, &acc, &mut torque);
344        (0..motors).for_each(|k| rows[k] += (torque[k] - hold[k]).powi(2));
345    }
346    (0..motors)
347        .filter(|&k| rows[k] > 0.0)
348        .map(|k| (peak.get(k).copied().unwrap_or(0.0) - hold[k].abs()) / rows[k].sqrt())
349        .fold(f64::INFINITY, f64::min)
350        .max(0.0)
351}
352
353/// A horizontal slice through what the machine reaches, at height `z` of its third axis (`workspace_slice`).
354#[derive(Debug, Clone, PartialEq)]
355pub struct Slice {
356    /// The span of the first two axes the grid covers, (low, high) each: their ranges and half of their width beyond
357    /// each end, so that the reach shows where it goes past the travel range.
358    pub x: (f64, f64),
359    pub y: (f64, f64),
360    /// Nodes per side: node (i, j) is at x.0 + i (x.1 - x.0) / (n - 1), and likewise in y with j.
361    pub n: usize,
362    /// Per node, row after row (j outer): the condition number (`Machine::condition`; `INFINITY` out of reach of the
363    /// kinematics), whether the machine goes there (`Machine::unreachable` has nothing against it), and the largest
364    /// acceleration in the worst direction (`worst_acceleration`, with each motor's `peak` torque; NaN out of reach).
365    pub condition: Vec<f64>,
366    pub goes: Vec<bool>,
367    pub acceleration: Vec<f64>,
368}
369
370/// The slice at `z` with `n` nodes a side (see `Slice`); the other axes beyond the third at 0. `None` for a machine with
371/// fewer than three axes or no condition to tell (one whose motors move the tool as its axes).
372pub fn workspace_slice(machine: &dyn Machine, z: f64, n: usize, peak: &[f64]) -> Option<Slice> {
373    let axes = machine.axes();
374    axes.get(2)?;
375    machine.condition(&[0.0, 0.0, z])?;
376    let span = |a: &sim_core::AxisInfo| (a.min - (a.max - a.min) / 2.0, a.max + (a.max - a.min) / 2.0);
377    let (x, y) = (span(&axes[0]), span(&axes[1]));
378    let at = |(low, high): (f64, f64), i: usize| low + (high - low) * i as f64 / (n - 1) as f64;
379    let mut pose = vec![0.0; axes.len()];
380    let mut slice = Slice { x, y, n, condition: Vec::new(), goes: Vec::new(), acceleration: Vec::new() };
381    for j in 0..n {
382        for i in 0..n {
383            (pose[0], pose[1], pose[2]) = (at(x, i), at(y, j), z);
384            let condition = machine.condition(&pose).unwrap_or(f64::INFINITY);
385            slice.condition.push(condition);
386            slice.goes.push(machine.unreachable(&pose, 0.0).is_none());
387            slice.acceleration.push(if condition.is_finite() {
388                worst_acceleration(machine, &pose, peak)
389            } else {
390                f64::NAN
391            });
392        }
393    }
394    Some(slice)
395}
396
397/// The lowest and the highest value at each sample over `traces`, sample by sample from their starts; where a trace is
398/// shorter than another, its end counts no further.
399pub fn envelope<'a>(traces: impl IntoIterator<Item = &'a [f64]>) -> (Vec<f64>, Vec<f64>) {
400    let (mut low, mut high): (Vec<f64>, Vec<f64>) = (Vec::new(), Vec::new());
401    for trace in traces {
402        for (i, &v) in trace.iter().enumerate() {
403            if i < low.len() {
404                (low[i], high[i]) = (low[i].min(v), high[i].max(v));
405            } else {
406                low.push(v);
407                high.push(v);
408            }
409        }
410    }
411    (low, high)
412}
413
414#[cfg(test)]
415mod tests {
416    use super::*;
417
418    /// Two runs by hand: [1, 3, 2] and [2, 1, 2, 5] span [1, 1, 2, 5] to [2, 3, 2, 5].
419    #[test]
420    fn the_envelope_is_the_lowest_and_highest_of_the_runs_at_each_sample() {
421        let (a, b) = ([1.0, 3.0, 2.0], [2.0, 1.0, 2.0, 5.0]);
422        assert_eq!(envelope([&a[..], &b[..]]), (vec![1.0, 1.0, 2.0, 5.0], vec![2.0, 3.0, 2.0, 5.0]));
423    }
424
425    /// x'' = -w^2 x - 2 z w x' with w = 2 pi 10 and z = 0.1, as a first-order system: lambda = w (-z + i sqrt(1 - z^2)),
426    /// the shape (1, lambda).
427    #[test]
428    fn inverse_iteration_finds_the_damped_oscillators_eigenvalue() {
429        let (w, z) = (std::f64::consts::TAU * 10.0, 0.1);
430        let a = [0.0, 1.0, -w * w, -2.0 * z * w];
431        let (lambda, x) = eigen_near(&a, 2, [0.0, w]).unwrap();
432        let exact = [-z * w, w * (1.0 - z * z).sqrt()];
433        assert!(abs(sub(lambda, exact)) < 1e-9 * w, "{lambda:?} {exact:?}");
434        assert!(abs(sub(div(x[1], x[0]), exact)) < 1e-9 * w);
435        let mode = as_mode(lambda);
436        assert!((mode.hz - 10.0).abs() < 1e-9 && (mode.damping - z).abs() < 1e-9);
437    }
438
439    #[test]
440    fn stiffness_values_are_sorted_by_kind() {
441        assert_eq!(stiffness_kind("belt.stiffness_ea_n"), Some("belt"));
442        assert_eq!(stiffness_kind("gearbox.4.stiffness_nm_rad"), Some("gearbox"));
443        assert_eq!(stiffness_kind("friction_x.bristle_stiffness_n_m"), Some("guide"));
444        assert_eq!(stiffness_kind("link_bending.youngs_modulus_pa"), Some("link"));
445        assert_eq!(stiffness_kind("base.tilt_stiffness_x_nm_rad"), Some("base"));
446        for none in
447            ["hard_stop.stiffness_n_m", "joint.stop_stiffness_nm_rad", "gearbox.stiffness_t1_nm", "mass.carriage_kg"]
448        {
449            assert_eq!(stiffness_kind(none), None, "{none}");
450        }
451    }
452}