コード例 #1
0
ファイル: smart_motor.py プロジェクト: zachlambert/pi_car
def test():
    GPIO.setmode(GPIO.BOARD)
    pins = get_pins()
    left_motor = SmartMotor(pins["left motor"], pins["left encoder"], 20, 3,
                            True)
    right_motor = SmartMotor(pins["right motor"], pins["right encoder"], 20, 3,
                             True)
    updater = Updater(0.01)
    updater.add(left_motor.update)
    updater.add(right_motor.update)

    print("Testing SmartMotor")
    time.sleep(1)
    print("Move forward in a straight line by giving the motors equal speeds")
    left_motor.set_velocity(15)
    right_motor.set_velocity(15)
    updater.reset_timer()
    while updater.timer < 2:
        updater.update()
    left_motor.set_velocity(0)
    right_motor.set_velocity(0)
    time.sleep(1)

    print("Rotate on the spot by giving the motors opposite speeds")
    left_motor.set_velocity(15)
    right_motor.set_velocity(-15)
    updater.reset_timer()
    while updater.timer < 2:
        updater.update()
    left_motor.set_velocity(0)
    right_motor.set_velocity(0)
    time.sleep(1)

    print("Varying the speed of left motor")
    start_speed = 0
    end_speed = 40
    updater.add(lambda dt: left_motor.set_velocity(start_speed + (
        end_speed - start_speed) * (updater.timer / 3)))
    updater.reset_timer()
    while updater.timer < 3:
        updater.update()
    updater.remove(-1)
    updater.add(lambda dt: left_motor.set_velocity(end_speed - (
        end_speed - start_speed) * (updater.timer / 3)))
    updater.reset_timer()
    while updater.timer < 3:
        updater.update()
    updater.remove(-1)
    left_motor.set_velocity(0)

    print("Finished")
    GPIO.cleanup()
コード例 #2
0
def test():
    GPIO.setmode(GPIO.BOARD)
    pins = get_pins()
    car = Car(pins["car"])
    updater = Updater(0.01)
    updater.add(car.update)

    print("Moving straight forward")
    car.set_velocities(15, 0)
    updater.reset_timer()
    while updater.timer < 2:
        updater.update()
    print("Rotating on the spot at 90 degrees per second")
    car.set_velocities(0, -90)
    updater.reset_timer()
    while updater.timer < 2:
        updater.update()
    print("Reversing and turning left with turning radius 20cm")
    car.set_velocities(-20, math.degrees(1))
    updater.reset_timer()
    while updater.timer < 2:
        updater.update()
    car.set_velocities(0, 0)

    print("Finished")
    GPIO.cleanup()