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

Function drive_gpg

Software/Scratch/GoPiGo3Scratch.py:892–943  ·  view source on GitHub ↗

Handle driving forward or backward infinite, or X cm, or X inches, or X wheel rotations, or X seconds

(regObj)

Source from the content-addressed store, hash-verified

890
891
892def drive_gpg(regObj):
893 '''
894 Handle driving forward or backward
895 infinite, or X cm, or X inches, or X wheel rotations, or X seconds
896 '''
897 sensors = {}
898 incoming_drive = regObj.group(DRIVE_GROUP)
899 incoming_direction = ( 1 if regObj.group(DRIVE_DIRECTION_GROUP) != None else -1)
900 incoming_distance = regObj.group(DRIVE_DISTANCE_GROUP)
901 incoming_cm = regObj.group(DRIVE_CM_GROUP)
902 incoming_inches = regObj.group(DRIVE_INCHES_GROUP)
903 incoming_degrees = regObj.group(DRIVE_DEGREES_GROUP)
904 incoming_rotations = regObj.group(DRIVE_ROTATIONS_GROUP)
905 incoming_seconds = regObj.group(DRIVE_SECONDS_GROUP)
906 # start with the calls that will not require encoder readings
907 if incoming_distance == None:
908 if incoming_direction > 0:
909 # print("gpg forward")
910 gpg.forward()
911 else:
912 # print("gpg backward")
913 gpg.backward()
914 return None
915 # these will return encoder readings
916 try:
917 incoming_distance = float(incoming_distance)
918 except:
919 print("issue with casting distance to a float")
920 if incoming_cm:
921 # print ("gpg cm {}".format(incoming_distance*incoming_direction))
922 gpg.drive_cm(incoming_distance*incoming_direction, blocking=True)
923 elif incoming_inches:
924 # print ("gpg inches {}".format(incoming_distance*incoming_direction))
925 gpg.drive_inches(incoming_distance*incoming_direction, blocking=True)
926 elif incoming_degrees:
927 # print ("gpg degrees {}".format(incoming_distance*incoming_direction))
928 gpg.drive_degrees(incoming_distance*incoming_direction, blocking=True)
929 elif incoming_rotations:
930 # print ("gpg rotations {}".format(incoming_distance * incoming_direction))
931 gpg.drive_degrees(incoming_distance*incoming_direction*360, blocking=True)
932 elif incoming_seconds:
933 # print("gpg forward")
934 if incoming_direction > 0:
935 gpg.forward()
936 else:
937 gpg.backward()
938 time.sleep(incoming_distance)
939 gpg.stop()
940 # print ("gpg stopped")
941 sensors["Encoder Left"] = gpg.get_motor_encoder(gpg.MOTOR_LEFT)
942 sensors["Encoder Right"] = gpg.get_motor_encoder(gpg.MOTOR_RIGHT)
943 return(sensors)
944
945
946def setup_default_broadcasts():

Callers 1

handle_GoPiGo3_msgFunction · 0.85

Calls 7

drive_cmMethod · 0.80
drive_inchesMethod · 0.80
drive_degreesMethod · 0.80
forwardMethod · 0.45
backwardMethod · 0.45
stopMethod · 0.45
get_motor_encoderMethod · 0.45

Tested by

no test coverage detected