25
25
import sonar
26
26
27
27
PIN_MOTOR_ENABLE = 22
28
- PIN_LEFT_FORWARD = 25
29
- PIN_LEFT_BACKWARD = 24
30
- PIN_RIGHT_FORWARD = 4
31
- PIN_RIGHT_BACKWARD = 17
28
+ PIN_LEFT_FORWARD = 8
29
+ PIN_LEFT_BACKWARD = 7
30
+ PIN_RIGHT_FORWARD = 10
31
+ PIN_RIGHT_BACKWARD = 9
32
32
PIN_PUSHBUTTON = 11
33
- PIN_SERVO_3 = 9
34
- PIN_SERVO_4 = 10
35
- PIN_SONAR_1_TRIGGER = 18
36
- PIN_SONAR_1_ECHO = 7
37
- PIN_SONAR_2_TRIGGER = 18
38
- PIN_SONAR_2_ECHO = 8
39
- PIN_SONAR_3_TRIGGER = 18
40
- PIN_SONAR_3_ECHO = 23
41
- PIN_ENCODER_LEFT = 14
42
- PIN_ENCODER_RIGHT = 15
33
+ # PIN_SERVO_3 = 9
34
+ # PIN_SERVO_4 = 10
35
+ PIN_SONAR_1_TRIGGER = 17
36
+ PIN_SONAR_1_ECHO = 18
37
+ # PIN_SONAR_2_TRIGGER = 18
38
+ # PIN_SONAR_2_ECHO = 8
39
+ # PIN_SONAR_3_TRIGGER = 18
40
+ # PIN_SONAR_3_ECHO = 23
41
+ # PIN_ENCODER_LEFT = 14
42
+ # PIN_ENCODER_RIGHT = 15
43
43
44
44
PWM_FREQUENCY = 100 #Hz
45
45
PWM_RANGE = 100 #0-100
@@ -75,7 +75,7 @@ def __init__(self, servo=False, motor_trim_factor=1.0):
75
75
self ._is_moving = False
76
76
self .sonar = [sonar .Sonar (self .pi , PIN_SONAR_1_TRIGGER , PIN_SONAR_1_ECHO ),
77
77
sonar .Sonar (self .pi , PIN_SONAR_2_TRIGGER , PIN_SONAR_2_ECHO ),
78
- sonar .Sonar (self .pi , PIN_SONAR_3_TRIGGER , PIN_SONAR_3_ECHO )]
78
+ sonar .Sonar (self .pi , PIN_SONAR_3_TRIGGER , PIN_SONAR_3_ECHO )]
79
79
self ._encoder_cur_left = 0
80
80
self ._encoder_cur_right = 0
81
81
self ._encoder_target_left = - 1
@@ -127,7 +127,7 @@ def _dc_motor(self, speed_left=100, speed_right=100, elapse=-1, steps_left=-1, s
127
127
self ._encoder_cur_right = 0
128
128
self ._encoder_target_left = steps_left
129
129
self ._encoder_target_right = steps_right
130
-
130
+
131
131
self ._is_moving = True
132
132
if speed_left < 0 :
133
133
speed_left = abs (speed_left )
@@ -210,7 +210,7 @@ def callback(self, gpio, level, tick):
210
210
elapse = self ._cb_elapse .get (gpio )
211
211
if level == 0 :
212
212
self ._cb_last_tick [gpio ] = tick
213
- elif tick - self ._cb_last_tick [gpio ] > elapse :
213
+ elif tick - self ._cb_last_tick [gpio ] > elapse :
214
214
self ._cb_last_tick [gpio ] = tick
215
215
print "pushed: " , level , tick
216
216
cb ()
@@ -226,5 +226,3 @@ def reboot(self):
226
226
227
227
def sleep (self , elapse ):
228
228
time .sleep (elapse )
229
-
230
-
0 commit comments