Checks if (*wheels have rotated for a given number of degrees*): * The left *wheel* has rotated for ``left_target_degrees`` degrees. * The right *wheel* has rotated for ``right_target_degrees`` degrees. If both conditions are met, it returns ``True``, oth
(self, left_target_degrees, right_target_degrees)
| 594 | |
| 595 | |
| 596 | def target_reached(self, left_target_degrees, right_target_degrees): |
| 597 | """ |
| 598 | Checks if (*wheels have rotated for a given number of degrees*): |
| 599 | |
| 600 | * The left *wheel* has rotated for ``left_target_degrees`` degrees. |
| 601 | * The right *wheel* has rotated for ``right_target_degrees`` degrees. |
| 602 | |
| 603 | If both conditions are met, it returns ``True``, otherwise it's ``False``. |
| 604 | |
| 605 | :param int left_target_degrees: Target degrees for the *left* wheel. |
| 606 | :param int right_target_degrees: Target degrees for the *right* wheel. |
| 607 | |
| 608 | :return: Whether both wheels have reached their target. |
| 609 | :rtype: boolean. |
| 610 | |
| 611 | For checking if the `GoPiGo3`_ robot has moved **forward** for ``360 / 360`` wheel rotations, we'd use the following code snippet. |
| 612 | |
| 613 | .. code-block:: python |
| 614 | |
| 615 | # both variables are measured in degrees |
| 616 | left_motor_target = 360 |
| 617 | right_motor_target = 360 |
| 618 | |
| 619 | # reset the encoders |
| 620 | gpg3_obj.reset_encoders() |
| 621 | # and make the robot move forward |
| 622 | gpg3_obj.forward() |
| 623 | |
| 624 | while gpg3_obj.target_reached(left_motor_target, right_motor_target): |
| 625 | # give the robot some time to move |
| 626 | sleep(0.05) |
| 627 | |
| 628 | # now lets stop the robot |
| 629 | # otherwise it would keep on going |
| 630 | gpg3_obj.stop() |
| 631 | |
| 632 | On the other hand, for moving the `GoPiGo3`_ robot to the **right** for ``187 / 360`` wheel rotations of the left wheel, we'd use the following code snippet. |
| 633 | |
| 634 | .. code-block:: python |
| 635 | |
| 636 | # both variables are measured in degrees |
| 637 | left_motor_target = 187 |
| 638 | right_motor_target = 0 |
| 639 | |
| 640 | # reset the encoders |
| 641 | gpg3_obj.reset_encoders() |
| 642 | # and make the robot move to the right |
| 643 | gpg3_obj.right() |
| 644 | |
| 645 | while gpg3_obj.target_reached(left_motor_target, right_motor_target): |
| 646 | # give the robot some time to move |
| 647 | sleep(0.05) |
| 648 | |
| 649 | # now lets stop the robot |
| 650 | # otherwise it would keep on going |
| 651 | gpg3_obj.stop() |
| 652 | |
| 653 | .. note:: |
no test coverage detected