-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.py
105 lines (95 loc) · 3.15 KB
/
home.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
104
105
#!/usr/bin/env python3
import sys, math, time
from mpu import Sensor
from openastroclient import OpenAstroClient
#mpu9250
offsets = [-37.8, -24.2, 23.0, 19.0]
offsets = [-38.2, -24.2, 23.0, 19.0]
# new measure on table
offsets = [-37.6, -24.2, 22.9, 19.0]
##mpu6050
#offsets = [-7.1, -22.5, 2.0, 2.0]
# table
targets = [0, 0]
# front
#targets = [ -2.65, 45.72]
# back
#targets = [ -2.65, 45.72]
epsilon = 0.5
sensor = Sensor(offsets=offsets)
class Axis:
def __init__(self, target, steps, meade):
self.target = target
self.steps = steps
self.meade = meade
self.speed = -1
@property
def is_close(self, pos):
return math.fabs(self.target - pos) < epsilon
@property
def is_ra(self):
return self.meade == 'r'
@property
def current_position(self):
(a,b) = client.sendCommandAndWait(":GX#")
array = b.split(",")[2:4]
index = 0 if self.is_ra else 1
return array[index]
def do_home(self, pos):
sgn = -1 if self.is_ra else 1
steps = int(self.steps * sgn * (self.target - pos))
if(math.fabs(steps) < 500):
speed = 1
elif(math.fabs(steps) < 1000):
speed = 2
else:
speed = 3
if self.speed != speed:
self.speed = speed
speed_char = "GCMS"[self.speed]
client.sendCommandAndWait(f":R{speed_char}#")
cmd = f":MX{self.meade}{steps}#"
return cmd
def home(self):
done = False
while not done:
x,y = sensor.angles
pos = x if self.is_ra else y
diff = self.target - pos
done = math.fabs(diff) < epsilon
if not done:
cmd = self.do_home(pos)
print(f"\nTarget:{self.target:5.2f} pos:{pos:5.2f} delta:{diff:5.2f}")
client.sendCommand(cmd)
current_position = self.current_position
new_position = self.current_position
while new_position != current_position:
print(f"\rWaiting until target is reached, current: {current_position}, new: {new_position}", end="")
current_position = new_position
new_position = self.current_position
time.sleep(1)
#print(cmd)
#time.sleep(10)
ra = Axis(targets[0], 314.2, "r")
dec = Axis(targets[1], 314.2, "d")
if __name__ == '__main__':
if 1 == 1:
startx, starty = 0,0
while not False:
x,y = sensor.angles
# y = y + 45
print(f"\rX: {x:5.2f} Y: {y:5.2f} dX:{startx-x:5.2f} dY:{starty-y:5.2f}", end="")
time.sleep(1)
sys.exit(0)
client = OpenAstroClient(hostname="localhost")
client.debug = True
x,y = sensor.angles
print(f"\rX: {x:5.2f} Y: {y:5.2f} dX:{x-ra.target:5.2f} dY:{y-dec.target:5.2f}", end="")
for i in range(0,2):
ra.home()
dec.home()
client.sendCommandAndWait(":Q#")
client.sendCommandAndWait(":SHP#")
x,y = sensor.angles
print(f"\rX: {x:5.2f} Y: {y:5.2f} dX:{x-ra.target:5.2f} dY:{y-dec.target:5.2f}", end="")
time.sleep(1)