1
- import serial
2
- import time
3
-
4
1
'''
5
2
File: rot2proG.py
6
3
Author: Jaiden Ferraccioli
11
8
and a moving target.
12
9
'''
13
10
11
+ import serial
12
+ import time
13
+
14
+ '''
15
+ This class defines the control interface for the SPID Elektronik rot2proG antenna rotor controller.
16
+
17
+ Note: The controller will not change azimuth or elevation values unless the rotor is connected.
18
+
19
+ Setup: The controller must be set to use the "SPID" protocol. To do this, press the 'S' button on the
20
+ controller until it says 'PS' along with the current azimuth and elevation. Then the left or
21
+ right buttons on the controller to change between protocols. Select the protocol saying 'SP' in
22
+ the 'Horizontal' field of the controller. Once the controller is set to use the SPID protocol,
23
+ we must put it into automated mode. To do this, press the 'F' button until the controller reads
24
+ 'A' along with the current azimuth and elevation. You are now ready to communicate with the
25
+ rotor controller.
26
+ '''
14
27
class Rot2proG :
15
28
16
29
pulse = 0
17
30
debug = False
18
31
32
+ '''
33
+ This sets up the serial connection and pulse value.
34
+ When set to true, the debugging parameter allows for information such as
35
+ asimuth, elevation and pulse to be printed out when functions are called.
36
+ Debugging defualts to False.
37
+ '''
19
38
def __init__ (self , debugging = False ):
20
39
self .ser = serial .Serial (port = '/dev/ttyUSB0' ,baudrate = 600 , bytesize = 8 , parity = 'N' , stopbits = 1 , timeout = None )
21
40
self .status ()
@@ -24,9 +43,19 @@ def __init__(self, debugging=False):
24
43
print (self .ser .name )
25
44
print ("Pulse: " + str (self .pulse ) + "\n " )
26
45
46
+ '''
47
+ This makes sure that the serial connection is closed when the class is deleted
48
+ or the program terminates
49
+ '''
27
50
def __del__ (self ):
28
51
self .ser .close ()
29
52
53
+ '''
54
+ Send a STATUS command to the controller, which requests the current azimuth
55
+ and elevation of the rotor. The azimuth, elevation and pulse are then computed,
56
+ the pulse is set and the azimuth, elevation and pulse are returned as a list (first
57
+ element being azimuth, the second being elevation, and the third being pulse).
58
+ '''
30
59
def status (self ):
31
60
cmd = ['\x57 ' ,'\x00 ' ,'\x00 ' ,'\x00 ' ,'\x00 ' ,'\x00 ' , '\x00 ' , '\x00 ' , '\x00 ' , '\x00 ' , '\x00 ' , '\x1f ' , '\x20 ' ]
32
61
packet = "" .join (cmd )
@@ -41,6 +70,8 @@ def status(self):
41
70
ph = ord (rec_packet [5 ])
42
71
pv = ord (rec_packet [10 ])
43
72
73
+ ret = [az , el , ph ]
74
+
44
75
assert (ph == pv )
45
76
self .pulse = ph
46
77
@@ -51,6 +82,15 @@ def status(self):
51
82
print ("PH: " + str (ph ))
52
83
print ("PV: " + str (pv ) + "\n " )
53
84
85
+ return ret
86
+
87
+ '''
88
+ Send a STOP command to the controller, which causes the rotor to stop moving and
89
+ return the current azimuth, elevation and pulse of the rotor where it stopped. The
90
+ azimuth, elevation and pulse are then computed, the pulse is set and the azimuth,
91
+ elevation and pulse are returned as a list (first element being azimuth, sencond
92
+ being elevation and the third being pulse).
93
+ '''
54
94
def stop (self ):
55
95
cmd = ['\x57 ' ,'\x00 ' ,'\x00 ' ,'\x00 ' ,'\x00 ' ,'\x00 ' , '\x00 ' , '\x00 ' , '\x00 ' , '\x00 ' , '\x00 ' , '\x0f ' , '\x20 ' ]
56
96
packet = "" .join (cmd )
@@ -65,6 +105,8 @@ def stop(self):
65
105
ph = ord (rec_packet [5 ])
66
106
pv = ord (rec_packet [10 ])
67
107
108
+ ret = [az , el , ph ]
109
+
68
110
assert (ph == pv )
69
111
self .pulse = ph
70
112
@@ -75,6 +117,14 @@ def stop(self):
75
117
print ("PH: " + str (ph ))
76
118
print ("PV: " + str (pv ) + "\n " )
77
119
120
+ return ret
121
+
122
+ '''
123
+ send a SET command to the controller, which causes the rotor to adjust its position
124
+ to the azimuth and elevation specified by the azi and eli parameters respecitvely.
125
+ The azi and eli parameters are floating point values that specify the desired position.
126
+ There is no response to the SET command, thus nothing to return.
127
+ '''
78
128
def set (self , azi , eli ):
79
129
az = "0" + str ((self .pulse * (azi + 360 )))
80
130
el = "0" + str ((self .pulse * (eli + 360 )))
@@ -94,6 +144,10 @@ def set(self, azi, eli):
94
144
95
145
time .sleep (1 )
96
146
147
+ '''
148
+ Calls the STATUS, STOP and SET functions multiple times
149
+ in order to test the rot2proG class functionality
150
+ '''
97
151
def test (self ):
98
152
rot = Rot2proG (True )
99
153
rot .status ()
0 commit comments