Example #1
0
 def luxmeter(self):
     analogRead = None
     while analogRead is None:
         try:
             analogRead = self.hal.sensors.lux.value
         except TypeError:
             pass
     resistance = converters.tension2resistance(analogRead, 10000)
     lux = converters.resistance2lux(resistance, **LUXMETER)
     return lux
Example #2
0
async def pid(hal, pid=None, times=float('inf')):
    #f = open('testfile.txt','w')
    Ku = 0.015
    Tu = 0.00001

    Kp = 0.6*Ku
    Ki = (2*Ku)/Tu
    Kd = (Kp*Tu)/8

    if not pid: pid = PID(800, Kp, Ki , Kd, min=0, max=255)
    #pid = PID(800, Ku*0.6, 0 , 0, min=0, max=255)

    hal.animations.led.upload([0])
    hal.animations.led.loopin2 = True
    hal.animations.led.playing = True

    i = 0
    while times:
        mean = 0
        for _ in range(3):
            analogRead = None
            while analogRead is None:
                try:
                    analogRead = hal.sensors.lux.value
                except TypeError:
                    pass
            resistance = converters.tension2resistance(analogRead, 10000)
            lux = converters.resistance2lux(resistance, **LUXMETER)
            mean += lux
            await asyncio.sleep(0.02)
        lux = round(mean / 3, 2)

        res = int(pid.compute(lux))
        logger.info("Obs=%s, PID asks %s", lux, res)

        #toWrite = str(i) + " " + str(lux) + "\n"
        #f.write(toWrite)

        hal.animations.led.upload([res])

        await asyncio.sleep(0.5)
        i += 1

        times -= 1
    print("end loop")
Example #3
0
def luxmeter(analogRead):
    resistance = converters.tension2resistance(analogRead, 10000)
    #print("res:", resistance)
    lux = converters.resistance2lux(resistance, **LUXMETER)
    return lux