Handles all turn movements Turn left/right Turn left/right X degrees/seconds/rotations
(regObj)
| 834 | return None |
| 835 | |
| 836 | def turn_gpg(regObj): |
| 837 | ''' |
| 838 | Handles all turn movements |
| 839 | Turn left/right |
| 840 | Turn left/right X degrees/seconds/rotations |
| 841 | ''' |
| 842 | # these will return encoder readings |
| 843 | if regObj.group(DRIVE_TURN_AMOUNT): |
| 844 | # print("turn x amount") |
| 845 | try: |
| 846 | turn_amount = int(regObj.group(DRIVE_TURN_AMOUNT)) |
| 847 | except Exception as e: |
| 848 | print("turn_gpg: {}".format(e)) |
| 849 | pass |
| 850 | if regObj.group(DRIVE_TURN_LEFT): |
| 851 | turn_amount = turn_amount * -1 |
| 852 | if regObj.group(DRIVE_TURN_ROTATIONS): |
| 853 | turn_amount = turn_amount * 360 |
| 854 | # print ( "gpg turn {} degrees".format(turn_amount)) |
| 855 | gpg.turn_degrees(turn_amount,blocking=True) |
| 856 | elif regObj.group(DRIVE_TURN_SECONDS): |
| 857 | if regObj.group(DRIVE_TURN_LEFT): |
| 858 | # print("turning left") |
| 859 | gpg.left() |
| 860 | else: |
| 861 | # print("turning right") |
| 862 | gpg.right() |
| 863 | # don't use turn_amount here as it could be negative when |
| 864 | # going left |
| 865 | time.sleep(float(regObj.group(DRIVE_TURN_AMOUNT))) |
| 866 | gpg.stop() |
| 867 | # print("stopped") |
| 868 | # don't test for degrees per se as it's the default value |
| 869 | # and is optional |
| 870 | # left 90 is the same as left 90 degrees |
| 871 | else: |
| 872 | # print ( "gpg turn {} degrees".format(turn_amount)) |
| 873 | try: |
| 874 | gpg.turn_degrees(turn_amount,blocking=True) |
| 875 | except Exception as e: |
| 876 | print("turn_gpg: {}".format(e)) |
| 877 | pass |
| 878 | sensors["Encoder Left"] = gpg.get_motor_encoder(gpg.MOTOR_LEFT) |
| 879 | sensors["Encoder Right"] = gpg.get_motor_encoder(gpg.MOTOR_RIGHT) |
| 880 | return(sensors) |
| 881 | # calls that will not require encoder readings |
| 882 | if regObj.group(DRIVE_TURN_LEFT): |
| 883 | # print("turn left") |
| 884 | gpg.left() |
| 885 | return None |
| 886 | elif regObj.group(DRIVE_TURN_RIGHT): |
| 887 | # print("turn right") |
| 888 | gpg.right() |
| 889 | return None |
| 890 | |
| 891 | |
| 892 | def drive_gpg(regObj): |
no test coverage detected