补充 Finger 模型切换与逐帧接触状态
按实际几何和处理参数校验切换模型,并保留帧内接触状态。88 项相关测试通过。
This commit is contained in:
@@ -55,6 +55,45 @@ def make_sensor(*, median=1):
|
||||
return sensor
|
||||
|
||||
|
||||
def test_finger_model_swap_validates_actual_runtime_and_invalidates_zero(monkeypatch, tmp_path):
|
||||
import orisys.calibration_context as context_mod
|
||||
from orisys.finger.runtime import FingerRuntime
|
||||
|
||||
sensor = make_sensor()
|
||||
sensor.device_id = None
|
||||
sensor.mirror = False
|
||||
sensor.set_calibration_reference({"fn": 10}, reference_id="old-zero")
|
||||
runtime = FingerRuntime.__new__(FingerRuntime)
|
||||
runtime.tactile = SimpleNamespace(raw_sensor=sensor)
|
||||
mesh = tmp_path / "mesh.npz"
|
||||
mesh.write_bytes(b"actual geometry")
|
||||
runtime.geometry = SimpleNamespace(config={}, export_paths=SimpleNamespace(mesh=mesh),
|
||||
source_scale=.42, out_height=2, out_width=2)
|
||||
runtime.domain = object()
|
||||
runtime.frame_processor = SimpleNamespace(flip_source_vertical=True)
|
||||
monkeypatch.setattr(context_mod, "domain_fingerprint", lambda domain: "domain")
|
||||
contexts = []
|
||||
|
||||
def context(config, filters, **kwargs):
|
||||
contexts.append(kwargs)
|
||||
return {"signature": "actual"}
|
||||
|
||||
monkeypatch.setattr(context_mod, "build_context", context)
|
||||
selected = RecordingModel()
|
||||
selected.pipeline = {"coordinates": {"frame": "autocal_flat"}}
|
||||
runtime.set_calibration(selected)
|
||||
assert sensor.calibration is selected
|
||||
assert sensor.calibration_status == {"fn": "zero_unavailable"}
|
||||
assert contexts[0]["geometry_sha256"] == context_mod.sha256_file(mesh)
|
||||
assert contexts[0]["output_domain_sha256"] == "domain"
|
||||
wrong_shape = RecordingModel()
|
||||
wrong_shape.pipeline = selected.pipeline
|
||||
wrong_shape.coordinate_map = np.zeros((1, 1, 2))
|
||||
with pytest.raises(ValueError, match="shape"):
|
||||
runtime.set_calibration(wrong_shape)
|
||||
assert sensor.calibration is selected
|
||||
|
||||
|
||||
def predict(sensor, frame, fn, *, contact=True, mapped=True):
|
||||
return sensor.apply_calibration_frame(frame_id=frame, timestamp_s=frame / 30.,
|
||||
raw=(fn, 20., 30.), uv=(0., 0.),
|
||||
|
||||
Reference in New Issue
Block a user