-
Notifications
You must be signed in to change notification settings - Fork 5
/
42124.py
38 lines (32 loc) · 1.03 KB
/
42124.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
from pybricks.pupdevices import *
from pybricks.parameters import *
from pybricks.tools import wait
steering = Motor(Port.B)
driving = Motor(Port.A)
remoteControl = Remote()
#steering calibration sequence
steering.run_until_stalled(500)
steering.reset_angle(0)
steering.run_until_stalled(-500)
maxAngle = steering.angle()
steering.run_target(500, (maxAngle/2)+10)
steering.reset_angle(0)
#main loop
while True:
#update pressed buttons information
pressed = remoteControl.buttons.pressed()
#commands to drive forwards or backwards
if Button.LEFT_PLUS in pressed:
driving.dc(100)
elif Button.LEFT_MINUS in pressed:
driving.dc(-100)
else:
driving.brake()
#commands to steer
if Button.RIGHT_PLUS in pressed:
steering.run_target(1200, (maxAngle/2)-5, Stop.HOLD,False)
elif Button.RIGHT_MINUS in pressed:
steering.run_target(1200, -((maxAngle/2)-5), Stop.HOLD,False)
else:
steering.run_target(1200, 0, Stop.HOLD, False)
wait(100)