Example #1
0
class AvoidEdge(Behavior):
    def __init__(self, BBCON, priority):
        super().__init__(BBCON)
        print("We are going in to calibration mode in 2 sec")
        time.sleep(2)
        self.sensob = ReflectanceSensors(auto_calibrate=True)
        self.priority = priority                      #Preset value that is set by the user
        self.sensob.update()
        self.old = self.sensob.get_value()

    def printName(self):
        return "Behavior AvoidEdge  "

    def update(self):
            super().considerState()
            if self.active_flag:
                self.sense_and_act()
                self.weight = self.priority * self.match_degree

    def sense_and_act(self):
        self.sensob.update()
        self.new = self.sensob.get_value()
        print(sum(self.old)/len(self.old) - sum(self.new)/len(self.new) > 0.1)
        if (sum(self.old)/len(self.old) - sum(self.new)/len(self.new) > 0.1 ):
            self.motor_recommendations = [-1,-1]
            self.match_degree = 1
        else:
            self.match_degree = 0
            self.motor_recommendations = [1,1]

        self.old = self.new

    def test(self):
        return True
Example #2
0
class ReflectanceSob:
    def __init__(self):
        self.sensor = ReflectanceSensors(auto_calibrate=False)
        self.max_val = self.sensor.max_val


    def update(self):
        print('reflectance sensor updates')
        self.sensor.update()
        self.value = self.sensor.value
    def reset(self):
        self.sensor.reset()
Example #3
0
class ReflectanceSob:
    def __init__(self):
        self.sensor = ReflectanceSensors(auto_calibrate=False)
        self.max_val = self.sensor.max_val

    def update(self):
        print('reflectance sensor updates')
        self.sensor.update()
        self.value = self.sensor.value

    def reset(self):
        self.sensor.reset()
Example #4
0
class ReflectanceSensob(Sensob):
    def __init__(self):
        super(ReflectanceSensob, self).__init__()
        self.sensor = ReflectanceSensors()
        self.sensors.append(self.sensor)

    def get_value(self):
        ''' returnerer en liste med verdier: [left, midleft, midright right]'''
        return self.value

    def update(self):
        self.sensor.update()
        self.value = self.sensor.get_value()
        return self.value
Example #5
0
def edge_detection():
    ir = ReflectanceSensors(max_reading=3000, min_reading=1000)
    button = ZumoButton()
    while True:
        button.wait_for_press()
        reading = ir.update()
        print(reading)
        time.sleep(0.6)
Example #6
0
def tourist(steps=25,shots=5,speed=.25):
    ZumoButton().wait_for_press()
    rs = ReflectanceSensors(); m = Motors(); c = Camera()
    for i in range(steps):
        random_step(m,speed=speed,duration=0.5)
        vals = rs.update()
        if sum(vals) < 1:  # very dark area
            im = shoot_panorama(c,m,shots)
            im.dump_image('vacation_pic'+str(i)+'.jpeg')
Example #7
0
def tourist(steps=25,shots=5,speed=.25):
    ZumoButton().wait_for_press()
    rs = ReflectanceSensors(); m = Motors(); c = Camera()
    for i in range(steps):
        random_step(m,speed=speed,duration=0.5)
        vals = rs.update()
        if sum(vals) < 1:  # very dark area
            im = shoot_panorama(c,m,shots)
            im.dump_image('vacation_pic'+str(i)+'.jpeg')
Example #8
0
class FollowLine:

    def __init__(self):
        self.reflectanseSensor = ReflectanceSensors()
        self.values = self.getValueList()
        self. values = self.isOnLine()

    def getValueList(self):
        self.reflectanseSensor.reset()
        self.reflectanseSensor.update()
        return self.reflectanseSensor.get_value()

    def isOnLine(self):
        nowValue = self.getValueList()
        offLineList = [0,1,4,5]
        for i in range(6):
            if i in offLineList and nowValue[i] < 0.2:
                return [(1000-(nowValue[i]*1000)),i]
        return [0,10]

    def getPriValues(self):
        return self.isOnLine()
Example #9
0
class FallingOut(Sensob):
    def __init__(self):
        super(FallingOut, self).__init__()
        self.sensor = ReflectanceSensors(max_reading=3000, min_reading=1000)
        self.value = []

    def update(self):
        self.sensor.update()
        self.value = self.sensor.get_value()

    def reset(self):
        pass

    def calibrate(self):
        self.sensor = ReflectanceSensors(auto_calibrate=True)

    def interpret(self):
        danger = 0
        if self.value[0] < 0.65:
            danger = -1
        elif self.value[5] < 0.65:
            danger = 1
        return danger
Example #10
0
class Reflectance(Sensob):
    def __init__(self):
        super().__init__("Reflectance")
        self.reflect = ReflectanceSensors()

    def get_sensor_current_value(self):
        value = self.reflect.update()
        return value

    def update(self):
        self.value = self.get_sensor_current_value()

    def get_value(self):
        return self.value
Example #11
0
def test():
    sensor = ReflectanceSensors()

    for x in range(30):
        print(sensor.update())