예제 #1
0
    def startup(self):
        # add sensor objects
        cam = Sensob(Camera())
        ultrasonic = Sensob(Ultrasonic())
        ir_sensor = Sensob(ReflectanceSensors())
        self.add_sensob(cam)
        self.add_sensob(ultrasonic)
        self.add_sensob(ir_sensor)

        # add behaviors
        sb = StandardBehavior(self)
        self.add_behavior(sb)
        self.activate_behavior(sb)
        cb = CameraBehavior(self)
        self.add_behavior(cb)
        self.activate_behavior(cb)
        ub = UltraBehavior(self)
        self.add_behavior(ub)
        self.activate_behavior(ub)
        ir = IRBehavior(self)
        self.add_behavior(ir)
        self.activate_behavior(ir)

        button = ZumoButton()
        button.wait_for_press()
        self._running = True
        while self._running:
            self.run_one_timestep()
            # wait
            time.sleep(0.001)
예제 #2
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()
예제 #3
0
def main3():
    button = ZumoButton()
    distance_ob = Distanceob()
    camera_ob = Cameraob()
    ir_prox_ob = IRProximityob()

    count = 0

    bbcon = BBCON()

    behavior_stop_red = StopRed(bbcon=bbcon, sensobs=[distance_ob, camera_ob])
    behavior_follow_side = FollowSide(bbcon=bbcon, sensobs=[ir_prox_ob])
    behavior_drive = DriveAround(bbcon=bbcon)
    bbcon.add_behavior(behavior_stop_red)
    bbcon.add_behavior(behavior_drive)
    bbcon.add_behavior(behavior_follow_side)
    bbcon.add_sensob(distance_ob)
    bbcon.add_sensob(camera_ob)
    bbcon.add_sensob(ir_prox_ob)
    bbcon.activate_behavior(behavior_follow_side)
    bbcon.activate_behavior(behavior_stop_red)
    bbcon.activate_behavior(behavior_drive)

    button.wait_for_press()
    while count < 100:
        bbcon.run_one_timestep()
        count += 1
    def runOneTimestep(self):
        print("Starts")
        button = ZumoButton()
        button.wait_for_press()
        self.addSenob()
        self.addBehavior()
        pictureTime = 0
        while True:
            #print("Runns itteration")
            #Reads from active sensors
            activeSensors = []
            #Adds imageBehaviour
            if pictureTime > 3:
                self.active_behaviors.append(self.behaviors[3])

            for behavior in self.active_behaviors:
                sensorList = behavior.getSensobs()
                for sensor in sensorList:
                    if not activeSensors.__contains__(sensor):
                        activeSensors.append(sensor)
            #print("Adds to active sensors")
            for sensor in activeSensors:
                #print("Adds sensor")
                if (sensor != None):
                    sensor.update()
            #print("Update all behaviors")
            #Update all behaviors
            for behavior in self.active_behaviors:
                behavior.updateRecomendation()
            #print("About to chose action")
            #Requesting the motor recomendation and halt request flag
            behavior, requestFlag = self.abitrator.choose_action()
            #print("Action:", behavior.getMovement())
            if requestFlag:
                break
            #Update the motobs so that the motors are activated/deactivated
            self.motobs.recomend(behavior.getMovement())
            #print("Recomended movement")
            self.motobs.update()
            #print("Uppdated motors")

            if self.active_behaviors.__contains__(self.behaviors[3]):
                self.active_behaviors.remove(self.behaviors[3])
                pictureTime = 0

            #Wait. Defines how long the code should wait
            sleep(0.05)
            pictureTime = pictureTime + 1
            #Resets sensors
            for sensor in activeSensors:
                if sensor != None:
                    sensor.reset()
예제 #5
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: ")
예제 #6
0
def main():
    button = ZumoButton()
    ir_prox_ob = IRProximityob()

    count = 0

    bbcon = BBCON()

    behavior_follow_side = FollowSide(bbcon=bbcon, sensobs=[ir_prox_ob])
    behavior_drive = DriveAround(bbcon=bbcon)

    bbcon.add_behavior(behavior_follow_side)
    bbcon.add_behavior(behavior_drive)
    bbcon.add_sensob(ir_prox_ob)
    bbcon.activate_behavior(behavior_follow_side)
    bbcon.activate_behavior(behavior_drive)

    button.wait_for_press()
    while count < 100:
        bbcon.run_one_timestep()
        count += 1
예제 #7
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()
예제 #8
0
    # Tuple of a behavior's motor recommendations and a halt_flag (boolean)
    # We will update all motobs which will then update the settings
    # for all motors.
    def update_all_motobs(self, tuple):
        print(tuple)
        for i in range(len(self.motob)):
            # Motob can also check the halt_flag
            self.motob[i].update(tuple)


if __name__ == '__main__':
    bbcon = Bbcontroller()
    arbitrator = Arbitrator(bbcon)

    zumo = ZumoButton()
    zumo.wait_for_press()

    r = ReflectanceSensors()
    u = Ultrasonic()
    c = Camera()

    sensobs = [r, u, c]
    bbcon.arbitrator = arbitrator

    fl = FollowLine(bbcon, sensobs)
    ac = AvoidCollisions(bbcon, sensobs)
    sp = SnapPhoto(sensobs)
    ro = Rotate(sensobs)
    st = Stop(bbcon, sensobs)
    dc = DoCircles(sensobs)
예제 #9
0
    butt = ButtonFeeler()
    peep = Peeper()
    sensobs = {
        "fallingout": fall,
        "duckfinder": duck,
        "buttonfeeler": butt,
        "peeper": peep
    }
    print("Sensobs made")
    for sensob in sensobs:
        BBCON.add_sensob(sensob, sensobs[sensob])
    print("Sensobs added")
    stop = Stop(BBCON, 1.0)
    fall = DontFall(BBCON, 1.0)
    violate = ViolateDuck(BBCON, 0.8)
    find = FindDuck(BBCON, 0.8)
    # wander = Wander(BBCON, 0.1)
    behaviors = [stop, fall, violate, find]
    for behavior in behaviors:
        BBCON.add_behavior(behavior)
    print("Added behaviors to BBCON")
    BBCON.active_behaviors = BBCON.behaviors
    lil_pump = Motob()
    lil_pump.motors.stop()
    BBCON.add_motob(lil_pump)
    print("Duck hater initialized")
    button.wait_for_press()
    time.sleep(1)
    while not BBCON.halt:
        BBCON.run_one_timestep()