Skip to content

Commit 92995fc

Browse files
Update asi_tiger_controller.py
Consistent type hints.
1 parent b0249f5 commit 92995fc

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

src/navigate/model/devices/APIs/asi/asi_tiger_controller.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ASIException(Exception):
5858
- command: error code received from ASI Console
5959
"""
6060

61-
def __init__(self, code: str):
61+
def __init__(self, code: str) -> None:
6262
"""Initialize the ASIException class
6363
Parameters
6464
----------
@@ -94,7 +94,7 @@ def __init__(self, code: str):
9494
super().__init__(self.message)
9595
# Sends message to base exception constructor for python purposes
9696

97-
def __str__(self):
97+
def __str__(self) -> str:
9898
"""Overrides base Exception string to be displayed
9999
in traceback"""
100100
return f"{self.code} -> {self.message}"
@@ -103,7 +103,7 @@ def __str__(self):
103103
class TigerController:
104104
"""Tiger Controller class"""
105105

106-
def __init__(self, com_port: str, baud_rate: int, verbose: bool = False):
106+
def __init__(self, com_port: str, baud_rate: int, verbose: bool = False) -> None:
107107
"""Initialize the Tiger Controller class
108108
109109
@@ -249,9 +249,8 @@ def get_default_motor_axis_sequence(self) -> list[str]:
249249
motor_axes.pop(i)
250250
return motor_axes
251251

252-
##### TODO: Modify these to accept dictionaries and send a
253-
# single command for all axes
254-
def set_feedback_alignment(self, axis, aa):
252+
##### TODO: Modify to accept dictionaries and send a single command for all axes
253+
def set_feedback_alignment(self, axis: str, aa: float) -> None:
255254
"""Set the stage feedback alignment.
256255
257256
Adjusts the drive strength by writing to a non-volatile on-board
@@ -277,7 +276,7 @@ def set_feedback_alignment(self, axis, aa):
277276
self.send_command(f"AZ {axis}\r")
278277
self.read_response()
279278

280-
def set_backlash(self, axis, val):
279+
def set_backlash(self, axis: str, val: float) -> None:
281280
"""Enable/disable stage backlash correction.
282281
283282
This command sets (or displays) the amount of distance in millimeters of the
@@ -303,7 +302,7 @@ def set_backlash(self, axis, val):
303302
self.send_command(f"B {axis}={val:.7f}\r")
304303
self.read_response()
305304

306-
def set_finishing_accuracy(self, axis, ac):
305+
def set_finishing_accuracy(self, axis: str, ac: float) -> None:
307306
"""Set the stage finishing accuracy.
308307
309308
This command sets/displays the Finish Error setting, which controls when the
@@ -325,7 +324,7 @@ def set_finishing_accuracy(self, axis, ac):
325324
self.send_command(f"PC {axis}={ac:.7f}\r")
326325
self.read_response()
327326

328-
def set_error(self, axis, ac):
327+
def set_error(self, axis: str, ac: float) -> None:
329328
"""Set the stage drift error
330329
331330
This command sets the Drift Error setting. This setting controls the
@@ -638,15 +637,15 @@ def wait_for_device(self, timeout: float = 1.75) -> None:
638637
if self.verbose:
639638
print(f"Waited {waiting_time:.2f} s")
640639

641-
def stop(self):
640+
def stop(self) -> None:
642641
"""Stop all stage movement immediately"""
643642

644643
self.send_command("HALT")
645644
self.read_response()
646645
if self.verbose:
647646
print("ASI Stages stopped successfully")
648647

649-
def set_speed(self, speed_dict):
648+
def set_speed(self, speed_dict: dict) -> None:
650649
"""Set speed
651650
652651
Parameters
@@ -658,7 +657,7 @@ def set_speed(self, speed_dict):
658657
self.send_command(f"S {axes}")
659658
self.read_response()
660659

661-
def set_speed_as_percent_max(self, pct):
660+
def set_speed_as_percent_max(self, pct: float) -> None:
662661
"""Set speed as a percentage of the maximum speed
663662
664663
Parameters
@@ -692,7 +691,7 @@ def set_speed_as_percent_max(self, pct):
692691
)
693692
self.read_response()
694693

695-
def get_speed(self, axis: str):
694+
def get_speed(self, axis: str) -> float:
696695
"""Get speed
697696
698697
Parameters
@@ -704,7 +703,7 @@ def get_speed(self, axis: str):
704703
response = self.read_response()
705704
return float(response.split("=")[1])
706705

707-
def get_encoder_counts_per_mm(self, axis: str):
706+
def get_encoder_counts_per_mm(self, axis: str) -> float:
708707
"""Get encoder counts pre mm of axis
709708
710709
Parameters
@@ -728,7 +727,7 @@ def scanr(
728727
end_position_mm: float,
729728
enc_divide: float = 0,
730729
axis: str = "X",
731-
):
730+
) -> None:
732731
"""Set scanr operation mode.
733732
734733
Parameters
@@ -765,7 +764,7 @@ def scanv(
765764
number_of_lines: float,
766765
overshoot: float = 1.0,
767766
axis: str = "X",
768-
):
767+
) -> None:
769768
"""Set scanv operation mode.
770769
771770
Parameters
@@ -792,7 +791,7 @@ def scanv(
792791
self.send_command(command)
793792
self.read_response()
794793

795-
def start_scan(self, axis: str, is_single_axis_scan: bool = True):
794+
def start_scan(self, axis: str, is_single_axis_scan: bool = True) -> None:
796795
"""Start scan
797796
798797
Parameters
@@ -805,12 +804,12 @@ def start_scan(self, axis: str, is_single_axis_scan: bool = True):
805804
self.send_command("SCAN")
806805
self.read_response()
807806

808-
def stop_scan(self):
807+
def stop_scan(self) -> None:
809808
"""Stop scan."""
810809
self.send_command("SCAN P")
811810
self.read_response()
812811

813-
def is_moving(self):
812+
def is_moving(self) -> bool:
814813
"""Check to see if the stage is moving.
815814
816815
Sends the command / which is equivalent to STATUS
@@ -848,7 +847,7 @@ def is_moving(self):
848847

849848
# Basic Serial Commands for Filter Wheels
850849

851-
def send_filter_wheel_command(self, cmd) -> None:
850+
def send_filter_wheel_command(self, cmd: str) -> None:
852851
"""Send a serial command to the filter wheel.
853852
854853
Parameters
@@ -861,28 +860,29 @@ def send_filter_wheel_command(self, cmd) -> None:
861860
self.send_command(f"{cmd}\n")
862861
# print(f"Sent Command: {command.decode(encoding='ascii')}")
863862

864-
def select_filter_wheel(self, filter_wheel_number=0):
865-
"""
866-
Select the filter wheel, e.g., 0, 1...
863+
def select_filter_wheel(self, filter_wheel_number: int=0) -> None:
864+
""" Select the filter wheel, e.g., 0, 1...
867865
868-
Sets the current filter wheel for subsequent commands. Prompt shows currently
869-
selected wheel, e.g., 0> is result of FW 0 command. If the selected wheel is
866+
Sets the current filter wheel for later commands. Prompt shows the currently
867+
selected wheel, e.g., 0> is a result of FW 0 command. If the selected wheel is
870868
HOMED and ready to go, the FW command returns the selected wheel as normal. If
871869
the wheel is not ready for any reason, the response ERR is returned. Example:
872870
871+
Notes
872+
----------
873873
0> FW 1 1 Normal – switch to FW 1
874874
1> FW 0 ERR FW 0 not ready
875875
0> Although FW 0 not ready – can still change FW 0 parameters.
876876
877877
Parameters
878878
----------
879879
filter_wheel_number : int
880-
The filter wheel number to select.
880+
The filter-wheel number to select.
881881
"""
882882
self.send_filter_wheel_command(f"FW {filter_wheel_number}")
883883
self.read_response()
884884

885-
def move_filter_wheel(self, filter_wheel_position=0):
885+
def move_filter_wheel(self, filter_wheel_position: int=0) -> None:
886886
"""Move Filter Wheel
887887
888888
Move to filter position n , where n is a valid filter position.
@@ -896,34 +896,36 @@ def move_filter_wheel(self, filter_wheel_position=0):
896896
self.send_filter_wheel_command(f"MP {filter_wheel_position}")
897897
self.read_response()
898898

899-
def move_filter_wheel_to_home(self):
899+
def move_filter_wheel_to_home(self) -> None:
900900
"""Move the Filter Wheel to Home Position
901901
902-
Causes current wheel to seek its home position.
902+
Causes the current wheel to seek its home position.
903903
"""
904904
self.send_filter_wheel_command("HO")
905905
self.read_response()
906906

907-
def change_filter_wheel_speed(self, speed=0):
908-
"""Change the Filter Wheel Speed
907+
def change_filter_wheel_speed(self, speed: int=0) -> None:
908+
"""Change the Filter-Wheel Speed
909909
910910
Selects a consistent set of preset acceleration and speed parameters.
911911
Supported in version 2.4 and later.
912912
913-
0 Default - directly set and saved AU, AD, and VR parameters are used.
914-
1 Slowest and smoothest switching speed.
915-
2 to 8 Intermediate switching speeds.
916-
9 Fastest but least reliable switching speed.
913+
Parameters
914+
----------
915+
speed : int
916+
Speed of the filter wheel. The speed is a preset value that can be set
917+
between 0 and 9, where 0 is the default speed, 1 is the slowest but
918+
smoothest switching speed, and 9 is the fastest yet least reliable speed.
917919
"""
918920
self.send_filter_wheel_command(f"SV {speed}")
919921
self.read_response()
920922

921-
def halt_filter_wheel(self):
923+
def halt_filter_wheel(self) -> None:
922924
"""Halt filter wheel"""
923925
self.send_filter_wheel_command("HA")
924926
self.read_response()
925927

926-
def move_dichroic(self, dichroic_id, dichroic_position=0):
928+
def move_dichroic(self, dichroic_id: str, dichroic_position: int=0) -> None:
927929
"""Move Dichroic Slider.
928930
929931
Move to dichroic position n , where n is a valid filter position.
@@ -939,11 +941,9 @@ def move_dichroic(self, dichroic_id, dichroic_position=0):
939941
self.send_filter_wheel_command(f"MOVE {dichroic_id}={dichroic_position}")
940942
self.read_response()
941943

942-
def square_wave(self, on_time, delay_time):
944+
def square_wave(self, on_time: int, delay_time: int) -> None:
943945
"""Square wave modulation.
944946
945-
For testing only.
946-
947947
Parameters
948948
----------
949949
on_time : int
@@ -984,7 +984,7 @@ def square_wave(self, on_time, delay_time):
984984
self.send_command(f'{command}\r')
985985
self.read_response()
986986

987-
def logic_card_on(self, axis : str):
987+
def logic_card_on(self, axis: str) -> None:
988988
"""Turn on the logic card
989989
990990
Parameters
@@ -999,7 +999,7 @@ def logic_card_on(self, axis : str):
999999
self.send_command(f'6 CCA Z=64\r')
10001000
self.read_response()
10011001

1002-
def logic_card_off(self, axis : str):
1002+
def logic_card_off(self, axis: str) -> None:
10031003
"""Turn off the logic card
10041004
10051005
Parameters

0 commit comments

Comments
 (0)