def __init__(
        self,
        filename,
        vflip,
        hflip,
        video_stabilization,
        video_preview,
        device,
        baudrate,
        erase,
        fps,
        height,
        width,
        lag,
    ):
        self.filename = filename  # filename factory (to create filenames)

        self.board = pingo.detect.get_board()

        led_pin = self.board.pins[13]
        self.led = Led(led_pin)

        btn_pin = self.board.pins[7]
        self.switch = Switch(btn_pin)

        self.switch.set_callback_down(self.switch_released)
        self.switch.set_callback_up(self.switch_pressed)

        self.camera_settings = Settings(
            resolution=(width, height), framerate=fps, vflip=vflip, hflip=hflip, video_stabilization=video_stabilization
        )

        self.video_preview = video_preview
        self.device = device
        self.baudrate = baudrate
        self.erase = erase

        self.lag = lag
        self.time_to_sleep = 0.01

        self.recording = False
        self.recording_task = None

        self.sensors = []

        sensors_arduino = SensorsArduino(device=self.device, baudrate=self.baudrate, adc_channels_number=2)
        logger.info("capabilities: %s" % sensors_arduino.capabilities)
        sensors_arduino.connect()
        sensors_arduino.ADC[0].calibrate(lambda value: linear_function_with_limit(value, 520.0, 603.0, 0.0, 100.0))

        self.sensors.append(sensors_arduino)
Exemple #2
0
def main(device, baudrate):
    logging.basicConfig(level=logging.INFO)
    
    sensors00 = SensorsArduino(device=device, baudrate=baudrate, adc_channels_number=2)
    print("capabilities: %s" % sensors00.capabilities)
    sensors00.connect()
    sensors00.ADC[0].calibrate(lambda value: linear_function_with_limit(value, 520.0, 603.0, 0.0, 100.0))
        
    maxlen = 100
    data_x = RingBuffer(maxlen, datetime.datetime.utcnow(), dtype=datetime.datetime)
    data_y = RingBuffer(maxlen)

    y = 100 # initial value

    fig, ax = plt.subplots()
    line, = ax.plot(data_x.all[::-1], data_y.all[::-1], linestyle='-', marker='+', color='r', markeredgecolor='b')
    #ax.set_ylim([0, 1023])
    ax.set_ylim([0, 100])

    t_last = datetime.datetime.utcnow()
    while True:
        t = datetime.datetime.utcnow()
        try:
            if sensors00.update() and sensors00.ADC[0].has_new_data:
                print(sensors00._bin_msg._data)
                y = sensors00.ADC[0].value
                #y = limit(y, 1800.0, 24000.0, 0.0, 100.0)
                logger.info("%s %s %s" % (t, y, t - t_last))
                data_x.append(t)
                data_y.append(y)
                line.set_xdata(data_x.all[::-1])
                xmin, xmax = data_x.min(), data_x.max()
                if xmax > xmin:
                    ax.set_xlim([xmin, xmax])
                    line.set_ydata(data_y.all[::-1])
                    #ymin, ymax = data_y.min(), data_y.max()
                    #if ymax > ymin:
                    #    ax.set_ylim([ymin, ymax])
                plt.pause(0.001)
        except Exception as e:
            logger.error(traceback.format_exc())
            #raise e
        t_last = t
Exemple #3
0
def main(device, baudrate):
    logging.basicConfig(level=logging.INFO)
    
    sensors00 = SensorsArduino(device=device, baudrate=baudrate, adc_channels_number=2)
    print("capabilities: %s" % sensors00.capabilities)
    sensors00.connect()
    sensors00.ADC[0].calibrate(lambda value: linear_function_with_limit(value, 520.0, 603.0, 0.0, 100.0))

    t_last = datetime.datetime.utcnow()
    while True:
        t = datetime.datetime.utcnow()
        try:
            if sensors00.update() and sensors00.ADC[0].has_new_data:
                print(sensors00._bin_msg._data)
                ai0 = sensors00.ADC[0]
                y_raw = ai0.raw
                y = ai0.value
                logger.info("%s %s %s" % (t, y, t - t_last))
        except Exception as e:
            logger.error(traceback.format_exc())
            #raise e
        t_last = t
Exemple #4
0
def main(vflip, hflip, video_stabilization, data_folder, data_filename, video_filename, video_preview, 
    device, baudrate, erase):

    logging.basicConfig(level=logging.INFO)

    s_now = datetime.datetime.utcnow().strftime("%Y%m%d-%H%M%S-%f")
    
    data_folder = os.path.expanduser(data_folder)
    
    if not erase:
        data_folder = os.path.join(data_folder, s_now)
        if not os.path.exists(data_folder):
            os.makedirs(data_folder)


    sensors00 = SensorsArduino(device=device, baudrate=baudrate, adc_channels_number=2)
    logger.info("capabilities: %s" % sensors00.capabilities)
    sensors00.connect()
    sensors00.ADC[0].calibrate(lambda value: linear_function_with_limit(value, 520.0, 603.0, 0.0, 100.0))

    
    with picamera.PiCamera() as camera:
        #turn LED on
        #led.on()

        #setup camera
        camera.resolution = (VIDEOWIDTH, VIDEOHEIGHT)
        camera.framerate = VIDEOFPS
        camera.vflip = vflip
        camera.hflip = hflip
        camera.video_stabilization = video_stabilization

        if video_preview:
            camera.start_preview()
        
        with DataBuffer(os.path.join(data_folder, data_filename)) as data:
            data.columns = ["t", "frame", "pos"]
            
            camera.start_recording(os.path.join(data_folder, video_filename)) #, inline_headers=False)
            logger.info("Recording - started pi camera")
            try:
                while(True):
                    now = datetime.datetime.utcnow()
                    
                    logger.info("data in the loop @ %s" % now)
                    
                    framenumber = camera.frame.index
                    logger.info(framenumber)
                    
                    to_append = False
                    ai0 = sensors00.ADC[0]
                    if sensors00.update() and not ai0.has_same_value: #and ai0.has_new_data: #ai0.has_same_raw_value
                        to_append = True
                    
                    if to_append:
                        data.append(now, framenumber, ai0.value) # ai0.raw or ai0.value
                    
                    time.sleep(0.01)

            except KeyboardInterrupt:
                logger.info("User Cancelled (Ctrl C)")
                camera.stop_recording()
                if video_preview:
                    camera.stop_preview()