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)
| 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 | """ |
no test coverage detected