-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathBlueDotPirateMixed.py
62 lines (47 loc) · 1.48 KB
/
BlueDotPirateMixed.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
from bluedot import BlueDot
from signal import pause
from explorerhat import motor
maxPower = 1.0
def pos_to_values(x, y):
left = y if x > 0 else y + x
right = y if x < 0 else y - x
return (clamped(left), clamped(right))
def clamped(v):
return max(-1, min(1, v))
def drive():
global maxPower
x_axis = 0.0
y_axis = 0.0
min_power = 0.3
while True:
if bd.is_pressed:
x_axis, y_axis = bd.position.x, bd.position.y
print(x_axis,y_axis)
else:
x_axis, y_axis = 0, 0
if abs(x_axis) < min_power:
x_axis = 0
if abs(y_axis) < min_power:
y_axis = 0
mixer_results = mixer(x_axis, y_axis)
power_left = ((mixer_results[0]) * 100)
power_right = ((mixer_results[1]) * 100)
# print(power_left, power_right)
motor.one.speed((-power_right * maxPower))
motor.two.speed(power_left * maxPower)
def mixer(inYaw, inThrottle,):
left = inThrottle + inYaw
right = inThrottle - inYaw
scaleLeft = abs(left)
scaleRight = abs(right)
scaleMax = max(scaleLeft, scaleRight)
scaleMax = max(1, scaleMax)
out_left = (constrain(left / scaleMax, -1, 1))
out_right = (constrain(right / scaleMax, -1, 1))
results = [out_right, out_left]
return results
def constrain(val, min_val, max_val):
return min(max_val, max(min_val, val))
bd = BlueDot()
drive()
pause()