-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
121 lines (86 loc) · 2.81 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
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import Port, Stop, Direction, Button, Color
from pybricks.tools import wait, StopWatch, DataLog
from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile, ImageFile
import time
import random
class BallE:
def __init__(self):
self.ev3 = EV3Brick()
# Const Definition
self.ballinSound = "ballin.wav"
self.diameter = 57
self.axes = 94
# Motor Definition
self.mr = Motor(Port.D)
self.ml = Motor(Port.A)
self.arm = Motor(Port.B)
# Sensor Definition
self.gyro = GyroSensor(Port.S1)
self.trans = DriveBase(self.mr, self.ml, self.diameter, self.axes)
#sound
self.speaker = self.ev3.speaker
self.speaker.set_volume(100)
def arm_rotate(self, rotation, time):
self.arm.run_time(rotation, time)
def turn(self, rotation):
self.trans.turn(rotation)
def turn_acc(self, rotation):
self.gyro.reset_angle(0)
while True:
if(self.gyro.angle() == 0):
break
while True:
if(self.gyro.speed() == 0):
break
"""
Above is all calibration
"""
while(self.gyro.angle() != rotation):
difference = rotation - self.gyro.angle()
turn_rate = (difference * 0.5)*-1
if turn_rate < 1 and turn_rate > 0:
self.trans.turn(1)
elif turn_rate < 0 and turn_rate > -1:
self.trans.turn(-1)
else:
self.trans.turn(turn_rate)
self.trans.stop()
print(self.gyro.angle())
def move(self, vel):
self.trans.straight(vel)
def dance(self):
self.ev3.speaker.play_file(self.ballinSound)
self.trans.turn(random.randrange(10, 360))
self.trans.straight(random.randrange(10,100))
def square(self):
balle.turn_acc(90)
balle.move(300)
balle.turn_acc(90)
balle.move(300)
balle.turn_acc(90)
balle.move(300)
balle.turn_acc(90)
balle.move(300)
balle = BallE()
def stationA03():
"""
stationA03 _summary_
"""
balle.move(680)
balle.turn_acc(70)
balle.arm_rotate(500,400)
balle.move(140)
balle.arm_rotate(-200, 600)
#station1.2
balle.move(-20)
balle.turn_acc(-160)
#nick
balle.ev3.speaker.play_file("ballin.wav")
balle.ev3.speaker.say("KUCKOKSMILSCH")
#balle.ev3.speaker.say("Tom ran over a cat with a lawnmower and blamed it on somebody else")
stationA03()