examples/a121/algo/tank_level/tank_level.py

examples/a121/algo/tank_level/tank_level.py#

 1# Copyright (c) Acconeer AB, 2022-2024
 2# All rights reserved
 3
 4from __future__ import annotations
 5
 6import acconeer.exptool as et
 7from acconeer.exptool import a121
 8from acconeer.exptool.a121.algo.distance import (
 9    PeakSortingMethod,
10    ReflectorShape,
11    ThresholdMethod,
12)
13from acconeer.exptool.a121.algo.distance._processors import (
14    DEFAULT_FIXED_AMPLITUDE_THRESHOLD_VALUE,
15    DEFAULT_FIXED_STRENGTH_THRESHOLD_VALUE,
16)
17from acconeer.exptool.a121.algo.tank_level import RefApp
18from acconeer.exptool.a121.algo.tank_level._ref_app import RefAppConfig
19
20
21def main():
22    args = a121.ExampleArgumentParser().parse_args()
23    et.utils.config_logging(args)
24
25    # Setup the configurations
26    # Detailed at https://docs.acconeer.com/en/latest/exploration_tool/algo/a121/ref_apps/tank_level.html
27
28    # Sensor selections
29    sensor = 1
30
31    # Tank level configurations
32    ref_app_config = RefAppConfig(
33        start_m=0.03,
34        end_m=0.5,
35        max_step_length=2,
36        max_profile=a121.Profile.PROFILE_2,
37        close_range_leakage_cancellation=True,
38        signal_quality=20,
39        update_rate=None,
40        median_filter_length=5,
41        num_medians_to_average=5,
42        threshold_method=ThresholdMethod.CFAR,
43        reflector_shape=ReflectorShape.PLANAR,
44        peaksorting_method=PeakSortingMethod.CLOSEST,
45        num_frames_in_recorded_threshold=50,
46        fixed_threshold_value=DEFAULT_FIXED_AMPLITUDE_THRESHOLD_VALUE,  # float
47        fixed_strength_threshold_value=DEFAULT_FIXED_STRENGTH_THRESHOLD_VALUE,  # float
48        threshold_sensitivity=0.0,  # float
49    )
50
51    # End setup configurations
52
53    # Preparation for client
54    client = a121.Client.open(**a121.get_client_args(args))
55
56    # Preparation for reference application processor
57    ref_app = RefApp(client=client, sensor_id=sensor, config=ref_app_config)
58    ref_app.calibrate()
59    ref_app.start()
60
61    interrupt_handler = et.utils.ExampleInterruptHandler()
62    print("Press Ctrl-C to end session")
63
64    while not interrupt_handler.got_signal:
65        processed_data = ref_app.get_next()
66        try:
67            if processed_data.level is not None:
68                print("Tank level result " + str(processed_data.level))
69        except et.PGProccessDiedException:
70            break
71
72    ref_app.stop()
73    client.close()
74    print("Disconnecting...")
75
76
77if __name__ == "__main__":
78    main()

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