示例#1
0
文件: main.py 项目: runaraj/Proglab
def lineTest():
    reflect = ReflectanceSensors()
    ZumoButton().wait_for_press()
    motor = Motors()

    stuck = CheckStuck()

    camera = Camera()

    motob = Motob(motor)
    arbitrator = Arbitrator(motob=motob)

    sensob = Sensob()
    sensob.set_sensors([reflect])
    bbcon = BBCON(arbitrator=arbitrator, motob=motob)
    bbcon.add_sensob(sensob)
    bbcon.set_checkStucker(stuck)

    b = LineFollow(1, [sensob])
    bbcon.add_behavior(b)


    timesteps = 0
    while timesteps < 30:
        bbcon.run_one_timestep()
        timesteps += 1
示例#2
0
文件: main.py 项目: runaraj/Proglab
def lineCollision():
    reflect = ReflectanceSensors()
    ZumoButton().wait_for_press()
    motor = Motors()
    stuck = CheckStuck()
    ultra = Ultrasonic()
    proxim = IRProximitySensor()
    sensobCol = Sensob()
    sensobCol.set_sensors([ultra, proxim])
    motob = Motob(motor=motor)
    sensobLine = Sensob()
    sensobLine.set_sensors([reflect])

    arb = Arbitrator(motob=motob)
    bbcon = BBCON(arbitrator=arb, motob=motob)
    bbcon.set_checkStucker(stuck)
    line = LineFollow(1, [sensobLine])
    col = CollisionAvoidance(1, [sensobCol])
    bbcon.add_behavior(line)
    bbcon.add_behavior(col)
    bbcon.add_sensob(sensobCol)
    bbcon.add_sensob(sensobLine)

    count = 0
    while count < 20:
        bbcon.run_one_timestep()
        count += 1
示例#3
0
文件: main.py 项目: runaraj/Proglab
def trackTest():
    ZumoButton().wait_for_press()
    motor = Motors()
    ultra = Ultrasonic()
    camera = Camera()


    stuck = CheckStuck()
    motob = Motob(motor)
    arbitrator = Arbitrator(motob=motob)

    sensob = Sensob()
    sensob.set_sensors([ultra, camera])

    bbcon = BBCON(arbitrator=arbitrator, motob=motob)
    b = TrackObject(priority=1, sensobs=[sensob])
    bbcon.set_checkStucker(stuck)
    bbcon.add_behavior(b)

    bbcon.activate_behavior(0)
    bbcon.add_sensob(sensob)

    timesteps = 0
    while timesteps < 25:

        bbcon.run_one_timestep()
        timesteps += 1
示例#4
0
def start():
    bbcon = BBCON()
    arb = Arbitrator(bbcon)
    motor = Motors()
    reflect_sens = ReflectanceSensors(False)
    cam = Camera()
    ir = IR()
    ultra = Ultrasonic()

    bbcon.add_motobs(motor)
    bbcon.set_arb(arb)
    bbcon.add_behaviour(AvoidObj(bbcon, ultra, ir))
    bbcon.add_behaviour(Behaviour_line_follower(bbcon, reflect_sens))
    bbcon.add_behaviour(fub(bb=bbcon))
    #behaviour avoid blue, has to be added last, do not change this, will screw up bbcon code
    bbcon.add_behaviour(Behaviour_avoid_blue(bb=bbcon, cam=cam, ultra=ultra))
    bbcon.add_sensob(reflect_sens)
    bbcon.add_sensob(ir)
    bbcon.add_sensob(ultra)
    #cam has to be added last, will screw up bbcon code if not
    bbcon.add_sensob(cam)

    butt = ZumoButton()
    butt.wait_for_press()
    print("Start zumo")

    while True:
        bbcon.run_one_timestep()
示例#5
0
def main():
    bbcon1 = BBCON()  # Create BBCON

    # Motors
    motor1 = Motors()  # Create a Motor
    motob1 = Motob(motor1)  # Create a motob
    bbcon1.motobs = [motob1]  # Give Motor to BBCON

    zumo_button = ZumoButton()  # Sets up pins and Zumobutton

    # Add setup for camera, and add it to BBCON when we want to test everything together
    camera_sensor = FindRedSensob()  # Create obstacle sensob
    find_and_follow_behavior = FindAndFollowRedBallBehavior(
        bbcon1, 3)  # Create obstacle Behavior
    camera_sensor.add_behavior(
        find_and_follow_behavior)  # Give sensob the behavior

    bbcon1.add_behavior(find_and_follow_behavior)  # Give BBCON the behavior
    bbcon1.add_sensob(camera_sensor)

    motor1.stop()  # Stop all motors

    print("\nAll creation is done, entering main loop\n")

    q = ""
    while q is not 'q':
        zumo_button.wait_for_press()

        for i in range(0, 10):
            print("Iteration " + str(i))
            if bbcon1.run_one_timestep():
                motor1.stop()
                exit()
        motor1.stop()
        q = input("Press 'q' to quit: ")
    exit()
示例#6
0
def main():

    zumo_button = ZumoButton()  # Sets up pins and Zumobutton
    zumo_button.wait_for_press()

    bbcon1 = BBCON()                                            # Create BBCON

    #Motors
    motor1 = Motors()                                           # Create a Motor
    motob1 = Motob(motor1)                                      # Create a motob

    bbcon1.motobs = [motob1]                                    # Give Motor to BBCON

    # Collision avoidance
    ultra_sensor = ObstacleDetectionSensob()                    # Create obstacle sensob
    avoid_object = AvoidObstacleBehavior(bbcon1, 1.5)             # Create obstacle Behavior
    ultra_sensor.add_behavior(avoid_object)                     # Give sensob the behavior

    bbcon1.add_behavior(avoid_object)                           # Give BBCON the behavior
    bbcon1.add_sensob(ultra_sensor)                             # Give BBCON the sensor

    # Line follow
    line_sensor = IRSensob()                                    # Create IR sensob
    line_follow = FollowLineBehavior(bbcon1, 0.5)                 # Create linefollow behavior
    line_follow.add_sensob(line_sensor)                         # Give linefollow sin sensob

    bbcon1.add_behavior(line_follow)                            # Give BBCON the linefollow
    bbcon1.add_sensob(line_sensor)                              # Give BBCON the IR sensob

    # Add setup for camera, and add it to BBCON when we want to test everything together
    camera_sensor = FindRedSensob()  # Create obstacle sensob
    find_and_follow_behavior = FindAndFollowRedBallBehavior(bbcon1, 1)  # Create obstacle Behavior
    camera_sensor.add_behavior(find_and_follow_behavior)  # Give sensob the behavior

    bbcon1.add_behavior(find_and_follow_behavior)  # Give BBCON the behavior
    bbcon1.add_sensob(camera_sensor)

    motor1.stop()                                               # Stop all motors

    print("\nAll creation is done, entering main loop\n")
    q = input("Press 'q' to quit: ")

    while q is not 'q':
                                                                #Runs 100 timesteps. Stops if q is pressed.
        for i in range(0, 100):
            print("\nIteration " + str(i))
            if bbcon1.run_one_timestep():
                motor1.stop()
                exit()
        motor1.stop()
        q = input("Press 'q' to quit: ")
示例#7
0
文件: main.py 项目: runaraj/Proglab
def systemTest():

    motor = Motors()
    ultra = Ultrasonic()
    proxim = IRProximitySensor()
    camera = Camera()
    reflectance = ReflectanceSensors()
    motob = Motob(motor)
    arbitrator = Arbitrator(motob)


    stuck = CheckStuck()
    collisionSensob = Sensob()
    collisionSensob.set_sensors([ultra, proxim])

    lineSensob = Sensob()
    lineSensob.set_sensors([reflectance])

    trackSensob = Sensob()
    trackSensob.set_sensors([ultra, camera])


    b = CollisionAvoidance(1, [collisionSensob])
    f = LineFollow(1, [lineSensob])
    t = TrackObject(1, [trackSensob])
    #print(collisionSensob.sensors)
    #print(lineSensob.sensors)
    bbcon = BBCON(arbitrator=arbitrator, motob=motob)
    bbcon.set_checkStucker(stuck)
    bbcon.add_behavior(b)
    bbcon.add_behavior(f)
    bbcon.add_behavior(t)
    #bbcon.activate_behavior(0)
    #bbcon.activate_behavior(1)
    #bbcon.activate_behavior(2)
    bbcon.add_sensob(collisionSensob)
    bbcon.add_sensob(lineSensob)
    bbcon.add_sensob(trackSensob)

    runTimesteps(bbcon, 100)
示例#8
0
文件: run.py 项目: Skattum/robot
    else:
        ZumoButton().wait_for_press()

    motors = Motors()
    motob = Motob(motors, commands)

    prios = {"carry_on": .1, "avoid_lines": 1, "obstacle": 3, "picture": 1}

    bbcon = BBCON(config_values, motob)

    behaviors = {
        "carry_on": CarryOn(bbcon, True, prios["carry_on"],
                            [sensobs["distnc"]]),
        "avoid_lines": AvoidLines(bbcon, True, prios["avoid_lines"],
                                  line_sensobs),
        "picture": Picture(bbcon, False, prios["picture"], [sensobs["rgbsns"]])
    }

    bbcon.add_behavior(behaviors["carry_on"])
    bbcon.add_behavior(behaviors["avoid_lines"])
    bbcon.add_behavior(behaviors["picture"])

    for sensob in sensobs.values():
        bbcon.add_sensob(sensob)

    while True:
        if bbcon.run_one_timestep():
            break

    print("ferdig.")