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()
def test(): pins = get_pins() servo1 = Servo(pins["pan servo"]) servo2 = Servo(pins["tilt servo"]) print("Testing servo 1") time.sleep(1) print("Angle: 0") servo1.set_angle(0) time.sleep(1) print("Angle: 90") servo1.set_angle(90) time.sleep(1) print("Angle: 180") servo1.set_angle(180) time.sleep(1) servo1.set_angle(90) print("Testing servo 2") time.sleep(1) print("Angle: 0") servo2.set_angle(0) time.sleep(1) print("Angle: 90") servo2.set_angle(90) time.sleep(1) print("Angle: 180") servo2.set_angle(180) time.sleep(1) servo2.set_angle(90) print("Finished")
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()
def test(): pins = get_pins() GPIO.setmode(GPIO.BOARD) left_motor = HW95Motor(pins["left motor"], True) right_motor = HW95Motor(pins["right motor"], True) left_encoder = WheelEncoder(pins["left encoder"], 20, 3) right_encoder = WheelEncoder(pins["right encoder"], 20, 3) print("Testing left encoder") time.sleep(1) print("Moving left motor 20cm") left_motor.set_speed(50) left_encoder.reset() while left_encoder.get_distance() < 20: time.sleep(0.01) left_motor.set_speed(0) time.sleep(1) print("Measure the speed of the left motor") time.sleep(1) left_motor.set_speed(50) end_time = time.time() + 1.5 while time.time() < end_time: print(left_encoder.get_speed()) time.sleep(0.1) left_motor.set_speed(0) print("Testing right encoder") time.sleep(1) print("Moving right motor 20cm") right_motor.set_speed(50) right_encoder.reset() while right_encoder.get_distance() < 20: time.sleep(0.01) right_motor.set_speed(0) time.sleep(1) print("Measure the speed of the right motor") time.sleep(1) right_motor.set_speed(50) end_time = time.time() + 1.5 while time.time() < end_time: print(right_encoder.get_speed()) time.sleep(0.1) right_motor.set_speed(0) time.sleep(1) print("Finished") GPIO.cleanup()
def test(): pins = get_pins() GPIO.setmode(GPIO.BOARD) left_motor = HW95Motor(pins["left motor"], True) right_motor = HW95Motor(pins["right motor"], True) print("Testing left motor") time.sleep(1) print("Left motor forward at 50%") left_motor.set_speed(50) time.sleep(1) print("Left motor forward at 100%") left_motor.set_speed(100) time.sleep(1) print("Left motor stopping") left_motor.set_speed(0) time.sleep(1) print("Left motor backward at 50%") left_motor.set_speed(-50) time.sleep(1) print("Left motor backward at 100%") left_motor.set_speed(-100) time.sleep(1) left_motor.set_speed(0) print("Testing right motor") time.sleep(1) print("Right motor forward at 50%") right_motor.set_speed(50) time.sleep(1) print("Right motor forward at 100%") right_motor.set_speed(100) time.sleep(1) print("Right motor stopping") right_motor.set_speed(0) time.sleep(1) print("Right motor backward at 50%") right_motor.set_speed(-50) time.sleep(1) print("Right motor backward at 100%") right_motor.set_speed(-100) time.sleep(1) right_motor.set_speed(0) print("Finished") GPIO.cleanup()
def test(): pins = get_pins() GPIO.setmode(GPIO.BOARD) left = OptoInterrupter(pins["left opto-interrupter"]) right = OptoInterrupter(pins["right opto-interrupter"]) print("Reading left opto-interrupter") time.sleep(1) end_time = time.time() + 5 while time.time() < end_time: print(left.get_value()) time.sleep(0.05) print("Reading right opto-interrupter") time.sleep(1) end_time = time.time() + 5 while time.time() < end_time: print(right.get_value()) time.sleep(0.05) time.sleep(1) print("Finished") GPIO.cleanup()
forward <distance> backward <distance> right <degrees> left <degrees> exit """ import RPi.GPIO as GPIO from mechanisms.car import Car from pin_data import get_pins from sensors.mpu import Mpu from utils.updater import Updater pins = get_pins() GPIO.setmode(GPIO.BOARD) car = Car(pins["car"]) mpu = Mpu() updater = Updater(0.01) updater.add(car.update) updater.add(mpu.update) def run_car_until(condition_func): while not condition_func(): updater.update() def move_forward(distance):