forked from pranavdasan/FLL2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
175 lines (159 loc) · 5.02 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
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
#!/usr/bin/env python3
import ev3dev.ev3
from ev3dev2.motor import MoveTank, OUTPUT_B, OUTPUT_C, OUTPUT_D, OUTPUT_A, SpeedPercent, follow_for_ms, SpeedRPM, LargeMotor, MoveSteering, MediumMotor
from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3, INPUT_4
from ev3dev2.sensor.lego import GyroSensor
from ev3dev2.button import Button
from ev3dev2.sound import Sound
from time import sleep
import time, init
import os
import Run1
import tvrun
import Navigation
import PodSA
import tvrun
# Main program
def main():
#Set Up
sound = Sound()
tank = Navigation.tank_init()
btn = Button()#hi
flipper = LargeMotor(OUTPUT_C)
colorful_flipper = flipper
flip_flop = MediumMotor(OUTPUT_D)
#Reset
tank.reset()
tank.gyro.reset()
flipper.reset()
flip_flop.reset()
os.system('setfont Lat15-TerminusBold32x16')
sound.play_tone(1500,0.3) #gyro is working!
#PUT THE FUNCTION IN THE ELSE STATEMENT
#Latest version of executing the latest functions (yeah I know, it's repetitive)
def left(state):
if state:
pass
else:
try:
print("Platform")
tank.gyro.reset()
starttime = time.time()
Run1.PlatformRun(tank, flipper, flip_flop)
init.debug_print(time.time()-starttime)
print(time.time()-starttime)
tank.reset()
flipper.reset()
flip_flop.reset()
except (RuntimeError, TypeError, NameError, SyntaxError):
tank.reset()
tank.gyro.reset()
flipper.reset()
flip_flop.reset()
pass
def up(state):
if state:
pass
else:
try:
starttime = time.time()
print("Dino Run")
tank.gyro.reset()
PodSA.newest_dino_powerplant(tank, flipper, flip_flop)
init.debug_print(time.time()-starttime)
tank.reset()
flipper.reset()
flip_flop.reset()
except (RuntimeError, TypeError, NameError, SyntaxError):
tank.reset()
tank.gyro.reset()
flipper.reset()
flip_flop.reset()
pass
def right(state):
if state:
pass
else:
try:
print("TV Run")
tank.gyro.reset()
tvrun.tv(tank, colorful_flipper)
tvrun.windmill(tank, colorful_flipper)
tvrun.toystory3(tank, colorful_flipper)
tank.reset()
flipper.reset()
flip_flop.reset()
except (RuntimeError, TypeError, NameError, SyntaxError):
tank.reset()
tank.gyro.reset()
flipper.reset()
flip_flop.reset()
pass
def down(state):
if state:
pass
else:
try:
print("Innov Run")
tank.gyro.reset()
PodSA.finalwater_reservoir_hangonhook(tank, flipper, flip_flop)
tank.reset()
flipper.reset()
flip_flop.reset()
except (RuntimeError, TypeError, NameError, SyntaxError):
tank.reset()
tank.gyro.reset()
flipper.reset()
flip_flop.reset()
pass
def enter(state):
if state:
pass
else:
try:
print("Energy Storage")
tank.gyro.reset()
starttime = time.time()
Run1.EnergyStorage(tank, flipper, flip_flop)
init.debug_print(time.time()-starttime)
print(time.time()-starttime)
tank.reset()
flipper.reset()
flip_flop.reset()
except (RuntimeError, TypeError, NameError, SyntaxError):
tank.reset()
tank.gyro.reset()
flipper.reset()
flip_flop.reset()
pass
btn.on_left = left
btn.on_right = right
btn.on_up = up
btn.on_down = down
btn.on_enter = enter
# This loop checks button states continuously (every 0.01s).
# If the new state differs from the old state then the appropriate
# button event handlers are called.
'''
tank.gyro.reset()
tank.turn_degrees(10,90)
print(tank.gyro.angle)
sleep(2)
tank.turn_degrees(10,90)
print(tank.gyro.angle)
sleep(2)
tank.turn_degrees(10,90)
print(tank.gyro.angle)
sleep(2)
tank.turn_degrees(10,90)
print(tank.gyro.angle)
sleep(2)
'''
sound.play_tone(2500,0.1)
sound.play_tone(2000,0.1) #everythig is working fine now
while True:
print(tank.gyro.angle)
btn.process()
sleep(0.01)
if __name__ == "__main__":
main()