def __init__(self, sensors=None, kwargs_parser=get_datalogger_config):
        """
            sensors : list of sensor objects to be initialized. (Not instances!)
            odr : total ODR of all sensor (ODR is needed here to determine board power saving mode)
            args : global parameters
        """

        # override .cfg parameters in application if needed
        self.override_config_parameters()

        # override .cfg paramters with command line arguments
        if kwargs_parser:
            kwargs_parser()

        self.sensors = []
        self.sensor = None

        # ODR is needed here to determine board power saving mode
        self.connection_manager = ConnectionManager(
            odr=evkit_config.odr)
        self.stream = None

        # add sensors if sensor list given
        if sensors:
            for sensor in sensors:
                self.add_sensor(sensor())

            # reset the sensor so no any old settings are in place
            for sensor in self.sensors:
                sensor.por()
Example #2
0
def test_online():
    import imports  # pylint: disable=unused-import
    from kx_lib.kx_board import ConnectionManager
    from kx_lib.kx_util import evkit_config
    from kmx62 import kmx62_data_logger
    from kmx62.kmx62_driver import KMX62Driver

    class CallBack(object):
        def __init__(self):
            self.prediction = Algorithm_prediction()

        def callback(self, data):
            ch, ax, ay, az, mx, my, mz, temp = data
            self.prediction.feed(ax)

            #print("\nThe vacuum cleaner is on the {}".format(self.prediction.result))

    ODR = 50
    callback_object = CallBack()

    connection_manager = ConnectionManager(
        board_config_json='rokix_board_rokix_sensor_node_i2c.json')
    sensor_kmx62 = KMX62Driver()
    try:
        connection_manager.add_sensor(sensor_kmx62)
        kmx62_data_logger.enable_data_logging(sensor_kmx62, odr=ODR)
        stream = kmx62_data_logger.KMX62DataStream([sensor_kmx62])
        stream.read_data_stream(console=False,
                                callback=callback_object.callback)

    finally:
        sensor_kmx62.set_power_off()
        connection_manager.disconnect()
Example #3
0
def app_main(odr=17):

    args = get_datalogger_args()
    if args.odr:
        odr = args.odr

    # For continuous more there 3 possible odr values: 17Hz, 8Hz and 4Hz
    allowed_odrs = (17, 8, 4)

    assert odr in allowed_odrs, \
        "Invalid odr, valid values {}".format(allowed_odrs)

    sensor = bm1383aglv_driver()
    connection_manager = ConnectionManager(odr=odr)

    connection_manager.add_sensor(sensor)

    enable_data_logging(sensor, odr=odr)

    if args.stream_mode:
        read_with_stream(sensor, args.loop)

    elif args.timer_stream_mode:
        read_with_stream(sensor, args.loop, timer=1. / odr)

    else:
        read_with_polling(sensor, args.loop)

    sensor.set_power_off()
    connection_manager.disconnect()
def print_version_info():
    cm = ConnectionManager()
    print('Protocol version   ' + cm.kx_adapter.fw_protocol_version)
    print('Board ID           %d' % cm.kx_adapter.board_id)
    print('Board UID          ' +
          ':'.join(['%02X' % t for t in cm.kx_adapter.get_dev_id()]))
    print('Firmware version   ' +
          ''.join(['%02x' % t for t in cm.kx_adapter.get_firmware_id()]))

    try:
        # Bootloader version only on nRF based boards
        print('Bootloader version ' +
              ''.join(['%02x' % t for t in cm.kx_adapter.get_bootloader_id()]))
    except ProtocolException:
        pass

    cm.disconnect()
Example #5
0
def test_online():
    import imports  # pylint: disable=unused-import
    from kx_lib.kx_board import ConnectionManager
    from kx_lib.kx_util import evkit_config
    from kmx62 import kmx62_data_logger
    from kmx62.kmx62_driver import KMX62Driver
    ODR = 50

    connection_manager = ConnectionManager(board_config_json='rokix_board_rokix_sensor_node_i2c.json')
    sensor_kmx62 = KMX62Driver()
    try:
        connection_manager.add_sensor(sensor_kmx62)
        kmx62_data_logger.enable_data_logging(sensor_kmx62, odr=ODR)
        stream = kmx62_data_logger.KMX62DataStream([sensor_kmx62])
        stream.read_data_stream(console=False, callback=callback)

    finally:
        sensor_kmx62.set_power_off()
        connection_manager.disconnect()
Example #6
0
def app_main(odr=25):

    args = get_datalogger_args()
    if args.odr:
        odr = args.odr
    sensor = KMX62Driver()
    connection_manager = ConnectionManager()
    connection_manager.add_sensor(sensor)
    enable_data_logging(sensor, odr=odr)

    if args.stream_mode:
        read_with_stream(sensor, args.loop)

    elif args.timer_stream_mode:
        raise EvaluationKitException('Timer polling not yet implemented')

    else:
        read_with_polling(sensor, args.loop)

    sensor.set_power_off()
    connection_manager.disconnect()
Example #7
0
def test_online():
    import imports  # pylint: disable=unused-import
    from kx_lib.kx_board import ConnectionManager
    from kx_lib.kx_util import evkit_config
    from kmx62 import kmx62_data_logger
    from kmx62.kmx62_driver import KMX62Driver

    class CallBack(object):
        def __init__(self):
            self.lateral_g = Algorithm_g_force(['ax', 'ay', 'az'])
            self.longitudinal_g = Algorithm_g_force(['ax', 'ay', 'az'])

        def callback(self, data):
            ch, ax, ay, az, mx, my, mz, temp = data
            self.lateral_g.feed((ay, ax, az))
            self.longitudinal_g.feed((ax, ay, az))
            print('%.02f\t%0.2f' %
                  (self.lateral_g.g_force, self.longitudinal_g.g_force))

    callback_object = CallBack()

    connection_manager = ConnectionManager(
        board_config_json='rokix_board_rokix_sensor_node_i2c.json')
    sensor_kmx62 = KMX62Driver()
    try:
        connection_manager.add_sensor(sensor_kmx62)
        kmx62_data_logger.enable_data_logging(sensor_kmx62,
                                              odr=global_settings.sensor.odr,
                                              max_range_acc='%dG' %
                                              global_settings.sensor.g_range)

        stream = kmx62_data_logger.KMX62DataStream([sensor_kmx62])
        stream.read_data_stream(console=False,
                                callback=callback_object.callback)

    finally:
        sensor_kmx62.set_power_off()
        connection_manager.disconnect()
Example #8
0
def app_main(odr=25):
    sp = ShapePlot()
    v1 = acc0
    p2 = [8, 0, 0]
    v2 = acc1
    p1 = [-8, 0, 0]
    points = [p1, p2]
    # for i in range(40):
    # 	print(v1)
    # 	# v1[0] = v1[0] + 500
    # 	# v1[2] = v1[2] - 500
    # 	vecs = [v1,v2]
    # 	points = [p1,p2]
    # 	sp.plot(vecs,points)
    # 	time.sleep(.1)

    args = get_datalogger_args()

    if args.odr:
        odr = args.odr

    sensor0 = KX022Driver()
    sensor1 = KX022Driver()

    connection_manager0 = ConnectionManager(odr=odr, req_port=0)
    connection_manager1 = ConnectionManager(odr=odr, req_port=1)

    connection_manager0.add_sensor(sensor0)
    connection_manager1.add_sensor(sensor1)

    enable_data_logging(sensor0, odr=odr)
    enable_data_logging(sensor1, odr=odr)

    while True:

        if args.stream_mode:
            read_with_stream(sensor, args.loop)

            print 'here11'
        elif args.timer_stream_mode:
            read_with_stream(sensor, loop=args.loop, timer=1. / odr)

            print 'here12'
        else:
            # read_with_polling(sensor, args.loop)
            read_with_polling(sensor0, 1, 0)
            read_with_polling(sensor1, 1, 1)
            print 'here13'

        v1 = acc0
        v2 = acc1
        sp.plot([v1, v2], points)
        # time.sleep(0.01)
    print 'here'

    sensor0.set_power_off()
    sensor1.set_power_off()

    connection_manager0.disconnect()
    connection_manager1.disconnect()

    print 'here1'
def main():
    sensor = KX132Driver()
    cm = ConnectionManager()
    cm.add_sensor(sensor)
    sensor.register_dump()