forked from MambaBlack29/ChakraSindhu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
81 lines (69 loc) · 2.49 KB
/
main.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
'''
Main file which compiles everything and manages all the control decisions
Gets inputs from update file
Gets logical made by yaw and machine files
Sends output from out file
'''
import asyncio
import update
import out
import machine
import yaw
class main:
'''
Attributes:
----------
update_obj: object of update class
yaw_obj: object of yaw class
machine_obj: object of machine class
out_obj: object of out class
'''
def __init__(self):
'''
Initialize all the objects and variables
'''
self.update_obj = update.update()
self.yaw_obj = yaw.yaw()
self.machine_obj = machine.machine()
self.out_obj = out.out()
self.update_obj.update_values()
# loop function, runs infinitely later on
async def loop(self):
'''
An async function which runs infinitely, updating all the values and making decisions
'''
# create async delay object to get exactly 1 second delay
delay_coroutine = asyncio.sleep(1)
# get the data from update
self.update_obj.update_values()
# based on the data, make changes in the logical variables
self.machine_obj.get_machine_brake()
self.yaw_obj.get_error_direction()
# now we have all the data, we can call output functions based on control values
# non extreme working conditions
if self.update_obj.mode == 0:
# avg direction of wind is more than tolerable
if self.yaw_obj.error > self.yaw_obj.yaw_tolerance_check:
# brake until motor off
while self.update_obj.machine_vel > 0:
self.out_obj.brake_on()
self.update_obj.update_values()
# yaw until error within tolerance
while self.yaw_obj.error > self.yaw_obj.yaw_tolerance_update:
self.out_obj.yaw_out()
self.update_obj.update_values()
# in either case, after error correction, run machine normally
self.out_obj.machine_out()
# extreme or abornal conditions
else:
# if:
pass
# waits for the remainder of 1 second till ending loop function
await delay_coroutine
if __name__ == '__main__':
main_obj = main() # runs the __init__ function = setup
try:
while True:
asyncio.run(main_obj.loop())
except KeyboardInterrupt:
main_obj.out_obj.cleanup()