Incorrect data when donwloading logging data

Hello Laura,
I want to log gyroscope and accelerometer from multiple MMC at 800Hz at maximum resolution (16g, 2000rad/s). But when I download the data, the data is obviously wrong. Because the accelerometer does not measure ~1g but another value (often only 0.3g on the z-axis and 0 on all other axis, if it is on a tabel). It is also very often the case that both sensors deliver the same data or every second measuring point is the same. When downloading with the mobile phone app, it works without any problems. This is the code for downloading:

def download_data(device, loggers, logger):

    if not device.is_connected:
        s_connect(device, logger)

    logger.info(f'{device.address} | Downloading data')
    t_acc = []
    data_acc = []
    t_gyro = []
    data_gyro = []
    e = Event()

    def progress_update_handler(context, entries_left, total_entries):
        if (entries_left == 0):
            e.set()

    def data_logger_acc(p):
        t_acc.append(p.contents.epoch)
        data_acc.append(parse_value(p))

    def data_logger_gyro(p):
        t_gyro.append(p.contents.epoch)
        data_gyro.append(parse_value(p))

    callback_acc = FnVoid_VoidP_DataP(lambda ctx, p: data_logger_acc(p))
    callback_gyro = FnVoid_VoidP_DataP(lambda ctx, p: data_logger_gyro(p))

    fn_wrapper = FnVoid_VoidP_UInt_UInt(progress_update_handler)
    download_handler = LogDownloadHandler(context = None,
                    received_progress_update = fn_wrapper,
                    received_unknown_entry = cast(None, FnVoid_VoidP_UByte_Long_UByteP_UByte),
                    received_unhandled_entry = cast(None, FnVoid_VoidP_DataP))
    try:
        time_start = time.perf_counter()
        libmetawear.mbl_mw_logger_subscribe(loggers[0], None, callback_acc)
        libmetawear.mbl_mw_logger_subscribe(loggers[1], None, callback_gyro)
        libmetawear.mbl_mw_logging_download(device.board, 0,
                                            byref(download_handler))
        e.wait()

    except ArgumentError as err:
        logger.error(f'{device.address} | ArgumentError: {err}')
        debug_reset(device, logger)
        return (None, None, None, None)

    download_time = round(time.perf_counter() - time_start, 5)
    logger.info(f'{device.address} | Downloaded data : {download_time}s')
    debug_reset(device, logger)
    e.clear()
 return (t_acc, data_acc, t_gyro, data_gyro)

Comments

  • What does your setup code look like? Did you setup the 800Hz and correct G range?

  • This is the code for the setup of the logger. I have also added the code to start and stop.

    gyro_rate = GyroBoschOdr._800Hz
    gyro_range = GyroBoschRange._2000dps
    acc_rate = AccBmi160Odr._800Hz
    acc_range = AccBoschRange._16G
    
    
    def setup_logging(device):
        signal_acc = libmetawear.mbl_mw_acc_get_acceleration_data_signal(device.board)
        logger_acc = create_voidp(lambda fn: libmetawear.mbl_mw_datasignal_log(signal_acc, None, fn),
                              resource='acc_logger')
        libmetawear.mbl_mw_acc_bmi160_set_odr(device.board, acc_rate)
        libmetawear.mbl_mw_acc_set_range(device.board, acc_range)
        libmetawear.mbl_mw_acc_bosch_write_acceleration_config(device.board)
    
        signal_gyro = libmetawear.mbl_mw_gyro_bmi160_get_rotation_data_signal(device.board)
        logger_gyro = create_voidp(lambda fn: libmetawear.mbl_mw_datasignal_log(signal_gyro, None, fn),
                                   resource='gyro_logger')
        libmetawear.mbl_mw_gyro_bmi160_set_odr(device.board, gyro_rate)
        libmetawear.mbl_mw_gyro_bmi160_set_range(device.board, gyro_range)
        libmetawear.mbl_mw_gyro_bmi160_write_config(device.board)
    
        logger_all = (logger_acc, logger_gyro)
        return logger_all
    
    
    def start_logging(device):
        libmetawear.mbl_mw_logging_start(device.board, 0)
        libmetawear.mbl_mw_acc_enable_acceleration_sampling(device.board)
        libmetawear.mbl_mw_gyro_bmi160_enable_rotation_sampling(device.board)
        libmetawear.mbl_mw_acc_start(device.board)
        libmetawear.mbl_mw_gyro_bmi160_start(device.board)
    
    
    def stop_logging(device):
        libmetawear.mbl_mw_acc_stop(device.board)
        libmetawear.mbl_mw_acc_disable_acceleration_sampling(device.board)
        libmetawear.mbl_mw_gyro_bmi160_stop(device.board)
        libmetawear.mbl_mw_gyro_bmi160_disable_rotation_sampling(device.board)
        libmetawear.mbl_mw_logging_stop(device.board)
    
  • edited January 2022

    I am sure I have found the error. The data is still correct in the download hander but as soon as it is finished the data is corrupted. I don't know why, but here is the code:

    def download_data(device: MetaWear, loggers: list, logger: logging.Logger):
        logger.info(f'{device.address} | Downloading data')
        t_acc = []
        data_acc = []
        t_gyro = []
        data_gyro = []
        e = Event()
    
        def progress_update_handler(context, entries_left, total_entries):
            if (entries_left == 0):
                e.set()
    
        def data_logger_acc(p):
            t_acc.append(p.contents.epoch)
            data_acc.append(parse_value(p))
            #Here the data is still correct
            #print(f'acc={data_acc[-1]}', flush=True)
    
        def data_logger_gyro(p):
            t_gyro.append(p.contents.epoch)
            data_gyro.append(parse_value(p))
            #Here the data is still correct
            #print(f'gyr={data_gyro[-1]}', flush=True)
    
        callback_acc = FnVoid_VoidP_DataP(lambda ctx, p: data_logger_acc(p))
        callback_gyro = FnVoid_VoidP_DataP(lambda ctx, p: data_logger_gyro(p))
    
        fn_wrapper = FnVoid_VoidP_UInt_UInt(progress_update_handler)
        download_handler = LogDownloadHandler(context = None,
                        received_progress_update = fn_wrapper,
                        received_unknown_entry = cast(None, FnVoid_VoidP_UByte_Long_UByteP_UByte),
                        received_unhandled_entry = cast(None, FnVoid_VoidP_DataP))
    
        try:
            time_start = time.perf_counter()
            libmetawear.mbl_mw_logger_subscribe(loggers[0], None, callback_acc)
            libmetawear.mbl_mw_logger_subscribe(loggers[1], None, callback_gyro)
            libmetawear.mbl_mw_logging_download(device.board, 0,
                                                byref(download_handler))
            e.wait()
    
        except ArgumentError as err:
            logger.error(f'{device.address} | ArgumentError: {err}')
            reset(device, logger)
            return (None, None, None, None)
    
        download_time = round(time.perf_counter() - time_start, 5)
        logger.info(f'{device.address} | Downloaded data : {download_time}s')
        reset(device, logger)
        e.clear()
        #At this point the data is already wrong
        #print(f'acc={data_acc}', flush=True)
        #print(f'gyro={data_gyro}', flush=True)
        return (t_acc, data_acc, t_gyro, data_gyro)
    
Sign In or Register to comment.