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

Function TurnDegrees

Software/Python/Examples/Motor_Turn.py:22–38  ·  view source on GitHub ↗
(degrees, speed)

Source from the content-addressed store, hash-verified

20GPG = gopigo3.GoPiGo3() # Create an instance of the GoPiGo3 class. GPG will be the GoPiGo3 object.
21
22def TurnDegrees(degrees, speed):
23 # get the starting position of each motor
24 StartPositionLeft = GPG.get_motor_encoder(GPG.MOTOR_LEFT)
25 StartPositionRight = GPG.get_motor_encoder(GPG.MOTOR_RIGHT)
26
27 # the distance in mm that each wheel needs to travel
28 WheelTravelDistance = ((GPG.WHEEL_BASE_CIRCUMFERENCE * degrees) / 360)
29
30 # the number of degrees each wheel needs to turn
31 WheelTurnDegrees = ((WheelTravelDistance / GPG.WHEEL_CIRCUMFERENCE) * 360)
32
33 # Limit the speed
34 GPG.set_motor_limits(GPG.MOTOR_LEFT + GPG.MOTOR_RIGHT, dps = speed)
35
36 # Set each motor target
37 GPG.set_motor_position(GPG.MOTOR_LEFT, (StartPositionLeft + WheelTurnDegrees))
38 GPG.set_motor_position(GPG.MOTOR_RIGHT, (StartPositionRight - WheelTurnDegrees))
39
40try:
41 TurnDegrees(90, 100) # turn 90 degrees to the right, at a wheel speed of 100 degrees per second

Callers 1

Motor_Turn.pyFile · 0.85

Calls 3

get_motor_encoderMethod · 0.45
set_motor_limitsMethod · 0.45
set_motor_positionMethod · 0.45

Tested by

no test coverage detected