forked from MITHaystack/srt-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotors.py
103 lines (82 loc) · 3 KB
/
rotors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""rotors.py
Module for Managing Different Motor Objects
"""
from enum import Enum
from .motors import NoMotor, Rot2Motor, H180Motor, PushRodMotor, CassiMotor
def angle_within_range(angle, limits):
lower_limit, upper_limit = limits
if lower_limit <= upper_limit:
return lower_limit <= angle <= upper_limit
else:
return not lower_limit < angle < upper_limit
class RotorType(Enum):
"""
Enum Class for the Different Types of
"""
NONE = "NONE"
ROT2 = "ALFASPID"
H180 = "H180MOUNT"
PUSH_ROD = "PUSHROD"
CASSI = "CASSI"
class Rotor:
"""
Class for Controlling Any Rotor Motor Through a Common Interface
See Also
--------
motors.py
"""
def __init__(self, motor_type, port, baudrate, az_limits, el_limits):
"""Initializes the Rotor with its Motor Object
Parameters
----------
motor_type : RotorType
String enum Identifying the Type of Motor
port : str
Serial Port Identifier String for Communicating with the Motor
az_limits : (float, float)
Tuple of Lower and Upper Azimuth Limits
el_limits : (float, float)
Tuple of Lower and Upper Elevation Limits
"""
if motor_type == RotorType.NONE or motor_type == RotorType.NONE.value:
self.motor = NoMotor(port, baudrate, az_limits, el_limits)
elif motor_type == RotorType.ROT2 or motor_type == RotorType.ROT2.value:
self.motor = Rot2Motor(port, baudrate, az_limits, el_limits)
elif motor_type == RotorType.H180 or motor_type == RotorType.H180.value:
self.motor = H180Motor(port, baudrate, az_limits, el_limits)
elif motor_type == RotorType.PUSH_ROD or motor_type == RotorType.PUSH_ROD.value:
self.motor = PushRodMotor(port, baudrate, az_limits, el_limits)
elif motor_type == RotorType.CASSI or motor_type == RotorType.CASSI.value:
self.motor = CassiMotor(port, baudrate, az_limits, el_limits)
else:
raise ValueError("Not a known motor type")
self.az_limits = az_limits
self.el_limits = el_limits
def get_azimuth_elevation(self):
"""Latest Known Azimuth and Elevation
Returns
-------
(float, float)
Azimuth and Elevation Coordinate as a Tuple of Floats
"""
return self.motor.status()
def set_azimuth_elevation(self, az, el):
"""Sets the Azimuth and Elevation of the Motor
Parameters
----------
az : float
Azimuth Coordinate to Point At
el : float
Elevation Coordinate to Point At
Returns
-------
None
"""
if self.angles_within_bounds(az, el):
self.motor.point(az, el)
else:
raise ValueError("Angle Not Within Bounds")
def angles_within_bounds(self, az, el):
return angle_within_range(az, self.az_limits) and angle_within_range(
el, self.el_limits
)