Step 2 — Map Surface-Z Error

After a layer is printed and its rosbag is captured, the rosbag_parser associates the err_surface_mm signal with the robot's (X, Y, Z) position at each moment in time, producing both a human-readable 3D visualization and a machine-readable error map.

What Happens

  1. Read /kuka/pose messages → extract (timestamp, X, Y, Z).
  2. Read /wire_stickout/err_surface_mm messages → extract (timestamp, value).
  3. Interpolate error values onto pose timestamps (nearest-neighbor by time).
  4. Optionally parse the G-code for the commanded toolpath overlay.
  5. Apply trimming/smoothing to suppress transient sensor noise at layer start/end.
  6. Write error_map.csv — each row maps a robot position to its error.
  7. Render an interactive 3D Plotly scatter plot and save to plot.html.
rosbag_parser :: BagDirectory -> GCode -> (HTML, CSV)

Command

uv run python map_surface_err_to_xyz_pos.py \
  /path/to/L<N>_Z<ZZ>/ \
  /path/to/<layer>.gcode \
  --nominal_z <ZZ> \
  --no-gcode \
  -o ~/PhotogrammetryWAAM/STATE/ERR/L<N>.html \
  --smooth 12 \
  --trim_first_n_err_vals 32 \
  --trim_last_n_err_vals 32

Working directory: shared/rosbag_parser/

Key Parameters

FlagDefaultPurpose
--nominal_z MMauto-detectOverride nominal layer Z height
--smooth N1Moving-average window size for error signal
--trim_first_n_err_vals N0Zero out first N error values (approach transient)
--trim_last_n_err_vals N0Zero out last N error values (departure transient)
--exclude_outside_z_bounds MM0.5Drop poses more than ±MM from nominal Z
--no-gcodefalseSkip G-code overlay in the plot

Processing Order

  1. Detect (or accept) nominal Z.
  2. Trim leading samples where Z deviates > 1 mm from nominal.
  3. Exclude samples outside ±exclude_outside_z_bounds of nominal Z.
  4. Interpolate error to remaining pose timestamps.
  5. Zero first/last N error values.
  6. Apply smoothing window.

Outputs

ArtifactFormatConsumed By
L<N>.htmlInteractive Plotly 3D plotHuman inspection
L<N>_error_map.csvX,Y,Z,err_mmStep 3 — proportional control

error_map.csv Schema

X,Y,Z,err_mm
12.2021,47.3637,43.2479,4.0644
10.7972,47.6810,43.2649,4.0644
...

All positions are in the robot frame (mm). Error is signed: positive means the surface is above nominal, negative means below.

3D Plot Traces

TraceColorData
Robot pathBlack(X, Y, Z) from /kuka/pose
G-code pathBlue(X, Y, Z) from G-code (offset-transformed)
Error surfaceRed(X, Y, Z + err_mm)