Skip to content

Commit bae046a

Browse files
committed
fix encoder
1 parent a1bb26e commit bae046a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

coderbot.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
PIN_LEFT_BACKWARD = 24
3030
PIN_RIGHT_FORWARD = 4
3131
PIN_RIGHT_BACKWARD = 17
32-
PIN_PUSHBUTTON = 18
32+
PIN_PUSHBUTTON = 11
3333
PIN_SERVO_3 = 9
3434
PIN_SERVO_4 = 10
3535
PIN_SONAR_1_TRIGGER = 18
@@ -76,6 +76,10 @@ def __init__(self, servo=False, motor_trim_factor=1.0):
7676
self.sonar = [sonar.Sonar(self.pi, PIN_SONAR_1_TRIGGER, PIN_SONAR_1_ECHO),
7777
sonar.Sonar(self.pi, PIN_SONAR_2_TRIGGER, PIN_SONAR_2_ECHO),
7878
sonar.Sonar(self.pi, PIN_SONAR_3_TRIGGER, PIN_SONAR_3_ECHO)]
79+
self._encoder_cur_left = 0
80+
self._encoder_cur_right = 0
81+
self._encoder_target_left = -1
82+
self._encoder_target_right = -1
7983
the_bot = None
8084

8185
def exit(self):
@@ -119,6 +123,8 @@ def get_sonar_distance(self, sonar_id=0):
119123
return self.sonar[sonar_id].get_distance()
120124

121125
def _dc_motor(self, speed_left=100, speed_right=100, elapse=-1, steps_left=-1, steps_right=-1 ):
126+
self._encoder_cur_left = 0
127+
self._encoder_cur_right = 0
122128
self._encoder_target_left = steps_left
123129
self._encoder_target_right = steps_right
124130

0 commit comments

Comments
 (0)