(degrees, speed)
| 20 | GPG = gopigo3.GoPiGo3() # Create an instance of the GoPiGo3 class. GPG will be the GoPiGo3 object. |
| 21 | |
| 22 | def 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 | |
| 40 | try: |
| 41 | TurnDegrees(90, 100) # turn 90 degrees to the right, at a wheel speed of 100 degrees per second |
no test coverage detected