Example #1
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 #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 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)
Example #4
0
def main():
    # initialisering
    ZumoButton().wait_for_press()
    bbcon = BBCON()
    us = Ultrasonic()

    ir_sensob = Sensob(
        ReflectanceSensors(True))  # True betyr med auto-kalibrering
    usonic_sensob = Sensob(us)
    camera_sensob = Sensob(sensor=Camera(), sensor2=us)

    avoid_borders = Avoid_borders(ir_sensob, bbcon)
    walk_randomly = Walk_randomly(None, bbcon)
    clean = Clean(usonic_sensob, bbcon)
    approach = Approach(usonic_sensob, bbcon)
    take_photo = Take_photo(camera_sensob, bbcon)

    # setup
    bbcon.add_sensob(ir_sensob)  # legger til IR sensob
    bbcon.add_sensob(usonic_sensob)  # legger til Ultrasonic sensob
    #bbcon.add_sensob(camera_sensob)    # legger til Ultrasonic/camera sensob

    bbcon.add_behavior(avoid_borders)  # legger til avoid_borders
    bbcon.add_behavior(walk_randomly)  # legger til walk_randomly
    #bbcon.add_behavior(clean)          # legger til clean
    bbcon.add_behavior(approach)  # legger til approach
    bbcon.add_behavior(take_photo)  # legger til take_photo

    bbcon.activate_behavior(avoid_borders)
    bbcon.activate_behavior(walk_randomly)
    bbcon.activate_behavior(approach)
    #bbcon.activate_behavior(take_photo)

    while True:
        bbcon.run_one_timestep()
Example #5
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 #6
0
def init_bbcon(bbcon):
    reflectance_sensob = Sensob(ReflectanceSensors())
    camera_sensob = Sensob(Camera())
    ultrasonic = Sensob(Ultrasonic())

    bbcon.add_sensob(reflectance_sensob)
    bbcon.add_sensob(camera_sensob)
    bbcon.add_sensob(ultrasonic)

    take_picture = TakePicture(bbcon)
    collision_avoidance = CollisionAvoidance(bbcon)
    image_behavior = ImageBehavior(bbcon)

    bbcon.add_behavior(take_picture)
    bbcon.add_behavior(collision_avoidance)
    bbcon.add_behavior(image_behavior)
Example #7
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()
Example #8
0
def take_photo():
    c = Camera()
    s = Sensob(c)
    tf = Take_photo(s, s)
    print(tf.active_flag)
    tf.set_active()
    print(tf.active_flag)
    tf.update()
    print(tf.active_flag)
Example #9
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()
Example #10
0
def reflectTest():

    #motor = Motors()
    #motob = Motob(motor=motor)

    reflect = ReflectanceSensors()
    sensob = Sensob()
    sensob.set_sensors([reflect])
    ZumoButton().wait_for_press()
    count = 0
    while count < 10:
        sensob.update()
        print(sensob.get_values())
        count += 1
        time.sleep(2.5)
Example #11
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)
Example #12
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
Example #13
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
Example #14
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
Example #15
0
 def __init__(self):
     self.bilde = None
     self.value = [0,0,0,0,0]                    #Makes the list with red pixels
     Sensob.__init__(self,[Camera()])            #Super-constructor with the camera-sensor.
Example #16
0
 def reset(self):
     Sensob.reset(self)
     self.value = [0,0,0,0,0]
 def __init__(self):
     Sensob.__init__(self, [Ultrasonic()])
Example #18
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)