MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / drive_cm

Method drive_cm

Software/Python/easygopigo3.py:304–341  ·  view source on GitHub ↗

Move the `GoPiGo3`_ forward / backward for ``dist`` amount of centimeters. | For moving the `GoPiGo3`_ robot forward, the ``dist`` parameter has to be *positive*. | For moving the `GoPiGo3`_ robot backward, the ``dist`` parameter has to be *negative*. :param float

(self, dist, blocking=True)

Source from the content-addressed store, hash-verified

302 self.NO_LIMIT_SPEED)
303
304 def drive_cm(self, dist, blocking=True):
305 """
306 Move the `GoPiGo3`_ forward / backward for ``dist`` amount of centimeters.
307
308 | For moving the `GoPiGo3`_ robot forward, the ``dist`` parameter has to be *positive*.
309 | For moving the `GoPiGo3`_ robot backward, the ``dist`` parameter has to be *negative*.
310
311 :param float dist: The distance in ``cm`` the `GoPiGo3`_ has to move.
312 :param boolean blocking = True: Set it as a blocking or non-blocking method.
313
314 ``blocking`` parameter can take the following values:
315
316 * ``True`` so that the method will wait for the `GoPiGo3`_ robot to finish moving.
317 * ``False`` so that the method will exit immediately while the `GoPiGo3`_ robot will continue moving.
318
319 """
320 # dist is in cm
321 # if dist is negative, this becomes a backward move
322
323 dist_mm = dist * 10
324
325 # the number of degrees each wheel needs to turn
326 WheelTurnDegrees = ((dist_mm / self.WHEEL_CIRCUMFERENCE) * 360)
327
328 # get the starting position of each motor
329 StartPositionLeft = self.get_motor_encoder(self.MOTOR_LEFT)
330 StartPositionRight = self.get_motor_encoder(self.MOTOR_RIGHT)
331
332 self.set_motor_position(self.MOTOR_LEFT,
333 (StartPositionLeft + WheelTurnDegrees))
334 self.set_motor_position(self.MOTOR_RIGHT,
335 (StartPositionRight + WheelTurnDegrees))
336
337 if blocking:
338 while self.target_reached(
339 StartPositionLeft + WheelTurnDegrees,
340 StartPositionRight + WheelTurnDegrees) is False:
341 time.sleep(0.1)
342
343 def drive_inches(self, dist, blocking=True):
344 """

Callers 7

robotControllerFunction · 0.95
drive_inchesMethod · 0.95
back_awayFunction · 0.80
drive_gpgFunction · 0.80
hardware_test.pyFile · 0.80
easy_Motors.pyFile · 0.80

Calls 3

target_reachedMethod · 0.95
get_motor_encoderMethod · 0.45
set_motor_positionMethod · 0.45

Tested by

no test coverage detected