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

Method orbit

Software/Python/easygopigo3.py:517–593  ·  view source on GitHub ↗

Control the GoPiGo so it will orbit around an object. :param int degrees: Degrees to steer. **360** for full rotation. Negative for left turn. :param int radius_cm: Radius in `cm` of the circle to drive. Default is **0** (turn in place). :param boolean blo

(self, degrees, radius_cm=0, blocking=True)

Source from the content-addressed store, hash-verified

515
516
517 def orbit(self, degrees, radius_cm=0, blocking=True):
518 """
519 Control the GoPiGo so it will orbit around an object.
520
521 :param int degrees: Degrees to steer. **360** for full rotation. Negative for left turn.
522 :param int radius_cm: Radius in `cm` of the circle to drive. Default is **0** (turn in place).
523 :param boolean blocking = True: Set it as a blocking or non-blocking method.
524
525 .. important::
526 Note that while in non-blocking mode the speed cannot be changed before the end of the orbit as it would negate all orbit calculations.
527 After a non-blocking call, :py:meth:`~easygopigo3.EasyGoPiGo3.set_speed` has to be called before any other movement.
528 """
529 speed = self.get_speed()
530 radius = radius_cm * 10
531
532 # the total distance to drive in mm
533 drive_distance = math.pi * abs(radius) * abs(degrees) / 180 # / 180 is shorter than radius * 2 / 360
534
535 # the distance in mm to add to one motor and subtract from the other
536 drive_difference = ((self.WHEEL_BASE_CIRCUMFERENCE * degrees) / 360)
537
538 # the number of degrees each wheel needs to turn on average to get the necessary distance
539 distance_degrees = ((drive_distance / self.WHEEL_CIRCUMFERENCE) * 360)
540
541 # the difference between motor travel in degrees
542 difference_degrees = ((drive_difference / self.WHEEL_CIRCUMFERENCE) * 360)
543
544 # the distance each wheel needs to turn
545 left_target = (distance_degrees + difference_degrees)
546 right_target = (distance_degrees - difference_degrees)
547
548 # if it's a left turn
549 if degrees < 0:
550 MOTOR_FAST = self.MOTOR_RIGHT
551 MOTOR_SLOW = self.MOTOR_LEFT
552 fast_target = right_target
553 slow_target = left_target
554 else:
555 MOTOR_FAST = self.MOTOR_LEFT
556 MOTOR_SLOW = self.MOTOR_RIGHT
557 fast_target = left_target
558 slow_target = right_target
559
560 # determine driving direction from the speed
561 direction = 1
562 speed_with_direction = speed
563 if speed < 0:
564 direction = -1
565 speed_with_direction = -speed
566
567 # calculate the motor speed for each motor
568 fast_speed = speed_with_direction
569 slow_speed = abs((speed_with_direction * slow_target) / fast_target)
570
571 # set the motor speeds
572 self.set_motor_limits(MOTOR_FAST, dps = fast_speed)
573 self.set_motor_limits(MOTOR_SLOW, dps = slow_speed)
574

Callers

nothing calls this directly

Calls 6

get_speedMethod · 0.95
target_reachedMethod · 0.95
set_speedMethod · 0.95
set_motor_limitsMethod · 0.45
get_motor_encoderMethod · 0.45
set_motor_positionMethod · 0.45

Tested by

no test coverage detected