diff --git a/examples/basic_pipeline.py b/examples/basic_pipeline.py index 9ee99e1..4f80e51 100644 --- a/examples/basic_pipeline.py +++ b/examples/basic_pipeline.py @@ -77,13 +77,13 @@ def main() -> int: break # ------------------------------------------------------ use the results - # Scalars are calibrated Newtons when the bundle ships a calibration; the *_raw - # pair is always the unfiltered integrator output. + # The *_raw pair is always the unfiltered integrator output. touching = "yes" if snap.centroid is not None else "no" + fn_unit, fx_unit, fy_unit = sensor.force_units print( f"FPS={snap.fps:5.1f} " - f"normal={snap.normal_force:8.4f} N (raw {snap.normal_force_raw:10.2f}) " - f"shear=({snap.shear_x:7.4f}, {snap.shear_y:7.4f}) " + f"normal={snap.normal_force:8.4f} {fn_unit} (raw {snap.normal_force_raw:10.2f}) " + f"shear=({snap.shear_x:7.4f} {fx_unit}, {snap.shear_y:7.4f} {fy_unit}) " f"contact={touching} age={snap.age_ms:4.1f} ms", end="\r", ) diff --git a/examples/finger_pipeline.py b/examples/finger_pipeline.py index 466c096..12c919a 100644 --- a/examples/finger_pipeline.py +++ b/examples/finger_pipeline.py @@ -75,10 +75,11 @@ def main() -> int: # ------------------------------------------------------ use the results coverage = runtime.tactile.mask_stats.get("coverage") coverage_text = f"{coverage:.2f}" if isinstance(coverage, float) else "n/a" + fn_unit, fx_unit, fy_unit = runtime.tactile.force_units print( f"FPS={snap.fps:5.1f} " - f"normal={snap.normal_force:8.4f} N " - f"shear=({snap.shear_x:7.4f}, {snap.shear_y:7.4f}) " + f"normal={snap.normal_force:8.4f} {fn_unit} " + f"shear=({snap.shear_x:7.4f} {fx_unit}, {snap.shear_y:7.4f} {fy_unit}) " f"mask={coverage_text} age={snap.age_ms:4.1f} ms", end="\r", ) diff --git a/examples/mini_pipeline.py b/examples/mini_pipeline.py index 085f3b4..0cec0c7 100644 --- a/examples/mini_pipeline.py +++ b/examples/mini_pipeline.py @@ -95,9 +95,10 @@ def main(): cv2.imshow("depth", cv2.applyColorMap(div_normalized, cv2.COLORMAP_JET)) # 步骤 3.4:打印关键结果 + fn_unit, fx_unit, fy_unit = sensor.force_units print( - f"FPS={fps:.2f}, 法向力={fnormal:.4f}, 切向力X={fshearx:.4f}, " - f"切向力Y={fsheary:.4f}, 深度图尺寸={depth_map.shape}, 原始分辨率={sensor.img_size_raw}" + f"FPS={fps:.2f}, 法向力={fnormal:.4f} {fn_unit}, 切向力X={fshearx:.4f} {fx_unit}, " + f"切向力Y={fsheary:.4f} {fy_unit}, 深度图尺寸={depth_map.shape}, 原始分辨率={sensor.img_size_raw}" ) # 步骤 3.5:键盘控制 diff --git a/examples/plot_data.py b/examples/plot_data.py index bdde4e4..862e69e 100644 --- a/examples/plot_data.py +++ b/examples/plot_data.py @@ -65,7 +65,11 @@ def main(): sensor.info.VRAW, sensor.info.DEPTH, ) - print(f"FPS={fps:.2f}, 法向力={fn:.4f}, 切向力X={fx:.4f}, 切向力Y={fy:.4f}") + fn_unit, fx_unit, fy_unit = sensor.force_units + print( + f"FPS={fps:.2f}, 法向力={fn:.4f} {fn_unit}, " + f"切向力X={fx:.4f} {fx_unit}, 切向力Y={fy:.4f} {fy_unit}" + ) arrows = orisys.util.draw_arrows(sensor.img, flow, threshold=5, grid_spacing=10, arrow_scale=1.0) cv2.imshow("形变矢量场", arrows) diff --git a/src/orisys/finger/runtime.py b/src/orisys/finger/runtime.py index dded85f..fd2dc8f 100644 --- a/src/orisys/finger/runtime.py +++ b/src/orisys/finger/runtime.py @@ -101,6 +101,10 @@ class TactileProcessor: def valid_mask(self): return self._sensor.valid_mask + @property + def force_units(self) -> tuple[str, str, str]: + return self._sensor.force_units + def push_frame(self, frame, *, already_gray=False, valid_mask=None): """Feed one processed tactile frame into the analysis pipeline.""" mask = self._default_valid_mask if valid_mask is None else valid_mask diff --git a/tests/test_finger_runtime.py b/tests/test_finger_runtime.py index b1d7700..8d60f57 100644 --- a/tests/test_finger_runtime.py +++ b/tests/test_finger_runtime.py @@ -123,6 +123,7 @@ def test_tactile_processor_push_frame_uses_default_valid_mask(): def __init__(self): self.calls = [] + self.force_units = ("N", "raw", "raw") self.frame = None self.img = None self.flow = None @@ -146,6 +147,7 @@ def test_tactile_processor_push_frame_uses_default_valid_mask(): result = tactile.push_frame(frame, already_gray=True) assert result == "ok" + assert tactile.force_units == ("N", "raw", "raw") assert sensor.calls[0]["frame"] is frame assert sensor.calls[0]["already_processed"] is True assert sensor.calls[0]["already_gray"] is True