Skip to content

Commit 3ad0f1e

Browse files
committed
First pass at inclination measurement
1 parent 9e92f89 commit 3ad0f1e

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

src/instrumentman/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from . import setup
1111
from . import setmeasurement
1212
from . import geocomtest
13+
from . import inclination
1314

1415

1516
@extra_group("iman", params=None) # type: ignore[misc]
@@ -53,6 +54,7 @@ def cli_test() -> None:
5354
cli.add_command(terminal.cli)
5455
cli_measure.add_command(setmeasurement.cli_measure)
5556
cli_measure.add_command(setup.cli_measure)
57+
cli_measure.add_command(inclination.cli_measure)
5658
cli_calc.add_command(setmeasurement.cli_calc)
5759
cli_test.add_command(geocomtest.cli)
5860
cli_merge.add_command(setmeasurement.cli_merge)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from typing import Any
2+
3+
from click_extra import (
4+
extra_command,
5+
option,
6+
option_group,
7+
IntRange,
8+
File
9+
)
10+
11+
from ..utils import (
12+
com_baud_option,
13+
com_timeout_option,
14+
com_port_argument
15+
)
16+
17+
18+
@extra_command(
19+
"inclination",
20+
params=None,
21+
context_settings={"auto_envvar_prefix": None}
22+
) # type: ignore[misc]
23+
@com_port_argument()
24+
@option_group(
25+
"Connection options",
26+
"",
27+
com_baud_option(),
28+
com_timeout_option()
29+
)
30+
@option(
31+
"-o",
32+
"--output",
33+
help="file to save output to",
34+
type=File("wt", encoding="utf8", lazy=True)
35+
)
36+
@option(
37+
"-p",
38+
"--positions",
39+
help="number of positions to measure around the circle",
40+
type=IntRange(1),
41+
default=1
42+
)
43+
@option(
44+
"-z",
45+
"--zero",
46+
help="start from hz==0 (otherwise start from current orientation)",
47+
is_flag=True
48+
)
49+
@option(
50+
"-c",
51+
"--cycles",
52+
help="repetition cycles",
53+
type=IntRange(1),
54+
default=1
55+
)
56+
def cli_measure(**kwargs: Any) -> None:
57+
"""Measure instrument inclination in multiple positions."""
58+
from .app import main_measure
59+
60+
main_measure(**kwargs)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from io import TextIOWrapper
2+
3+
from click_extra import echo
4+
from geocompy.data import Angle
5+
from geocompy.geo import GeoCom
6+
from geocompy.communication import open_serial
7+
8+
9+
def run_measure(
10+
tps: GeoCom,
11+
output: TextIOWrapper | None = None,
12+
positions: int = 1,
13+
zero: bool = False,
14+
cycles: int = 1
15+
) -> None:
16+
turn = 360 // positions
17+
v = Angle(90, 'deg')
18+
start = 0
19+
20+
if not zero:
21+
angles = tps.tmc.get_angle()
22+
if angles.params is not None:
23+
start = round(angles.params[0].asunit('deg'))
24+
25+
echo(
26+
"hz,cross,length",
27+
output
28+
)
29+
30+
for a in range(start, start + cycles * 360, turn):
31+
hz = Angle(a, 'deg').normalized()
32+
tps.aut.turn_to(hz, v)
33+
34+
fullangles = tps.tmc.get_angle_inclination('MEASURE')
35+
if fullangles.params is None:
36+
continue
37+
38+
cross = fullangles.params[4]
39+
length = fullangles.params[5]
40+
41+
echo(
42+
f"{a % 360:d},{cross.asunit('deg') * 3600:.2f},"
43+
f"{length.asunit('deg') * 3600:.2f}",
44+
output
45+
)
46+
47+
48+
def main_measure(
49+
port: str,
50+
baud: int = 9600,
51+
timeout: int = 15,
52+
output: TextIOWrapper | None = None,
53+
positions: int = 1,
54+
zero: bool = False,
55+
cycles: int = 1
56+
) -> None:
57+
58+
with open_serial(
59+
port,
60+
retry=2,
61+
sync_after_timeout=True,
62+
speed=baud,
63+
timeout=timeout
64+
) as com:
65+
tps = GeoCom(com)
66+
run_measure(tps, output, positions, zero, cycles)

src/instrumentman/setmeasurement/app.py

Whitespace-only changes.

0 commit comments

Comments
 (0)