examples/a121/algo/vibration/example_app.py

examples/a121/algo/vibration/example_app.py#

 1# Copyright (c) Acconeer AB, 2024-2026
 2# All rights reserved
 3
 4from __future__ import annotations
 5
 6import pyqtgraph as pg
 7
 8import acconeer.exptool as et
 9from acconeer.exptool import a121
10from acconeer.exptool.a121.algo._utils import APPROX_BASE_STEP_LENGTH_M
11from acconeer.exptool.a121.algo.vibration import (
12    ExampleApp,
13    ExampleAppConfig,
14    ExampleAppResult,
15    get_high_frequency_config,
16)
17from acconeer.exptool.a121.algo.vibration.plot import VibrationPlot
18
19
20SENSOR_ID = 1
21
22
23def main():
24    args = a121.ExampleArgumentParser().parse_args()
25    et.utils.config_logging(args)
26
27    example_app_config = get_high_frequency_config()
28
29    client = a121.Client.open(**a121.get_client_args(args))
30
31    example_app = ExampleApp(
32        client=client,
33        sensor_id=SENSOR_ID,
34        example_app_config=example_app_config,
35    )
36
37    pg_updater = PGUpdater(example_app_config)
38    pg_process = et.PGProcess(pg_updater)
39
40    example_app.start()
41    pg_process.start()
42
43    interrupt_handler = et.utils.ExampleInterruptHandler()
44
45    while not interrupt_handler.got_signal:
46        example_app_result = example_app.get_next()
47
48        try:
49            pg_process.put_data(example_app_result)
50        except et.PGProccessDiedException:
51            break
52
53    print("Disconnecting...")
54    pg_process.close()
55    example_app.stop()
56
57
58class PGUpdater:
59    def __init__(self, example_app_config: ExampleAppConfig) -> None:
60        self._sensor_config = ExampleApp._get_sensor_config(example_app_config)
61        self._meas_dist_m = example_app_config.measured_point * APPROX_BASE_STEP_LENGTH_M
62        self._vibration_plot = VibrationPlot()
63
64    def setup(self, win: pg.GraphicsLayoutWidget) -> None:
65        self._vibration_plot.setup_plot(win, self._meas_dist_m)
66
67    def update(self, example_app_result: ExampleAppResult) -> None:
68        self._vibration_plot.update_plot(
69            result=example_app_result,
70            extra_result=example_app_result.processor_extra_result,
71            show_time_series_std=True,
72        )
73
74
75if __name__ == "__main__":
76    main()

View this example on GitHub: acconeer/acconeer-python-exploration