14
14
print ("ImportError: ModulinoPixels not installed" )
15
15
sys .exit (- 1 )
16
16
17
- VELOCITY = 13 # cm/s (max is 13cm/s)
18
- ANGULAR_VELOCITY = 250 # (max 320.8988764044944)
17
+ LINEAR_VELOCITY = 10 # (max 13cm/s)
18
+ ANGULAR_VELOCITY = 75 # (max 320.8988764044944)
19
19
FREEZE_FOR_SECONDS = 5
20
20
REVERT_CONTROLLER_FOR_SECONDS = 10
21
21
43
43
isPlayingReverted = False # if true the controller action are reverted
44
44
lifState = 0 # 0 = down, 1 = up
45
45
46
-
46
+ lin = 0
47
+ ang = 0
47
48
def receiveAndExecuteFromEspNow ():
48
49
global lifState
50
+ global lin
51
+ global ang
49
52
_ , msg = e .recv (
50
53
timeout_ms = 0
51
54
) # TODO: See ESPNow.irecv() for a memory-friendly alternative.
@@ -55,18 +58,19 @@ def receiveAndExecuteFromEspNow():
55
58
return
56
59
unpacked_message = struct .unpack ("B" , msg )
57
60
msg_type = unpacked_message [0 ]
61
+
58
62
if int (msg_type ) == STOP :
59
- a . drive ( 0 , 0 )
63
+ lin , ang = 0 , 0
60
64
elif int (msg_type ) == GO_FORWARD :
61
- v = VELOCITY if isPlayingReverted else - VELOCITY
62
- a . drive ( v , 0 )
65
+ lin = LINEAR_VELOCITY if isPlayingReverted else - LINEAR_VELOCITY
66
+ ang = 0
63
67
elif int (msg_type ) == GO_BACKWARD :
64
- v = - VELOCITY if isPlayingReverted else VELOCITY
65
- a . drive ( v , 0 )
68
+ lin = - LINEAR_VELOCITY if isPlayingReverted else LINEAR_VELOCITY
69
+ ang = 0
66
70
elif int (msg_type ) == TURN_LEFT :
67
- a . drive ( 0 , ANGULAR_VELOCITY )
71
+ ang = - ANGULAR_VELOCITY if isPlayingReverted else ANGULAR_VELOCITY
68
72
elif int (msg_type ) == TURN_RIGHT :
69
- a . drive ( 0 , - ANGULAR_VELOCITY )
73
+ ang = ANGULAR_VELOCITY if isPlayingReverted else - ANGULAR_VELOCITY
70
74
elif int (msg_type ) == LIFT :
71
75
if lifState == 0 :
72
76
liftUp ()
@@ -77,6 +81,7 @@ def receiveAndExecuteFromEspNow():
77
81
else :
78
82
print ("unknown command type " , msg_type )
79
83
84
+ a .drive (lin , ang )
80
85
81
86
def liftUp ():
82
87
a .set_servo_positions (180 , 0 )
0 commit comments