get acc gyr and mag values at the same time

Hi,

I have a simple code snippet to get all raw datas from acc, gyr and mag. It's pretty simple:

class State:
    # init state
    def __init__(self, device):
        self.device = device
        self.samples = 0
        self.accCallback = FnVoid_VoidP_DataP(self.acc_data_handler)
        self.gyroCallback = FnVoid_VoidP_DataP(self.gyro_data_handler)
        self.magCallback = FnVoid_VoidP_DataP(self.mag_data_handler)


    # acc callback function
    def acc_data_handler(self, ctx, data):
        print("ACC: %s -> %s" % (self.device.address, parse_value(data)))

        self.samples+= 1

    # gyro callback function
    def gyro_data_handler(self, ctx, data):
        print("GYRO: %s -> %s" % (self.device.address, parse_value(data)))
        self.samples+= 1

    # mag callback
    def mag_data_handler(self, ctx, data):
        print("MAG: %s -> %s" % (self.device.address, parse_value(data)))
        self.samples += 1

# init
states = []
# connect to all mac addresses in arg

d = MetaWear(mac1)
d.connect()

states.append(State(d))

# configure all metawears
for s in states:
    print("Configuring device")
    libmetawear.mbl_mw_settings_set_connection_parameters(s.device.board, 7.5, 7.5, 0, 6000)

    sleep(1.5)

    # config acc
    #libmetawear.mbl_mw_acc_set_odr(s.device.board, 50.0) # Generic call
    libmetawear.mbl_mw_acc_bmi160_set_odr(s.device.board, AccBmi160Odr._50Hz) # BMI 160 specific call
    libmetawear.mbl_mw_acc_bosch_set_range(s.device.board, AccBoschRange._4G)
    libmetawear.mbl_mw_acc_write_acceleration_config(s.device.board)

    # config gyro
    libmetawear.mbl_mw_gyro_bmi160_set_range(s.device.board, GyroBoschRange._1000dps);
    libmetawear.mbl_mw_gyro_bmi160_set_odr(s.device.board, GyroBoschOdr._50Hz);
    libmetawear.mbl_mw_gyro_bmi160_write_config(s.device.board);
    #print(s.accData)


    # setup mag
    libmetawear.mbl_mw_mag_bmm150_stop(s.device.board)
    libmetawear.mbl_mw_mag_bmm150_set_preset(s.device.board, MagBmm150Preset.REGULAR)

    # get mag and subscribe
    mag = libmetawear.mbl_mw_mag_bmm150_get_b_field_data_signal(s.device.board)
    libmetawear.mbl_mw_datasignal_subscribe(mag, None, s.magCallback)

    # start mag
    libmetawear.mbl_mw_mag_bmm150_enable_b_field_sampling(s.device.board)
    libmetawear.mbl_mw_mag_bmm150_start(s.device.board)

    # get acc signal and subscribe
    acc = libmetawear.mbl_mw_acc_get_acceleration_data_signal(s.device.board)
    libmetawear.mbl_mw_datasignal_subscribe(acc, None, s.accCallback)

    # get gyro signal and subscribe
    gyro = libmetawear.mbl_mw_gyro_bmi160_get_rotation_data_signal(s.device.board)
    libmetawear.mbl_mw_datasignal_subscribe(gyro, None, s.gyroCallback)

    # start acc
    libmetawear.mbl_mw_acc_enable_acceleration_sampling(s.device.board)
    libmetawear.mbl_mw_acc_start(s.device.board)

    # start gyro
    libmetawear.mbl_mw_gyro_bmi160_enable_rotation_sampling(s.device.board)
    libmetawear.mbl_mw_gyro_bmi160_start(s.device.board)

The output of this code with a metamotionRL is:

GYRO: E6:4E:5A:BF:56:D7 -> {x : 0.244, y : -0.213, z : 0.793}
ACC: E6:4E:5A:BF:56:D7 -> {x : -0.629, y : 0.444, z : -0.644}
GYRO: E6:4E:5A:BF:56:D7 -> {x : -0.640, y : -0.945, z : -0.183}
ACC: E6:4E:5A:BF:56:D7 -> {x : -0.629, y : 0.438, z : -0.649}
GYRO: E6:4E:5A:BF:56:D7 -> {x : -1.921, y : -1.768, z : -0.030}
ACC: E6:4E:5A:BF:56:D7 -> {x : -0.631, y : 0.445, z : -0.643}
GYRO: E6:4E:5A:BF:56:D7 -> {x : 0.183, y : -0.640, z : 0.732}
MAG: E6:4E:5A:BF:56:D7 -> {x : -6.750, y : -45.000, z : 138.312}
ACC: E6:4E:5A:BF:56:D7 -> {x : -0.630, y : 0.445, z : -0.636}
GYRO: E6:4E:5A:BF:56:D7 -> {x : 0.183, y : -0.122, z : 1.006}
ACC: E6:4E:5A:BF:56:D7 -> {x : -0.633, y : 0.446, z : -0.645}
GYRO: E6:4E:5A:BF:56:D7 -> {x : -0.061, y : -0.854, z : 1.341}
ACC: E6:4E:5A:BF:56:D7 -> {x : -0.634, y : 0.452, z : -0.654}
GYRO: E6:4E:5A:BF:56:D7 -> {x : -0.122, y : 0.000, z : 1.189}
ACC: E6:4E:5A:BF:56:D7 -> {x : -0.627, y : 0.448, z : -0.643}

But my question is that I have to get one line with Gyr, ACC, Data at the same time more or less like this:

ACCX ACCY ACCZ GYRX GYRY GYRZ MAGX MAGY MAGZ
-0.629 0.444 -0.644 0.244 -0.213 0.793 -6.750, -45.000 138.312

But in the print output I obtain not order data raw from gyr, acc, mag.

is there a way to get raw data in the same line, maybe suscribing to the same callbak?

Thanks a lot

Sign In or Register to comment.