增加多点标定输出三个合力平均值

This commit is contained in:
2026-10-15 18:31:46 +08:00
parent 2a154307fd
commit a3aeca1d12
2 changed files with 233 additions and 0 deletions
+94
View File
@@ -244,3 +244,97 @@ def test_solved_pose_is_stored_and_a_point_can_be_recorded_again(tmp_path):
session = json.loads((directory / "session.json").read_text(encoding="utf-8"))
assert session["completion"][0]["repeats_complete"] == 2
assert session["completion"][0]["complete"] is True
def test_stable_means_are_the_three_components_of_the_latter_half(tmp_path):
"""The summary is Fn, Fx, Fy after the hold settles. No combined magnitude."""
from orisys_autocal.multipoint import STABLE_MEANS_HEADER, stable_component_rows
repeat = tmp_path / "repeat-001"
(repeat / "capture").mkdir(parents=True)
start, end = 1_000, 1_000 + 100
with (repeat / "reference.csv").open("w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(handle, fieldnames=[
"step_index", "branch", "target_load_n", "t_start_host_mono_ns",
"t_end_host_mono_ns", "hold_complete",
])
writer.writeheader()
writer.writerow({
"step_index": 1, "branch": "load", "target_load_n": 5,
"t_start_host_mono_ns": start, "t_end_host_mono_ns": end, "hold_complete": 1,
})
with (repeat / "capture" / "frames.csv").open("w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(handle, fieldnames=["frame_id", "t_host_mono_ns", "dropped"])
writer.writeheader()
for frame, stamp in ((1, start + 10), (2, start + 60), (3, start + 80)):
writer.writerow({"frame_id": frame, "t_host_mono_ns": stamp, "dropped": 0})
with (repeat / "capture" / "forces.csv").open("w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(handle, fieldnames=[
"frame_id", "valid", "FN_raw", "FX_raw", "FY_raw", "Fmag_raw",
"FN_output_N", "FX_output_N", "FY_output_N",
])
writer.writeheader()
# The first sample is in the settling half and must not enter the mean.
writer.writerow({
"frame_id": 1, "valid": 1, "FN_raw": 9, "FX_raw": 9, "FY_raw": 9, "Fmag_raw": 15.588,
"FN_output_N": 100, "FX_output_N": 100, "FY_output_N": 100,
})
writer.writerow({
"frame_id": 2, "valid": 1, "FN_raw": 1, "FX_raw": 1, "FY_raw": 1, "Fmag_raw": 1.732,
"FN_output_N": 2, "FX_output_N": 0.4, "FY_output_N": -0.2,
})
writer.writerow({
"frame_id": 3, "valid": 1, "FN_raw": 3, "FX_raw": 3, "FY_raw": 3, "Fmag_raw": 5.196,
"FN_output_N": 4, "FX_output_N": 0.8, "FY_output_N": -0.6,
})
rows = stable_component_rows(repeat, site_id="P1", repeat_index=1)
assert list(rows[0]) == list(STABLE_MEANS_HEADER)
assert rows[0]["samples"] == 2
assert rows[0]["unit"] == "N"
assert float(rows[0]["FN_mean"]) == pytest.approx(3.0)
assert float(rows[0]["FX_mean"]) == pytest.approx(0.6)
assert float(rows[0]["FY_mean"]) == pytest.approx(-0.4)
assert "Fmag" not in rows[0]
def test_an_outlier_in_the_stable_half_is_left_out_of_its_own_mean(tmp_path):
from orisys_autocal.multipoint import stable_component_rows
repeat = tmp_path / "repeat-001"
(repeat / "capture").mkdir(parents=True)
start, end = 1_000, 1_100
with (repeat / "reference.csv").open("w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(handle, fieldnames=[
"step_index", "branch", "target_load_n", "t_start_host_mono_ns",
"t_end_host_mono_ns", "hold_complete",
])
writer.writeheader()
writer.writerow({
"step_index": 1, "branch": "load", "target_load_n": 5,
"t_start_host_mono_ns": start, "t_end_host_mono_ns": end, "hold_complete": 1,
})
stamps = (1060, 1070, 1080, 1090)
with (repeat / "capture" / "frames.csv").open("w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(handle, fieldnames=["frame_id", "t_host_mono_ns", "dropped"])
writer.writeheader()
for frame, stamp in enumerate(stamps, start=1):
writer.writerow({"frame_id": frame, "t_host_mono_ns": stamp, "dropped": 0})
normals = ((2.0, 0.4, -0.2), (4.0, 0.8, -0.6), (3.0, 0.6, -0.4), (80.0, 0.5, -0.3))
with (repeat / "capture" / "forces.csv").open("w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(handle, fieldnames=[
"frame_id", "valid", "FN_output_N", "FX_output_N", "FY_output_N",
])
writer.writeheader()
for frame, (fn, fx, fy) in enumerate(normals, start=1):
writer.writerow({
"frame_id": frame, "valid": 1,
"FN_output_N": fn, "FX_output_N": fx, "FY_output_N": fy,
})
row = stable_component_rows(repeat, site_id="P1", repeat_index=1)[0]
assert float(row["FN_mean"]) == pytest.approx(3.0)
assert float(row["FX_mean"]) == pytest.approx(0.575)
assert float(row["FY_mean"]) == pytest.approx(-0.375)