def drive_forwards_to_distance(distance=distance_to_wall):
    # counter =0
    print("drive_forwards_to_distance()")
    while DalekSensors.front_distance != distance:
        # get the speed to drive at
        speed = CalculateSpeedToDrive(DalekSensors.front_distance, distance)
        if DalekSensors.front_distance <= distance:
            drive.backward(speed)
            print("drive_backwards()")
        else:
            drive.paddleForward(speed, speed)
    drive.stop()
Example #2
0
    def tank_drive(_leftPaddle, _rightPaddle):
        debug.print_to_all_devices("left: {}  Right: {}".format(
            _leftPaddle, _rightPaddle))

        if (_leftPaddle == 0) and (_rightPaddle == 0):
            drive.stop()
            debug.clear()
        elif (_leftPaddle < 0) and (_rightPaddle < 0):
            drive.paddleForward(-_leftPaddle, -_rightPaddle)
            # debug.print_to_all_devices("forwards","Fw")
        elif (_leftPaddle > 0) and (_rightPaddle > 0):
            drive.paddleBackward(_leftPaddle, _rightPaddle)
            # debug.print_to_all_devices("Backwards", "Bw")
        elif (_leftPaddle <= 0) and (_rightPaddle >= 0):
            drive.turnForwardRight(-_leftPaddle, _rightPaddle)
            # debug.print_to_all_devices("Spin Right", "SR")
        elif (_leftPaddle >= 0) and (_rightPaddle <= 0):
            drive.turnForwardLeft(_leftPaddle, -_rightPaddle)