v0.1.0 · MIT · Python ≥ 3.11 · runtime: numpy + robot_msgs

robot_metrics

Performance metrics for robot parts. Hand it robot_msgs streams (a whole recording, or a live feed a few samples at a time) and it turns them into numbers with units: tracking error, stop error, lag, repeatability. A metric is math plus fixed settings; the pass/fail target is kept apart, where an objective turns a number into a verdict.

What goes in

Recordings as robot_msgs streams in a Run: the target and the measured state (JointTrajectory), the plan on its own ticks, a tool's PoseTrajectory, plus labels such as station and rung.

What a metric is

A small settings object, such as ErrorStat(statistic="rms"). It keeps a running tally as samples arrive: start empty, add samples (update), end the run (close), read the numbers (values). fold(run) does all of that for a whole recording in one call. A plain function sits beside each class for one-off use.

Whole recording or live: same numbers

Live: feed the same recording a few samples at a time and you get the same numbers as scoring it whole, even for a stop split across two chunks. Tallies from many runs add up into a rung, a station, a deployment.

What comes out

Numbers in each metric's display unit (deg, mm, ms, %), computed in SI underneath; every stop kept one by one; a record of the metric, its settings and version. Pass/fail targets live on Objectives, apart from the math: pass · fail · not_run.

API at a glance

A real run of a 1-DOF pendulum: the arm's metrics from the catalog, the same numbers from the whole recording and from a live feed, then a pass/fail target judged on its own. Every output is from the run that built this page.

One script on its own. It reads round 8's recordings, which are not public (point ROBOT_METRICS_ROUND8 at a copy); the README's example runs anywhere.

from robot_metrics import Objective, catalog, summarize
from robot_metrics.datasets import onedof_round8

runs = onedof_round8.real_runs()      # 252 real plays of a 1-DOF pendulum rack
run = runs[32]                        # one play: its streams, samples in each
run
Run(real station=can11 rung=0.9 kind=repeat · plan 318, state 318, target 318)
arm = catalog.pendulum_arm(tip_length_m=0.339).collection()
list(arm.aliases)                     # the 15 numbers the catalog defines
['servo/tracking RMS', 'servo/tracking peak', 'servo/stop error', 'servo/stop error p95', 'servo/stop error worst', 'servo/overshoot', 'servo/lag', 'servo/limiter share', 'servo/stops', 'tip tracking RMS', 'tip stop error', 'tip stop p95', 'tip stop worst', 'tip settle', 'all stops settled']
scored = arm.fold(run)                # run every sample through them, once
offline = arm.values(scored)          # read them out: {name: number}
offline["tip stop error"]             # mm: the tip's median stop error
0.23094052947652116
tally = arm.empty()                   # live: an empty running tally
for chunk in run.chunks(7):           # the same recording, 7 samples at a time
    tally = arm.update(tally, chunk)  # add these 7 samples
live = arm.values(arm.close(tally))   # the run ended: read the numbers out
live == offline                       # the same numbers either way
True
# score every CAN 11 run, grouped by (station, rung)
can11_runs = [run for run in runs if run.labels["station"] == "can11"]
by_rung = summarize(arm, can11_runs, by=("station", "rung"))

# a pass/fail target, kept apart from the math: every stop within 1 mm
every_stop = Objective(
    "tip stop error", "<=", 1.0, unit="mm", share=1.0, on="items"
)
every_stop.judge(by_rung[("can11", 0.9)]).message
'13 of 14 pass, worst 1.143 mm (proposed)'
one run · offline or liveRunrobot_msgs streamscommanded vs measuredMetricmath + fixed settingsadds up samplesNumberin its unit: deg, mm, msvalues(...)Objective≤ 1 mm on every stopkept apart from the mathVerdictpass · fail · not_runjudge(group)many runs · a deploymentRuns × Nlabels: station, rungreal · sim · replaysummarizescore each run, group themby=station, rungGroupnumbers · spread · sharesn, p95, worstGateevery objective passesGate.judge()Laddera verdict per cellhighest_passing()the same scoring, run by run, then groupedone run · offline or liveRunrobot_msgs streamscommanded vs measuredMetricmath + fixed settingsadds up samplesNumberin its unit: deg, mm, msvalues(...)Objective≤ 1 mm on every stopkept apart from the mathVerdictpass · fail · not_runjudge(group)many runs · a deploymentRuns × Nlabels: station, rungreal · sim · replaysummarizescore each run, group themby=station, rungGroupnumbers · spread · sharesn, p95, worstGateevery objective passesGate.judge()Laddera verdict per cellhighest_passing()

The API in one table

you haveyou callyou get
one recordingtally = collection.fold(run)every sample run through the metrics once; a tally is what they have added up
a live feedtally = collection.empty(), then tally = collection.update(tally, chunk) per chunk, then collection.close(tally) when the run endsthe same tally as the whole recording gives
the numberscollection.values(tally){name: number}, each in its own unit
many runssummarize(collection, runs, by=("station", "rung"))one group per (station, rung): its numbers, the spread of every stop (n, median, p95, worst), and pass shares with a Wilson interval
a targetObjective(name, "<=", 1.0, share=1.0).judge(group)a Verdict: pass · fail · not_run, with who owns the target
a picturecollection.view(name, tallies) → plot() · W&B · Rerun(fig, ax), a W&B payload, an .rrd
one callfunctional.error_stat(target, measured, statistic="rms")one number in SI, no setup
a stored valuecollection.records(tally, run)MetricRecord: the number, its unit, the metric, its settings, the version

Math only; the meaning comes from the data

A stock metric is just math: one ErrorStat measures a servo's tracking, a five-bar's tool error or a feed-forward residual, depending on which streams it is given. A new number is a stock metric with new settings and a name (an Alias), never a new function; two names for the same metric and settings compute once.

Layering

robot_msgs ← robot_metrics ← your tools (diagnostics, sim-to-real, a part catalog). The core imports numpy, robot_msgs and the stdlib; matplotlib, wandb and rerun-sdk only inside plot() and the adapters.

Catalog · 7 stock metrics

Every stock metric, grouped. Each card: what it measures, what it reads, what it returns, whether it works on a live feed, the plain function beside it, its settings, and its stock picture, drawn by plot() on CAN 11's real round-8 runs (the performance gain on a sealed sim). Each card's code is one script on its own. Tracking 2 · Stops 1 · Timing 1 · Health / codes 1 · Repeatability 1 · Performance gain 1.

groupmetricinoutrunsfunction
Tracking
How far the measured motion is from the target, sample by sample.
ErrorStatAlignedPaira number (SI)livefunctional.error_stat
ErrorPercentileAlignedPaira number (SI)livefunctional.error_percentile
Stops
What happens where the plan holds still: each stop's error, settle time, overshoot.
StopStatAlignedPaira number or a bool; every stoplivefunctional.stop_stat
Timing
How late the response runs behind the command.
TimeOffsetCommandAndStatesecondsend of runfunctional.time_offset
Health / codes
How often the drive reported a code: limiter, fault.
CodeShareAlignedPaira share, 0 to 1livefunctional.code_share
Repeatability
The same command, played again: how far apart the answers land.
RepeatabilityRepeata number (SI): RPend of runfunctional.repeatability
Performance gain
Did a fitted model make the thing that matters better, on runs it never saw?
PerformanceGainHeldOutPairnominal − fittedend of runfunctional.performance_gain

Tracking

ErrorStat

works live view: kpi_trend

One number for how far measured is from target over the samples it reads: RMS, worst (max_abs) or mean absolute error.

Its stock view, drawn by <code>plot()</code> (CAN 11's real round-8 runs)
Its stock view, drawn by plot() (CAN 11's real round-8 runs)
In AlignedPair · target, measured: two robot_msgs streams on the same instants (JointTrajectory, or PoseTrajectory for a tool). align() puts a plan on the replies' instants first.
Reads the error compare(target, measured).error of one field and joint, or a pose's position error.
Out number · a number in the signal's SI unit (rad, m for a tool, rad/s, N·m).
Keeps while it runs: four running sums (Σe², n, max|e|, Σ|e|), shared by rms, max_abs and mean_abs.

Function functional.error_stat(target, measured, **config)

In the catalog servo: tracking RMS servo: tracking peak arm: tip tracking RMS chain: tool tracking RMS chain: tool worst

Config: 4 fields
fielddefaultvalues
statistic'rms'rms · max_abs · mean_abs — rms | max_abs | mean_abs
rows'all'all · moving — all | moving (commanded speed not zero)
field'positions'positions · velocities · effort — positions | velocities | effort (a pose: its position error)
joint0
The code that drew the picture (0.27 s)

One script on its own, run from a clone's root. It reads round 8's recordings, which are not public (point ROBOT_METRICS_ROUND8 at a copy); the README's example runs anywhere.

import matplotlib.pyplot as plt
from robot_metrics import DEGREES, Alias, Collection, ErrorStat, View
from robot_metrics import summarize
from robot_metrics.datasets import onedof_round8
from robot_metrics.views import plot

# round 8's real plays, CAN 11's only
runs = onedof_round8.real_runs()
can11_runs = [run for run in runs if run.labels["station"] == "can11"]

statistics = ("rms", "max_abs", "mean_abs")
aliases = []
for statistic in statistics:
    metric = ErrorStat(statistic=statistic, rows="moving")
    alias = Alias(statistic, metric, unit="deg", scale=DEGREES)
    aliases.append(alias)
tracking = Collection(aliases)

# the three statistics share one computation
tracking.computations
1
# score every run, grouped by rung
by_rung = summarize(tracking, can11_runs, by=("rung",))
rungs, values, series = [], [], []
for (rung,), group in sorted(by_rung.items()):
    for statistic in statistics:
        rungs.append(rung)
        values.append(group.values[statistic])
        series.append(statistic)

view = View(
    title="CAN 11 · tracking error while moving, by rung",
    unit="deg",
    hint=ErrorStat.hint,
    x=rungs,
    y=values,
    group=series,
    x_label="rung",
)

# the picture, saved in this folder
figure, axes = plt.subplots(figsize=(6.4, 3.3), dpi=150)
figure, axes = plot(view, ax=axes, path="catalog-errorstat.png")
References
  • robot_msgs.compare.ErrorStats
  • robotdx.diagnostics.stock (io-diagnostics main a7fc658) tracking_error
  • evo APE (Grupp 2017)

Tracking

ErrorPercentile

works live view: distribution

A percentile of |target − measured| over the samples it reads (at 95, robot_msgs' p95_abs).

Its stock view, drawn by <code>plot()</code> (CAN 11's real round-8 runs)
Its stock view, drawn by plot() (CAN 11's real round-8 runs)
In AlignedPair · target, measured: two robot_msgs streams on the same instants (JointTrajectory, or PoseTrajectory for a tool). align() puts a plan on the replies' instants first.
Reads the same error signal as ErrorStat.
Out number · a number in the signal's SI unit.
Keeps while it runs: every |e| seen so far (exact).

Function functional.error_percentile(target, measured, **config)

In the catalog none yet: give it settings and a name in your part's metrics

Config: 4 fields
fielddefaultvalues
percentile95.0
rows'all'all · moving
field'positions'positions · velocities · effort
joint0
The code that drew the picture (0.12 s)

One script on its own, run from a clone's root. It reads round 8's recordings, which are not public (point ROBOT_METRICS_ROUND8 at a copy); the README's example runs anywhere.

import matplotlib.pyplot as plt
from robot_metrics import DEGREES, Alias, Collection, ErrorPercentile
from robot_metrics import View, summarize
from robot_metrics.datasets import onedof_round8
from robot_metrics.views import plot

# round 8's real plays, CAN 11's only
runs = onedof_round8.real_runs()
can11_runs = [run for run in runs if run.labels["station"] == "can11"]

aliases = []
for percentile in (50.0, 95.0, 99.0):
    metric = ErrorPercentile(percentile=percentile, rows="moving")
    name = f"p{percentile:g}"
    aliases.append(Alias(name, metric, unit="deg", scale=DEGREES))
percentiles = Collection(aliases)
list(percentiles.aliases)
['p50', 'p95', 'p99']
# score every run, grouped by rung
by_rung = summarize(percentiles, can11_runs, by=("rung",))
rungs, values, series = [], [], []
for (rung,), group in sorted(by_rung.items()):
    for alias in aliases:
        rungs.append(rung)
        values.append(group.values[alias.name])
        series.append(alias.name)

view = View(
    title="CAN 11 · |error| percentiles while moving, by rung",
    unit="deg",
    hint="kpi_trend",
    x=rungs,
    y=values,
    group=series,
    x_label="rung",
)

# the picture, saved in this folder
figure, axes = plt.subplots(figsize=(6.4, 3.3), dpi=150)
figure, axes = plot(view, ax=axes, path="catalog-errorpercentile.png")
References
  • robot_msgs.compare.ErrorStats.p95_abs
  • robotdx.diagnostics.stock (io-diagnostics main a7fc658) tracking_error (statistic='p95')
  • numpy.percentile (linear)

Stops

StopStat

works live view: distribution

Something about every stop. A stop is where the plan holds still (zero commanded speed for at least 0.25 s after a move); its error is the mean of its last 50 ms. Pooled over every stop it sees.

Its stock view, drawn by <code>plot()</code> (CAN 11's real round-8 runs)
Its stock view, drawn by plot() (CAN 11's real round-8 runs)
In AlignedPair · target, measured: two robot_msgs streams on the same instants (JointTrajectory, or PoseTrajectory for a tool). align() puts a plan on the replies' instants first.
Reads the measured joint and the target's position and velocities (a stop is where the commanded speed sits at zero for a while).
Out number · bool (statistic="all") · a number in the signal's unit (s for settle), a bool for statistic="all"; every stop is also kept, one by one.
Keeps while it runs: the stops so far plus the one still in progress, so a stop split across two chunks is found exactly.

Function functional.stop_stat(target, measured, **config)

In the catalog servo: stop error servo: stop error p95 servo: stop error worst servo: overshoot servo: stops arm: tip stop error arm: tip stop p95 arm: tip stop worst arm: tip settle arm: all stops settled

Config: 8 fields
fielddefaultvalues
of'error'error · settle · settled · overshoot · count
statistic'median'median · max · p95 · p90 · mean · count · all · any p<q>
bandinf
include_last_dwellTrue
joint0
dwell_min_s0.25
settle_window_s0.05
count_first_dwellFalse
The code that drew the picture (0.08 s)

One script on its own, run from a clone's root. It reads round 8's recordings, which are not public (point ROBOT_METRICS_ROUND8 at a copy); the README's example runs anywhere.

import matplotlib.pyplot as plt
from robot_metrics import Alias, Collection, StopStat, summarize
from robot_metrics.datasets import onedof_round8
from robot_metrics.views import plot

# round 8's real plays, CAN 11's only, and CAN 11's lever
runs = onedof_round8.real_runs()
can11_runs = [run for run in runs if run.labels["station"] == "can11"]
lever_m = onedof_round8.stations()["can11"]["tip_length_m"]

# rad at the joint -> mm at the tip
tip_scale = 1e3 * lever_m
tip_stop = Alias(
    "tip stop error", StopStat(), unit="mm", scale=tip_scale
)
stops = Collection([tip_stop])

# score every run, grouped by rung; add up each rung's runs
by_rung = summarize(stops, can11_runs, by=("rung",))
tallies_by_rung = {}
for (rung,), group in sorted(by_rung.items()):
    tallies_by_rung[f"rung {rung:g}"] = group.merged

view = stops.view(
    "tip stop error",
    tallies_by_rung,
    title="CAN 11 · every stop at the tip, by rung",
    target=1.0,
    target_label="1 mm",
)
len(view.y)                     # stops in the picture
84
# the picture, saved in this folder
figure, axes = plt.subplots(figsize=(6.4, 3.3), dpi=150)
figure, axes = plot(view, ax=axes, path="catalog-stopstat.png")
References
  • bam_rack_twin pendulum_score.stops / RobotDx T4 stop_accuracy
  • robotdx.diagnostics.stock (io-diagnostics main a7fc658) stop_error
  • robot_msgs.compare.goal (overshoot)
  • ISO 9283:1998 §7.2 (pose accuracy at a stop)

Timing

TimeOffset

needs the whole run view: kpi_trend

How late the measured motion runs behind the command, one number per run (robot_msgs' estimate_time_offset). On this rack it reads below zero: each reply is stamped after its tick.

Its stock view, drawn by <code>plot()</code> (CAN 11's real round-8 runs)
Its stock view, drawn by plot() (CAN 11's real round-8 runs)
In CommandAndState · command on its own ticks and state (the measured motion) as it came back: not lined up in time (finding the offset is the metric's job).
Reads two joint streams; robot_msgs.compare.estimate_time_offset on the whole run.
Out number · seconds; across runs the median of the per-run offsets.
Keeps while it runs: the run's samples until the run ends, then one offset per run.

Function functional.time_offset(command, measured, **config)

In the catalog servo: lag

Config: 1 fields
fielddefaultvalues
max_offset_s0.25
The code that drew the picture (0.22 s)

One script on its own, run from a clone's root. It reads round 8's recordings, which are not public (point ROBOT_METRICS_ROUND8 at a copy); the README's example runs anywhere.

import matplotlib.pyplot as plt
from robot_metrics import Alias, Collection, TimeOffset, View
from robot_metrics import summarize
from robot_metrics.datasets import onedof_round8
from robot_metrics.views import plot

# round 8's real plays, CAN 11's only
runs = onedof_round8.real_runs()
can11_runs = [run for run in runs if run.labels["station"] == "can11"]

# the plan (the command, on its own ticks) against the replies,
# not lined up in time: finding the offset is the metric's job
lag = Alias(
    "lag",
    TimeOffset(),
    signal=("plan", "state"),
    unit="ms",
    scale=1e3,
    across="median",
)
timing = Collection([lag])

# one lag per run, the median per rung
by_rung = summarize(timing, can11_runs, by=("rung",))
rungs, values = [], []
for (rung,), group in sorted(by_rung.items()):
    rungs.append(rung)
    values.append(group.values["lag"])

# ms; below zero on this rack: each reply is stamped after its tick
values
[-1.3509788592810978, -0.4159051295981529, -0.15500572617070651, -0.4311921077819014, -0.5884703890635314, -0.7070208377339166]
view = View(
    title="CAN 11 · reply lag behind the plan, median per rung",
    unit="ms",
    hint=TimeOffset.hint,
    x=rungs,
    y=values,
    x_label="rung",
)

# the picture, saved in this folder
figure, axes = plt.subplots(figsize=(6.4, 3.3), dpi=150)
figure, axes = plot(view, ax=axes, path="catalog-timeoffset.png")
References
  • robot_msgs.compare.estimate_time_offset
  • evo associate_trajectories offset_2

Health / codes

CodeShare

works live view: kpi_trend

The share of samples where the drive reported one of the given codes (moteus limiter or fault).

Its stock view, drawn by <code>plot()</code> (CAN 11's real round-8 runs)
Its stock view, drawn by plot() (CAN 11's real round-8 runs)
In AlignedPair · target, measured: two robot_msgs streams on the same instants (JointTrajectory, or PoseTrajectory for a tool). align() puts a plan on the replies' instants first.
Reads the measured stream's channels[channel] (moteus fault / limiter codes).
Out number · a share in [0, 1].
Keeps while it runs: (rows with a code, rows).

Function functional.code_share(target, measured, **config)

In the catalog servo: limiter share

Config: 2 fields
fielddefaultvalues
codes(97, 98, 99, 102)
channel'fault'
The code that drew the picture (0.07 s)

One script on its own, run from a clone's root. It reads round 8's recordings, which are not public (point ROBOT_METRICS_ROUND8 at a copy); the README's example runs anywhere.

import matplotlib.pyplot as plt
from robot_metrics import Alias, CodeShare, Collection, View
from robot_metrics import catalog, summarize
from robot_metrics.datasets import onedof_round8
from robot_metrics.views import plot

# round 8's real plays, every station
runs = onedof_round8.real_runs()

# moteus codes 97, 98, 99, 102: the limiter or a fault
limiter_codes = CodeShare(codes=catalog.LIMITER_CODES)
limiter = Alias("limiter share", limiter_codes, unit="%", scale=100.0)
health = Collection([limiter])

# score every run, grouped by station
by_station = summarize(health, runs, by=("station",))
stations, values = [], []
for (station,), group in sorted(by_station.items()):
    stations.append(station)
    values.append(group.values["limiter share"])
values                          # % of samples
[0.0, 0.0, 0.0, 0.0, 0.0, 0.006760868095463458]
view = View(
    title="Rows the limiter or a fault shaped, per station",
    unit="%",
    hint=CodeShare.hint,
    x=stations,
    y=values,
    x_label="station (round 8, every rung)",
)

# the picture, saved in this folder
figure, axes = plt.subplots(figsize=(6.4, 3.3), dpi=150)
figure, axes = plot(view, ax=axes, path="catalog-codeshare.png")
References
  • moteus register 0x00f fault / limiter codes
  • robotdx.diagnostics.stock (io-diagnostics main a7fc658) fault_codes

Repeatability

Repeatability

needs the whole run view: kpi_trend

ISO 9283 RP: the same command played again and again; how far apart the stops land (mean + k × spread, at the worst stop).

Its stock view, drawn by <code>plot()</code> (CAN 11's real round-8 runs)
Its stock view, drawn by plot() (CAN 11's real round-8 runs)
In Repeat · Repeat(command, target, measured): one real repeat of one command per update; a repeat of another command is refused.
Reads each repeat's stops (the stop kernel), the same stops across repeats.
Out number · the signal's SI unit (rad at a joint): ISO 9283 RP, the worst stop index.
Keeps while it runs: (command, each repeat's stop errors).

Function functional.repeatability(repeats, **config)

In the catalog none yet: give it settings and a name in your part's metrics

Config: 2 fields
fielddefaultvalues
k3.0
include_last_dwellTrue
The code that drew the picture (0.08 s)

One script on its own, run from a clone's root. It reads round 8's recordings, which are not public (point ROBOT_METRICS_ROUND8 at a copy); the README's example runs anywhere.

import matplotlib.pyplot as plt
from robot_metrics import Repeat, Repeatability, View
from robot_metrics.datasets import onedof_round8
from robot_metrics.views import plot

# round 8's real plays, CAN 11's only, and CAN 11's lever
runs = onedof_round8.real_runs()
can11_runs = [run for run in runs if run.labels["station"] == "can11"]
lever_m = onedof_round8.stations()["can11"]["tip_length_m"]

repeatability = Repeatability(k=3.0)
rungs, values = [], []
for rung in (0.2, 0.4, 0.6, 0.8, 0.9, 1.0):
    repeats = []
    for run in can11_runs:
        is_repeat = run.labels["kind"] == "repeat"
        if run.labels["rung"] == rung and is_repeat:
            target = run.streams["target"]
            measured = run.streams["state"]
            repeats.append(Repeat(("can11", rung), target, measured))

    # add up the rung's 5 repeats; rad at the joint -> mm at the tip
    tally = repeatability.fold(repeats)
    rp_tip_mm = repeatability.compute(tally) * lever_m * 1e3
    rungs.append(rung)
    values.append(rp_tip_mm)
values                          # mm at the tip, per rung
[0.8171440867784914, 1.3881499566668791, 0.35425065861733857, 0.26204103957164976, 0.3872953748015474, 0.2423048508115091]
view = View(
    title="CAN 11 · ISO 9283 RP (k=3) at the tip, 5 repeats a rung",
    unit="mm",
    hint=Repeatability.hint,
    x=rungs,
    y=values,
    x_label="rung",
)

# the picture, saved in this folder
figure, axes = plt.subplots(figsize=(6.4, 3.3), dpi=150)
figure, axes = plot(view, ax=axes, path="catalog-repeatability.png")
References
  • ISO 9283:1998 §7.2.2 pose repeatability
  • robotdx.diagnostics.stock (io-diagnostics main a7fc658) pose_accuracy
  • robot_msgs.compare.aggregate

Performance gain

PerformanceGain

needs the whole run view: kpi_trend

Did a fitted model help? One metric on held-out runs, played with the nominal values and with the fitted ones: nominal minus fitted.

Its stock view, drawn by <code>plot()</code> (a sealed sim's held-out runs)
Its stock view, drawn by plot() (a sealed sim's held-out runs)
In HeldOutPair · HeldOutPair(nominal, fitted): the same held-out runs played with the nominal values and with the fitted ones.
Reads any metric (or named metric), scored over each side's runs.
Out number · the inner metric's unit: nominal minus fitted (positive = the fit helped).
Keeps while it runs: (nominal number, fitted number).

Function functional.performance_gain(pair, **config)

In the catalog none yet: give it settings and a name in your part's metrics

Config: 2 fields
fielddefaultvalues
metricErrorStat(statistic='rms', rows='all', field='positions', joint=0)
signal('target', 'state')
The code that drew the picture (0.12 s)

One script on its own, run from a clone's root. It reads tests/data/sealed_ladder_held_out.json, which is in the repo, so it runs in any clone.

import json
import pathlib

import matplotlib.pyplot as plt
import numpy as np
from robot_msgs.std.header import Header
from robot_msgs.trajectory import JointTrajectory
from robot_metrics import Alias, ErrorStat, HeldOutPair
from robot_metrics import PerformanceGain, Run, View
from robot_metrics.views import plot

# a sealed sim's held-out runs, in this repo's tests/data/
# (run from a clone's root)
sealed_file = pathlib.Path("tests/data/sealed_ladder_held_out.json")
sealed = json.loads(sealed_file.read_text())

def held_out(rows):
    # the held-out plateaus as runs: feed-forward vs measured torque
    out = []
    for row in rows:
        t = np.asarray(row["t"])
        zeros = np.zeros((t.size, 1))
        speed = np.asarray(row["speed"])[:, None]
        feedforward = np.asarray(row["feedforward"])[:, None]
        torque = np.asarray(row["torque"])[:, None]
        header = Header(stamp=0.0, frame_id="output")
        target = JointTrajectory(
            t=t,
            joint_names=("servo",),
            positions=zeros,
            velocities=speed,
            effort=feedforward,
            header=header,
        )
        state = JointTrajectory(
            t=t,
            joint_names=("servo",),
            positions=zeros,
            velocities=speed,
            effort=torque,
            header=header,
        )
        streams = {"target": target, "state": state}
        run = Run(id=row["id"], streams=streams, provenance="sim")
        out.append(run)
    return tuple(out)

residual_rms = ErrorStat(statistic="rms", field="effort")
residual = Alias("feed-forward residual", residual_rms, unit="N·m")

nominal_runs = held_out(sealed["runs"]["nominal"])
fitted_runs = held_out(sealed["runs"]["fitted"])
pair = HeldOutPair(nominal=nominal_runs, fitted=fitted_runs)

# score both sides of the pair
gain = PerformanceGain(metric=residual)
tally = gain.update(gain.empty(), pair)

# residual RMS: (nominal, fitted)
gain.sides(tally)
(0.22196952061068506, 0.004184752627886935)
# nominal - fitted: above zero, the fit helped
gain.compute(tally)
0.21778476798279814
view = View(
    title="Residual RMS on held-out runs: nominal vs fitted",
    unit="N·m",
    hint="kpi_trend",
    x=["nominal", "fitted"],
    y=list(gain.sides(tally)),
    x_label="the same held-out runs (sealed sim), played with",
)

# the picture, saved in this folder
figure, axes = plt.subplots(figsize=(6.4, 3.3), dpi=150)
figure, axes = plot(view, ax=axes, path="catalog-performancegain.png")
References
  • hold-out validation (Hastie, Tibshirani, Friedman, ESL §7.2)
  • robot_models select_best

Named numbers, per part type

Each row is a name, a display unit and the streams it reads, over a stock metric with its settings (in code, an Alias). Rows with the same metric and settings are computed once, and every StopStat on one signal shares one pass of the stop finder: rows with the same number in computed as are computed together.

integrated_servo · 9 named numbers, 5 computations

The servo judged at its output: the plan at each reply's instant vs the reply.

nameunit · SI→unitstock metric + settingsreadsacross runsworkscomputed asnote
tracking RMSdeg ×57.3ErrorStat(rows='moving')target/statemedianlive#1RMS of target - measured over the rows the plan moves; a rung reads the median of its runs
tracking peakdeg ×57.3ErrorStat(statistic='max_abs')target/statemaxlive#2the worst |error| of the run, every row
stop errordeg ×57.3StopStat()target/statepoollive#3the median |error| of every stop, pooled over the runs
stop error p95deg ×57.3StopStat(statistic='p95')target/statepoollive#3
stop error worstdeg ×57.3StopStat(statistic='max')target/statepoollive#3
overshootdeg ×57.3StopStat(of='overshoot', statistic='max')target/statepoollive#3the largest robot_msgs.compare.goal overshoot over the stops (0 with none)
lagms ×1000TimeOffset()plan/statemedianwhole run#4estimate_time_offset(plan, state); negative on the rack: a reply is stamped after its tick
limiter share% ×100CodeShare()target/statepoollive#5rows the limiter or a fault shaped, pooled over the runs' rows
stops—StopStat(of='count', statistic='count')target/statepoollive#3how many stops the runs made

pendulum_arm · 15 named numbers, 5 computations (its 6 + the servo's 9)

An assembly: the servo plus a 339 mm lever. Every tip row is a servo number scaled through the lever to millimetres at the tip (Alias.through(..., scale_by="lever_m")), so the arm adds no computation of its own.

nameunit · SI→unitstock metric + settingsreadsacross runsworkscomputed asnote
tip tracking RMSmm ×339ErrorStat(rows='moving')target/statemedianlive#1tip = joint x lever
tip stop errormm ×339StopStat()target/statepoollive#3tip = joint x lever
tip stop p95mm ×339StopStat(statistic='p95')target/statepoollive#3tip = joint x lever
tip stop worstmm ×339StopStat(statistic='max')target/statepoollive#3tip = joint x lever
tip settlesStopStat(of='settle', band=0.00295)target/statepoollive#3the median stop's settle time into 1 mm at the tip (None when that median never settled)
all stops settled—StopStat(of='settled', statistic='all', band=0.00295)target/statepoollive#3every stop of the run settled into 1 mm at the tip (a bool: summarized as a Wilson share)

rigid_body_chain · 4 named numbers, 3 computations

A rigid chain (the five-bar, or any serial arm): each joint's RMS and the tool's position error from two PoseTrajectories.

nameunit · SI→unitstock metric + settingsreadsacross runsworkscomputed asnote
j2/tracking RMSdeg ×57.3ErrorStat()target/statepoollive#1
c1/tracking RMSdeg ×57.3ErrorStat(joint=1)target/statepoollive#2
tool tracking RMSmm ×1000ErrorStat()tool/target/tool/statepoollive#3
tool worstmm ×1000ErrorStat(statistic='max_abs')tool/target/tool/statemaxlive#3

Gates · pass/fail targets, kept apart from the math

Round 8's three verdicts per (station, rung) cell. Each target names who owns it; changing a target recomputes nothing.

gatetargetjudged onowner
tracksservo/tracking RMS <= 0.5 degthe group's numberagent (pendulum_goal)
tracksservo/tracking peak <= 1.5 degthe group's numberagent (pendulum_goal)
tracksservo/limiter share <= 2 %the group's numberagent (pendulum_goal)
tracksfaulted runs <= 0the group's numberagent (pendulum_goal)
tip stop (median)tip stop error <= 1 mmthe group's numberZach 2026-11-11 (the scorecard's median)
tip stop (median)tip settle <= 0.3 sthe group's numberagent (pendulum_goal)
tip stop (every stop)100% of tip stop error <= 1 mmevery stop, one by oneproposed: Zach 2026-11-11 on every stop

Install

Not on PyPI yet: install the tagged release from GitHub. The runtime needs numpy and robot_msgs; the extras add plot() (viz), the W&B payload and the Rerun writer.

pip install "robot-metrics[viz] @ git+https://github.com/zacharyyamaoka/robot_metrics@v0.1.0"
git clone https://github.com/zacharyyamaoka/robot_metrics && cd robot_metrics && uv run --extra test pytest -q

The tests that read the private recordings skip without them. This page is built by website/build_site.py; every number and picture on it came from that run.