Example #1
0
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
Example #2
0
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
Example #3
0
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
Example #4
0
def main():
    wp.wiringPiSetupGpio()
    ZumoButton().wait_for_press()
    global bbcon
    bbcon = BBCON()
    signal.signal(signal.SIGINT, signal_handler)

    run_forward = RunForward(bbcon, 2, [])
    bbcon.add_behavior(run_forward)
    bbcon.activate_behavior(run_forward)

    #stand_still = StandStill(bbcon, 1, [])
    #bbcon.add_behavior(stand_still)
    #bbcon.activate_behavior(stand_still)

    line_follower = LineFollower(bbcon, 5, [bbcon.sensobs['line_pos']])
    bbcon.add_behavior(line_follower)
    bbcon.activate_behavior(line_follower)

    find_red = FindRed(
        bbcon, 3, [bbcon.sensobs['red_search'], bbcon.sensobs['distance']])
    bbcon.add_behavior(find_red)

    avoid_walls = AvoidWalls(
        bbcon, 10, [bbcon.sensobs['distance'], bbcon.sensobs['proximity']])
    bbcon.add_behavior(avoid_walls)
    bbcon.activate_behavior(avoid_walls)

    while True:
        bbcon.run_one_timestep()
Example #5
0
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)
Example #6
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()
Example #7
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: ")
Example #8
0
File: run.py Project: 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.")