-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuntracker.py
271 lines (217 loc) · 6.52 KB
/
suntracker.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/env python3
# coding: latin-1
#Import library functions we need
import PicoBorgRev
from time import sleep
from pysolar.solar import *
import datetime
import time
from tkinter import*
from threading import Thread
import microstacknode.hardware.gps.l80gps as mst
gps=mst.L80GPS()
window=Tk()
# Tell the system how to drive the stepper
sequence = [[1.0, 1.0], [1.0, -1.0], [-1.0, -1.0], [-1.0, 1.0]] # Order for stepping
stepDelay = 0.002 # Delay between steps
# Name the global variables here:
global step
global PBR
#Setup the PicoBorg Reverse here:
PBR = PicoBorgRev.PicoBorgRev()
PBR.i2cAddress = 0x44 # Uncomment and change the value if you have changed the board address
PBR.Init()
#add varibles here:
step = -1
#highlight thickness
ht=3
#colour
colour="blue"
#text colour
tc="white"
#background colour
bg="light green"
#setting up window here:
window.title("Stepper control")
global end
end = 1
varible=StringVar(window)
varible.set("auto")
window.geometry("500x500+700+200")
window.configure(background=bg)
#add functions here:
def MoveStep(count):
global step
global PBR
# Choose direction based on sign (+/-)
if count < 0:
dir = -1
count *= -1
else:
dir = 1
# Loop through the steps
while count > 0:
# Set a starting position if this is the first move
if step == -1:
drive = sequence[-1]
PBR.SetMotor1(drive[0])
PBR.SetMotor2(drive[1])
step = 0
else:
step += dir
# Wrap step when we reach the end of the sequence
if step < 0:
step = len(sequence) - 1
elif step >= len(sequence):
step = 0
# For this step set the required drive values
if step < len(sequence):
drive = sequence[step]
PBR.SetMotor1(drive[0])
PBR.SetMotor2(drive[1])
sleep(stepDelay)
count -= 1
def auto():
end=False
print("Please point the umbrella to south. This program will start in 10 seconds.")
sleep(10)
# Start by turning all drives off
PBR.MotorsOff()
# Loop forever
oldc=0
proc=0
g=gps.get_gpgll()
while True:
d=datetime.datetime.now()
a=get_azimuth(g['latitude'], g['longitude'], d)
c=a/1.8
print(str(round(c))+' '+str(round(a)))
proc=c-oldc
steps = int(round(proc))
oldc=round(c)
if varible.get() == "manuel":
end = True
elif varible.get() == "auto":
end == False
if (end == True):
PBR.MotorsOff()
print("ended")
break
else:
MoveStep(steps)
sleep(4)
PBR.MotorsOff()
sleep(56)
# Move the specified amount of steps
def manuel1():
MoveStep(20)
def manuel2():
MoveStep(-20)
def gget():
#print(varible.get())
gget2=varible.get()
if gget2 == "auto":
thread1()
else:
manual()
def thread1():
threads = []
t1=Thread(target=auto)
t1.start()
b.place(relx=0.5,rely=0.05,anchor=CENTER)
l.place(relx=0.5,rely=0.15,anchor=CENTER)
bt.place(relx=0.5,rely=0.25,anchor=CENTER)
l2.place_forget()
bt2.place_forget()
bt3.place_forget()
bt5.place_forget()
s.place_forget()
e.place_forget()
bt6.place_forget()
def manual():
global end
end=True
l2.place(relx=0.5,rely=0.4,anchor=CENTER)
bt2.place(relx=0.5,rely=0.5,anchor=CENTER)
bt3.place(relx=0.5,rely=0.6,anchor=CENTER)
bt5.place(relx=0.5,rely=0.8,anchor=CENTER)
s.place(relx=0.5,rely=0.7,anchor=CENTER)
e.place(relx=0.5,rely=0.9,anchor=CENTER)
bt6.place(relx=0.5,rely=0.95,anchor=CENTER)
def close():
exit()
def movespef():
v=int(s.get())
MoveStep(v)
def confirm():
v2=int(e.get())
if v2 > int(500):
e.delete(0,END)
e.insert(0,"0")
print("too high")
elif v2 < int(-500):
e.delete(0,END)
e.insert(0,"0")
print("too low")
else:
e.delete(0,END)
e.insert(0,"0")
MoveStep(v2)
def stop():
if varible.get() == "auto":
print("cant do that")
else:
PBR.MotorsOff()
def clock():
while True:
t=time.asctime(time.localtime(time.time()))
l3.pack_forget()
l3.config(text=t)
l3.place(relx=0.8,rely=0.1,anchor=CENTER)
l3=Label(window,text="hello",fg=tc,bg=colour)
l3.place(relx=0.8,rely=0.1,anchor=CENTER)
threads2=[]
t2=Thread(target=clock)
t2.start()
#add auto/buttons at top here:
b=OptionMenu(window,varible,"auto","manuel")
b.place(relx=0.5,rely=0.05,anchor=CENTER)
l=Label(window,text="Auto or Manual",bg=colour,fg=tc)
l.place(relx=0.5,rely=0.15,anchor=CENTER)
bt=Button(window,text="press to confirm",command=gget,highlightbackground=colour,highlightthickness=ht)
bt.place(relx=0.5,rely=0.25,anchor=CENTER)
#add manuel controlls here:
l2=Label(window,text="----------------------------Manual controls----------------------------",bg=colour,fg=tc)
l2.place(relx=0.5,rely=0.4,anchor=CENTER)
bt2=Button(window,text="forwards",command=manuel1,highlightbackground=colour,highlightthickness=ht)
bt2.place(relx=0.5,rely=0.5,anchor=CENTER)
bt3=Button(window,text="back",command=manuel2,highlightbackground=colour,highlightthickness=ht)
bt3.place(relx=0.5,rely=0.6,anchor=CENTER)
s = Scale(window,from_=-100,to=100,orient=HORIZONTAL,highlightbackground=colour,highlightthickness=ht)
s.place(relx=0.5,rely=0.7,anchor=CENTER)
bt5=Button(window,command=movespef,text="move steps",highlightbackground=colour,highlightthickness=ht)
bt5.place(relx=0.5,rely=0.8,anchor=CENTER)
e=Entry(window,bg="red",highlightbackground=colour,highlightthickness=ht)
e.place(relx=0.5,rely=0.9,anchor=CENTER)
e.insert(0,"0")
bt6=Button(window,text="confirm",command=confirm,highlightbackground=colour,highlightthickness=ht)
bt6.place(relx=0.5,rely=0.95,anchor=CENTER)
#~~~~~~~~~~~~~~~~~~~~~~#
menu = Menu(window,bg=colour,fg=tc)
sub = Menu(menu, tearoff=False)
sub2 = Menu(menu, tearoff=False)
#add menu options here:
sub.add_command(label="Stop All",command=stop)
sub.add_command(label="Exit",command=close)
#add more menus here:
menu.add_cascade(label="Menu", menu=sub)
window.config(menu=menu)
#add place_forget here:
s.place_forget()
bt5.place_forget()
e.place_forget()
bt6.place_forget()
l2.place_forget()
bt2.place_forget()
bt3.place_forget()
mainloop()