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

Method drive_degrees

Software/Python/easygopigo3.py:361–413  ·  view source on GitHub ↗

Move the `GoPiGo3`_ forward / backward for ``degrees / 360`` wheel rotations. | For moving the `GoPiGo3`_ robot forward, the ``degrees`` parameter has to be *positive*. | For moving the `GoPiGo3`_ robot backward, the ``degrees`` parameter has to be *negative*. :par

(self, degrees, blocking=True)

Source from the content-addressed store, hash-verified

359 self.drive_cm(dist * 2.54, blocking)
360
361 def drive_degrees(self, degrees, blocking=True):
362 """
363 Move the `GoPiGo3`_ forward / backward for ``degrees / 360`` wheel rotations.
364
365 | For moving the `GoPiGo3`_ robot forward, the ``degrees`` parameter has to be *positive*.
366 | For moving the `GoPiGo3`_ robot backward, the ``degrees`` parameter has to be *negative*.
367
368 :param float degrees: Distance based on how many wheel rotations are made. Calculated by ``degrees / 360``.
369 :param boolean blocking = True: Set it as a blocking or non-blocking method.
370
371 ``blocking`` parameter can take the following values:
372
373 * ``True`` so that the method will wait for the `GoPiGo3`_ robot to finish rotating.
374 * ``False`` so that the method will exit immediately while the `GoPiGo3`_ robot will continue rotating.
375
376 For instance, the following function call is going to drive the `GoPiGo3`_ robot forward for *310 / 360* wheel rotations, which equates to aproximately *86%*
377 of the `GoPiGo3`_'s wheel circumference.
378
379 .. code-block:: python
380
381 gpg3_obj.drive_degrees(310)
382
383 On the other hand, changing the polarity of the argument we're passing, is going to make the `GoPiGo3`_ robot move backward.
384
385 .. code-block:: python
386
387 gpg3_obj.drive_degrees(-30.5)
388
389 This line of code makes the `GoPiGo3`_ robot go backward for *30.5 / 360* rotations, which is roughly *8.5%* of the `GoPiGo3`_'s wheel circumference.
390
391 """
392 # these degrees are meant to be wheel rotations.
393 # 360 degrees would be a full wheel rotation
394 # not the same as turn_degrees() which is a robot rotation
395 # degrees is in degrees, not radians
396 # if degrees is negative, this becomes a backward move
397
398 # get the starting position of each motor
399 StartPositionLeft = self.get_motor_encoder(self.MOTOR_LEFT)
400 StartPositionRight = self.get_motor_encoder(self.MOTOR_RIGHT)
401
402 self.set_motor_position(self.MOTOR_LEFT,
403 (StartPositionLeft + degrees))
404 self.set_motor_position(self.MOTOR_RIGHT,
405 (StartPositionRight + degrees))
406
407
408 if blocking:
409 while self.target_reached(
410 StartPositionLeft + degrees,
411 StartPositionRight + degrees) is False:
412 time.sleep(0.1)
413 return
414
415
416 def backward(self):

Callers 2

drive_gpgFunction · 0.80

Calls 3

target_reachedMethod · 0.95
get_motor_encoderMethod · 0.45
set_motor_positionMethod · 0.45

Tested by

no test coverage detected