API References


Library for the control of a MetaMotionR device

class index:

metamotion API Documentation

Class Accelerometer

Class for represent an Accelerometer sensor that is part of a MetaMotionR device This class enable the user to request all the data that is provided by this accelerometer sensor

__init__

def __init__(self, board, freq, motion_samples, motion_threshold, tap_threshold)

Method for initialice the accelerometer sensor with the desired parameters. Also initializing the data, this method subscribe for all the accelerometer signal and active the sensor

Parameters:

active

def active(self, acc_freq, motion_samples, motion_threshold, tap_threshold)

Method to configure, active and enable all the accelerometer sensors of the device

Parameters:

get_callback

def get_callback(self, attr, handler)

Generic method to generate a callback that wil be executed when a signal from a sensor is received

Parameter:

init_measures

def init_measures(self)

Subscribe the signal of the accelerometers measures in order to update the data

on_acceleration

def on_acceleration(self, func=None)

Add a handler to process the data received by the signal. If there is no handler, the data is saved in the attribute

Parameter:

on_motion

def on_motion(self, func=None)

Subscribe to motion detector data and attach a handler that receives the motion as a parameter.

Parameter:

on_tap

def on_tap(self, func=None)

Subscribe tap data and attach a handler that receives tap as a parameter

Parameter:

read_acceleration

def read_acceleration(self)

Return the last acceleration detected by the sensor. The acceleration is formed by the following fields:

read_motion

def read_motion(self)

Return the last motion detected by the sensor. The motion is formed by the following fields:

read_step_counter

def read_step_counter(self)

Return the number of steps that the user has made

read_tap

def read_tap(self)

Return the last tap detected by the sensor. The tap is formed by the following fields:

setup_logger

def setup_logger(self)

Create and initialize an accelerometer logger

subscribe_logged_data

def subscribe_logged_data(self)

Subscribe to the accelerometer logger in order to receive the acceleration data when the download action is performed

subscribe_signal

def subscribe_signal(self, attr, signal_subscriber, func=None)

Method to subscribe a client to a signal, indicating the attribute where the data received must be saved, the method to subscribe to the signal and the user function that will process the data. If no function is indicated, the data will be saved only

Parameter:

wait_until_download_completed

def wait_until_download_completed(self)

Wait until the acceleration data is fully downloaded

Class Color

Class to save constants about color LEDS. The three constants are GREEN, RED, and BLUE

Class ConnectionError

A exception to inform that a connection with a concrete sensor failed

Class Gyroscope

Class for represent a Gyroscope of a MetaMotionR device, this class enables the user to gather the rotation data from the gyroscope sensor

__init__

def __init__(self, board, freq)

Method to initalize the gyroscope client. The initialization include the activation of the gyroscope and subscription in order to update the attributes

active

def active(self, freq)

Active and configure the gyroscope sensor with default configuration

get_callback

def get_callback(self, attr, handler)

Generic method to generate a callback that wil be executed when a signal from a sensor is received

Parameter:

init_measures

def init_measures(self)

Subcribe to rotation data in order to update the attribute saving the data

on_rotation

def on_rotation(self, func=None)

Add a handler to process the data received by the signal. If there is no handler, the data is saved in the attribute self.gyro

Parameter:

read_rotation

def read_rotation(self)

Return the last rotation detected by the sensor. The rotation is formed by the following attributes:

setup_logger

def setup_logger(self)

Create and initialize a rotation logger

subscribe_logged_data

def subscribe_logged_data(self)

Subscribe to the rotation logger in order to receive the rotation data when the download action is performed

subscribe_signal

def subscribe_signal(self, attr, signal_subscriber, func=None)

Method to subscribe a client to a signal, indicating the attribute where the data received must be saved, the method to subscribe to the signal and the user function that will process the data. If no function is indicated, the data will be saved only

Parameter:

translate_frequency

def translate_frequency(self, desired_freq)

Translate a numeric frequency in the corresponding macro

wait_until_download_completed

def wait_until_download_completed(self)

Wait until the rotation data is fully downloaded

Class MetaMotion

This class is used for request and add handlers for MetaMotionR sensor This is an abstraction of the Mbientlab Metawear API. This class has two main attributes that represents the sensors that formed the device:

__init__

def __init__(self, mac_address=None)

MetaMotion constructor. This method is the start point of the library and must be invoked in order to use the library characteristics

Parameters:

check_model

def check_model(self, model)

Check if the model of the connected device is the MetaMotionR

Parameters:

connect

def connect(self)

Method to make the bluetooth connection with the MetaMotion sensor. It includes some necessary initialization for the library, like create an instance for the sensors and subscribe to some events. Also, check that the model of the sensor that we are connecting is the properly (MetaMotionR)

disconnect

def disconnect(self)

Disables all the sensors of the MetaMotionR device, and clean and disconnect it.

download_logs

def download_logs(self)

Download the data saved in the logs previosuly created in a MetaMotion device

get_device_info

def get_device_info(self)

Returns a string with the basic information of the device

is_connected

def is_connected(self)

Method to check if the MetaMotion sensor is correctly connected. If the sensor is correctly connected return True, else return False

read_battery

def read_battery(self)

Return information about the battery of the device. It has two fields:

scan_metamotion_sensor

def scan_metamotion_sensor(cls)

Method of the class that enable te user to scan MetaMotionR sensor. After the scanner this method return a list with the address of all the sensors found. If the list is empty there is no MetaMotionR devices nearby

setup_accelerometer

def setup_accelerometer(self, freq=25, motion_samples=4, motion_threshold=0.7, tap_threshold=1)

Initialize the accelerometer sensors that is part of the MetaMotionR device. Is mandatory to invoke this method before use any funcionalities of the accelerometer.

Parameters:

setup_gyroscope

def setup_gyroscope(self, freq=25)

Initialize the gyroscope sensor that is part of the MetaMotionR device. Is mandatory to invoke this method before use any funcionalities of the gyroscope.

Parameters:

start_logging

def start_logging(self)

Start to logging the data

stop_logging

def stop_logging(self)

Stop data logging.

subscribe_battery

def subscribe_battery(self)

Subscribe for battery signal in order tu update the battery level attribute

turn_off_led

def turn_off_led(self)

Turn off the led of the sensor

turn_on_led

def turn_on_led(self, mode, color)

Turn on the led of the sensor. It has tow parameters

Class MetaMotionDeviceNotFound

After a scanner, MetaMotion device was not found

Class Mode

Class to save constants about the led modes. There are three modes, BLINK, PULSE and SOLID

Class WrongMetaDeviceModel

Exception which indicates that the sensor connecte is not a MetaMotionR device