Exemplo n.º 1
0
 def __init__(self):
     self.behaviors = []
     self.active_behaviors = []
     self.sensobs = []
     self.motob = Motob()
     self.arbitrator = Arbitrator(self)
     self.setup()
Exemplo n.º 2
0
 def __init__(self):
     self.behaviours = []  #list of all behavior objects (BHRs)
     self.active_behaviours = []  #a list of all currently-active BHRs.
     self.sensobs = []  #a list of all sensory objects
     self.motobs = [Motob()]  #a list of all motor objects
     self.arb = Arbitrator(
     )  #this resolves motor requests produced by the behaviors.
Exemplo n.º 3
0
    def __init__(self):
        # Initialize arbitrator
        self.arbitrator = Arbitrator()

        # Initialize motobs (single object for both motors on the Zumo)
        self.motobs.append(Motob(Motors()))

        # Initialize sensors

        self.sensors = {
            'ultrasonic': Ultrasonic(0.05),
            'IR': IRProximitySensor(),
            'reflectance': ReflectanceSensors(False, 0, 900),
            'camera': Camera(),
        }

        self.active_sensors = [self.sensors['ultrasonic'], self.sensors['IR'], self.sensors['reflectance']]


        # Initialize sensobs

        self.sensobs = {
            'distance': DistanceSensob([self.sensors['ultrasonic']]),
            'line_pos': LinePosSensob([self.sensors['reflectance']]),
            'proximity': ProximitySensob([self.sensors['IR']]),
            'red_search': RedSearchSensob([self.sensors['camera']]),
        }

        self.active_sensobs = [self.sensobs['distance'], self.sensobs['line_pos'], self.sensobs['proximity']]

        time.sleep(1)
Exemplo n.º 4
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
Exemplo n.º 5
0
def main():
    motob = Motob()
    bbcon = Bbcon(motob)
    arbitrator = Arbitrator(bbcon)
    bbcon.set_arbitrator(arbitrator)

    # sensorer og sensob
    ult_sensor = Ultrasonic()
    ref_sensor = ReflectanceSensors(auto_calibrate=False)
    reflectance_sensob = ReflectanceSensob(ref_sensor)
    ultrasonic_sensob = UltrasonicSensob(ult_sensor)
    camera_sensob = CameraSensob(None, color=0)

    #behaviors
    dont_crash = DontCrash(bbcon, ultrasonic_sensob)
    follow_line = FollowLine(bbcon, reflectance_sensob)
    find_object = FindColoredObject(bbcon, camera_sensob)

    bbcon.add_behavior(dont_crash)
    bbcon.add_behavior(follow_line)
    bbcon.add_behavior(find_object)
    try:
        ZumoButton().wait_for_press()
        while not bbcon.object_found:  # Kjører helt til vi finner objektet
            bbcon.run_one_timestep()
    except KeyboardInterrupt:
        motob.motor.stop()
    finally:
        GPIO.cleanup()
Exemplo n.º 6
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
Exemplo n.º 7
0
 def __init__(self):
     self.behaviors = []
     self.active_behaviors = []
     self.sensobs = []
     self.motob = Motob()
     self.arbitrator = Arbitrator(self)
     self.picture_taken = False
Exemplo n.º 8
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
Exemplo n.º 9
0
    def __init__(self,
                 behaviors=None,
                 active_behaviors=None,
                 sensobs=None,
                 motobs=Motob(),
                 arbitrator=Arbitrator()):
        # Make arguments non-mutable (because PyCharm says so)

        if sensobs is None:
            sensobs = []
        if active_behaviors is None:
            active_behaviors = []
        if behaviors is None:
            behaviors = []

        # Checks if bbcon pointer is initialized
        if arbitrator.bbcon is None:
            arbitrator.bbcon = self

        # Save arguments
        self.behaviors = behaviors
        self.active_behaviors = active_behaviors
        self.sensobs = sensobs
        self.motobs = motobs

        self.arbitrator = arbitrator

        # Save halt flag
        self.halt_request = False
Exemplo n.º 10
0
 def __init__(self):
     self.behaviors = []                     #Liste over alle behaviors, aktive og inaktive
     self.active_behaviors = []              # Kun aktive behaviors
     self.sensobs = []                       # Liste over sensorer
     self.motobs = Motob(self)               # Liste med motorobjekter
     self.arbitrator = Arbitrator()          # Arbitrator-objektet, velger winning behavior
     self.num_timesteps = 0                  # Hvor mange timesteps som er kjort
     self.can_take_photo = False
Exemplo n.º 11
0
 def __init__(self):
     """Initializes BBCON variables"""
     self.behaviors = []
     self.active_behaviors = []
     self.sensobs = []
     self.motobs = [Motob()]
     self.arbitrator = Arbitrator(self)
     self.new_picture = False
Exemplo n.º 12
0
 def __init__(self):
     cam = CamUltra()
     ref = ReflectanceSob()
     self.sensobs = [cam, ref]
     self.active_behaviours = [AttackRed(cam), BeScared(cam), StayInMap(ref), Wander()]
     self.motobs = [Motob(self)]
     self.arbitrator = Arbitrator(self)
     #self.active_behaviours = []
     self.inactive_behaviours = []
Exemplo n.º 13
0
 def __init__(self):
     self.running = True
     self.behaviours = []
     self.active_behaviours = []
     self.inactive_behaviours = []
     self.sensobs = []
     self.motob = Motob()
     self.arbitrator = Arbitrator(self)
     self.setup()
Exemplo n.º 14
0
    def __init__(self):
        self.__behaviors = []  # List of all behaviors
        self.active_behaviors = []  # List of all _active_ behaviors
        self.__sensobs = []  # List of all sensory objects
        self.motob = Motob()  # List of all motor objects
        self.__arbitrator = Arbitrator(
            self)  # Arbitrator chooses the next behavior

        self.timesteps = 0
        self.notifications = []
Exemplo n.º 15
0
 def __init__(self):
     self.behaviors = [
     ]  # behavior-listen, med både inaktive og aktive behaviors
     self.active_behaviors = []  # liste med aktive behaviors
     self.sensobs = []  # liste med sensor-objekter
     self.motobs = Motob(self)  # list med motor-objekter
     self.arbitrator = Arbitrator(
     )  # arbitrator-objektet, velger winning-behavior
     self.num_timesteps = 0  # antall timesteps som er kjørt
     self.can_take_photo = False
Exemplo n.º 16
0
    def __init__(self):
        self.ARB = ARB(self)
        self.recommendations = []
        self.motob = Motob()

        self.behaviors = set()  # all behaviors
        self.active = set()  # active behaviors
        self.inactive = set()  # inactive behaviors

        self.sensobs = set()
        self.motobs = [self.motob]  # motor object(s)
Exemplo n.º 17
0
 def __init__(self):
     self.behaviors = [
     ]  #En liste av alle behavior objektene som brukes av BBCON
     self.active_behaviors = []  #En liste med de aktive behavior objektene
     self.sensobs = [
     ]  #En liste av alle sensorobjektene som brukes av BBCON
     self.motobs = Motob(
     )  #En liste ac alle motor objektene som brukes av BBCON
     self.arbitrator = Arbitrator(
         self, False)  #Arbitratoren som skal løse requests fra behaviors
     self.take_pic = False
Exemplo n.º 18
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: ")
Exemplo n.º 19
0
 def __init__(self):
     self.arbitrator = Arbitrator(self)
     #Oppretter fire sensob objekter. Kamera, ir, reflectance og ultra.
     cam = Sensob()
     cam.add_sensor(Camera())
     ir = Sensob()
     ir.add_sensor(IRProximitySensor())
     reflect = Sensob()
     reflect.add_sensor(ReflectanceSensors())
     ultra = Sensob()
     ultra.add_sensor(Ultrasonic())
     self.sensob = [cam,ir,reflect,ultra]
     self.motobs = [Motob()]
     self.behaviors = []
     self.wall_detected = False
     self.wall_checked = False
Exemplo n.º 20
0
def rett_fram():
    ir = ReflectanceSensors(True)
    s = Sensob(ir)
    ab = Avoid_borders(s, s)
    wr = Walk_randomly(s, s)
    a = Arbitrator()
    m = Motob()
    print("Motob set")
    ZumoButton().wait_for_press()
    print("Button pressed")
    while True:
        ab.update()
        wr.update()
        print("Vekt: ", ab.weight)
        print("Rec: ", ab.motor_recommendations)
        winner_rec = a.choose_action(ab, wr)
        print("recom: ", winner_rec)
        m.update(winner_rec)
Exemplo n.º 21
0
    def __init__(self):
        """ init """
        self.sensobs = []
        self.add_sensob(Sensob(Ultrasonic()))
        self.add_sensob(Sensob(ReflectanceSensors()))
        self.add_sensob(Sensob(Camera()))

        self.motob = Motob()

        self.behaviors = []
        self.add_behavior(Behavior(self, [10000, 10000, [10000, 10000, 10000]], "drive", 1))
        self.add_behavior(Behavior(self, [30, 10000, [10000, 10000, 10000]], "stop", 3))
        self.add_behavior(Behavior(self, [10000, 0.3, [10000, 10000, 10000]], "turnaround", 2))
        self.add_behavior(Behavior(self, [10000, 10000, [210, 10000, 10000]], "turn_left", 5))
        #self.add_behavior(Behavior(self, [10000, 10000, [10000, 200, 10000]], "turn_right", 4))
        self.active_behaviors = []

        self.arbitrator = Arbitrator()
Exemplo n.º 22
0
def main():
    #pdb.set_trace()
    ZumoButton().wait_for_press()
    bbcon = BBCON()

    # Sensors:
    reflectance_sensor = ReflectanceSensors()
    ultrasonic_sensor = Ultrasonic()
    camera_sensor = Camera()

    # Sensobs
    reflectance_sensob = Sensob(reflectance_sensor)
    ultrasonic_sensob = Sensob(ultrasonic_sensor)
    camera_sensob = Sensob(camera_sensor)

    trackline_sensobs = reflectance_sensob
    distance_adjust_sensobs = ultrasonic_sensob

    follow_red_sensobs = camera_sensob

    # Add to bbcon:

    # Add sensobs
    bbcon.add_sensob(trackline_sensobs)
    bbcon.add_sensob(distance_adjust_sensobs)
    bbcon.add_sensob(follow_red_sensobs)

    # Add motobs:
    bbcon.motobs = Motob()

    # Add behaviors
    bbcon.add_behavior(TrackLine(bbcon, trackline_sensobs))
    bbcon.add_behavior(DistanceAdjust(bbcon, distance_adjust_sensobs))
    bbcon.add_behavior(FollowRed(bbcon, follow_red_sensobs))

    # Set all behaviors to active at start; disable if not needed
    for behavior in bbcon.behaviors:
        bbcon.activate_behavior(behavior)

    # Run as long as robot is not halted
    # not bbcon.halt_request
    #pdb.set_trace()
    while True:
        bbcon.run_one_timestep()
Exemplo n.º 23
0
def test4():
    sensor = ReflectanceSensors()
    ZumoButton().wait_for_press()
    m = Motors()
    motob = Motob(m)

    sensob = Sensob()
    sensob.set_sensors([sensor])
    print(sensor.get_value())
    behavior = FollowLine(1, [sensob])
    #print("Behavior sensob:", behavior.sensobs)
    count = 0
    while True:
        sensob.update()
        behavior.update()
        print("MR:", behavior.motor_recommendations)
        motob.update(behavior.motor_recommendations[0])
        count += 1
        #time.sleep(3)
        if count == 15:
            break
Exemplo n.º 24
0
def test5():

    ZumoButton().wait_for_press()
    m = Motors()
    motob = Motob(m)
    sensor = Ultrasonic()

    sensob = Sensob()
    sensob.set_sensors([sensor])

    behavior = CollisionAvoidance(1, [sensob])
    print("Behavior sensob:", behavior.sensobs)
    count = 0
    while True:
        sensob.update()
        behavior.update()
        #print("MR:", behavior.get_sensob_data())
        motob.update(behavior.motor_recommendations[0])
        count +=1
        if count==12:
            break
Exemplo n.º 25
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)
Exemplo n.º 26
0
def main():
    wp.wiringPiSetupGpio()

    motors = Motors()
    motors.stop()
    motob = Motob(motors)

    sensors = {
        #'ultrasonic': Ultrasonic(0.05),
        #'IR': IRProximitySensor(),
        #'reflectance': ReflectanceSensors(False, 0, 900),
        #'camera': Camera(),
    }

    # Initialize sensobs

    sensobs = {
        #'distance': DistanceSensob([sensors['ultrasonic']]),
        #'line_pos': LinePosSensob([sensors['reflectance']]),
        #'proximity': ProximitySensob([sensors['IR']]),
        #'red_search': RedSearchSensob([sensors['camera']]),
    }

    commands = [(Command.F, 0.5), (Command.R, 0.5), (Command.F, 1)]
    i=0
    while True:
        for sensor in sensors.values():
            sensor.update()

        for sensob in sensobs.values():
            sensob.update()

        motob.update(commands[i%len(commands)])

        time.sleep(1)
        i+=1
Exemplo n.º 27
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()
Exemplo n.º 28
0
def test2():
    ZumoButton().wait_for_press()
    motob = Motob(Motors())
    deg = input("Skriv antall grader: ")
    dir = input("Skriv retning L/R: ")
    motob.update((dir, int(deg)))
Exemplo n.º 29
0
def test():
    ZumoButton().wait_for_press()
    motobs = Motob()
    motobs.update(['S'])
    sleep(1)
    motobs.update(['F'])
Exemplo n.º 30
0
Arquivo: run.py Projeto: Skattum/robot
        "left_line_tresh": .7,
        "right_line_tresh": .7,
        "stop_line_tresh": .7,
        "blue_tresh": .5,
        "distance_tresh": 15
    }

    autorun = True  # True: kjører roboten uten å vente på knappetrykk

    if autorun:
        wp.wiringPiSetupGpio()
    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"])