Error now occurring in metawear__init__.py file - error not occurring initially with same code

I was using the logging capability to capture accelerometer and gyro data with two devices, and had no problems initially with both devices. See the code below:

            print("Searching for device...")
            d = MetaWear('XX:XX:XX:XX:XX:XX')
            d.connect()
            print("Connected to " + d.address)

            print("Configuring device")

            def imu():
                try:
                    # print the epoch time in milliseconds for when the device is triggered to start capturing data
                    start_epoch_meas_time = int(round(time.time() * 1000))
                    print(start_epoch_meas_time)

                    acc_signal = libmetawear.mbl_mw_acc_get_acceleration_data_signal(d.board)
                    gyro_signal = libmetawear.mbl_mw_gyro_bmi160_get_rotation_data_signal(d.board)


                    acc_logger = create_voidp(lambda fn: libmetawear.mbl_mw_datasignal_log(acc_signal, None, fn), resource = "acc_logger")
                    gyro_logger = create_voidp(lambda fn: libmetawear.mbl_mw_datasignal_log(gyro_signal, None, fn), resource = "gyro_logger")

                    libmetawear.mbl_mw_logging_start(d.board, 0)

                    libmetawear.mbl_mw_gyro_bmi160_enable_rotation_sampling(d.board)
                    libmetawear.mbl_mw_acc_enable_acceleration_sampling(d.board)

                    libmetawear.mbl_mw_gyro_bmi160_start(d.board)
                    libmetawear.mbl_mw_acc_start(d.board)


                    # the accelerometer data is captured every 8 - 11 ms
                    # after about 0.05 s the data capture begins so if sleep time is 0.3 s
                    # then the data is captured for about 0.25s and the number of data points
                    # logged for each axis is about 25

                    # capture the data for about 1 s
                    # Trigger the imu 0.2 s before ball release
                    print("Logging data for 0.3s")
                    sleep(0.3)

                    libmetawear.mbl_mw_gyro_bmi160_stop(d.board)
                    libmetawear.mbl_mw_acc_stop(d.board)

                    libmetawear.mbl_mw_gyro_bmi160_disable_rotation_sampling(d.board)        
                    libmetawear.mbl_mw_acc_disable_acceleration_sampling(d.board)

                    libmetawear.mbl_mw_logging_stop(d.board)

                    print("Downloading data")
                    libmetawear.mbl_mw_settings_set_connection_parameters(d.board, 7.5, 7.5, 0, 6000)
                    # sleep(1.0)

                    e = Event()

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

                    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))

                    acc_values = []
                    gyro_values = []

                    acc_callback = FnVoid_VoidP_DataP(lambda ctx, ap: acc_values.append([ap.contents.epoch, parse_value(ap).x, parse_value(ap).y,parse_value(ap).z]))
                    gyro_callback = FnVoid_VoidP_DataP(lambda ctx, gp: gyro_values.append([gp.contents.epoch, parse_value(gp).x, parse_value(gp).y,parse_value(gp).z]))


                    libmetawear.mbl_mw_logger_subscribe(acc_logger, None, acc_callback)
                    libmetawear.mbl_mw_logger_subscribe(gyro_logger, None, gyro_callback)

                    libmetawear.mbl_mw_logging_download(d.board, 0, byref(download_handler))
                    e.wait()

                    print(acc_values)
                    print(gyro_values)

                    # seven or eight gyro measurements are performed before the accelerometer starts to measure values
                    # the time between measurements is anywhere from 8 to 11 ms
                    # the accelerometer is lagging the gyro by about 70 to 80 milliseconds
                    print(acc_values[0][0])
                    print(gyro_values[8][0])

                    # this is the amount of time it takes before both the accelerometer and gyro are both reading values 
                    # this time is in milliseconds and is around 0.2 s
                    # Therefore, trigger the imu at least 0.2 s before the first measurement is needed
                    print(gyro_values[8][0] - start_epoch_meas_time)

                except RuntimeError as err:
                    print(err)
                finally:
                    print("Resetting device")

                    e = Event()
                    d.on_disconnect = lambda status: e.set()
                    libmetawear.mbl_mw_debug_reset(d.board)
                    e.wait()

            imu()

However, now when running the following code for with either device, I get the following error:

Traceback (most recent call last):
File "_ctypes/callbacks.c", line 315, in 'calling callback function'
File "E:\Program Files\WorldViz\Vizard6\bin\lib\site-packages\mbientlab\metawear__init__.py", line 74, in handler
result[0] = RuntimeError("Could not create " + (resource if 'resource' in kwarg else "resource") ) if pointer == None else pointer
NameError: global name 'kwarg' is not defined

Why is this error now appearing for both devices and preventing me from logging the data?

Comments

  • Can you restart the bluetooth and reset your metawear devices? Something seems to be stuck in a bad state (you could even restart your machine for extra measure).

  • I tried running the MetaBase app and it crashed. I reinstalled the app and added the devices to reset them. Diagnostics were run and set by email for 'E6:12:88:19:7C:9F' and 'CA:61:16:C4:11:A5'

    Tried running the python code again and I get now the following error.

    Searching for device...
    Traceback (most recent call last):
    File "", line 11, in
    File "E:\Documents\Vizard_User_files\Vizard_6_2\MetaWear-SDK-Python-master\examples\log_acc_and_gyro_3.py", line 30, in
    d.connect()
    File "E:\Program Files\WorldViz\Vizard6\bin\lib\site-packages\mbientlab\metawear\metawear.py", line 195, in connect
    raise result[0]
    mbientlab.warble.WarbleException: Failed to discover gatt characteristics

  • Scan for the device before connecting to it

Sign In or Register to comment.