-
Notifications
You must be signed in to change notification settings - Fork 5
/
42129 EXPERIMENTAL.py
70 lines (57 loc) · 1.81 KB
/
42129 EXPERIMENTAL.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
#THIS IS AN EXPERIMENTAL VERSION!
#I DON'T HAVE THIS SET. I CAN NOT TEST THIS CODE PROPERLY!
#USAGE
#Change difflock with red buttons on remote
#SPECIAL THANKS to Profinerd for providing the port configuration
from pybricks.pupdevices import *
from pybricks.parameters import *
from pybricks.tools import wait
steering = Motor(Port.D)
driving = Motor(Port.B)
driving2 = Motor(Port.A)
diffLock = DCMotor(Port.C)
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)
#difflock calibration sequence
diffLock.dc(70)
wait(500)
diffLock.brake()
diffLockPosition = 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)
driving2.dc(100)
elif Button.LEFT_MINUS in pressed:
driving.dc(-100)
driving2.dc(-100)
else:
driving.brake()
driving2.brake()
if (Button.LEFT in pressed) and (diffLockPosition == 1):
diffLock.dc(70)
wait(500)
diffLock.brake()
diffLockPosition = 0
if (Button.RIGHT in pressed) and (diffLockPosition == 0):
diffLock.dc(-70)
wait(500)
diffLock.brake()
diffLockPosition = 1
#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)