Library for the control of a MetaMotionR device
class index:
- Accelerometer
- Color
- ConnectionError
- Gyroscope
- MetaMotion
- MetaMotionDeviceNotFound
- Mode
- WrongMetaDeviceModel
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:
board
[mandatory] this is the MetaMotionR Board where the sensor is located.freq
[optional] Frequency at which the acceleration is updated. By default, the frequency is 25Hz what means that will be sent 25 acceleration signales per second.motion_samples
[optional] Number of samples that must overpass themotion_threshold
in order to consider a motion.motion_threshold
[optional] Difference between the samples indicated inmotion_samples
to consider a motion.tap_threshold
[optional] Difference between samples acceleration to consider a tap.
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:
acc_freq
[optional] Frequency at which the acceleration is updated. By default, the frequency is 25Hz what means that will be sent 25 acceleration signales per second.motion_samples
[optional] Number of samples that must overpass themotion_threshold
in order to consider a motion.motion_threshold
[optional] Difference between the samples indicated inmotion_samples
to consider a motion.tap_threshold
[optional] Difference between samples acceleration to consider a tap.
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:
attr
[mandatory] this is the class atribute where the data recived by the signal is going to be saved.handler
[mandatory] a user handler to process the data once received.
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:
func
[optional] a handler to process the data.
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:
func
[optional] a handler to process the data.
on_tap
def on_tap(self, func=None)
Subscribe tap data and attach a handler that receives tap as a parameter
Parameter:
func
[optional] a handler to process the data.
read_acceleration
def read_acceleration(self)
Return the last acceleration detected by the sensor. The acceleration is formed by the following fields:
x
: Acceleration in X axis in Gs units.y
: Acceleration in Y axis in Gs units.z
: Acceleration in Z axis in Gs units.
read_motion
def read_motion(self)
Return the last motion detected by the sensor. The motion is formed by the following fields:
sign
: Axis direction where the sensor is moving.x_axis_active
: 1 if the motion was produced in the X axis.y_axis_active
: 1 if the motion was produced in the Y axis.z_axis_active
: 1 if the motion was produced in the Z axis.
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:
sign
: Axis direction where the tap is detected.type
: 2 if only 1 tap is detected, 1 if 2 taps.
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:
attr
[mandatory] this is the class atribute where the data recived by the signal is going to be saved.signal_subscriber
[mandatory] is the metawear function that enable the user to receive data from a signal.func
[optional] a user handler to process the data once received.
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:
attr
[mandatory] this is the class atribute where the data recived by the signal is going to be saved.handler
[mandatory] a user handler to process the data once received.
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:
func
[optional] a handler to process the data.
read_rotation
def read_rotation(self)
Return the last rotation detected by the sensor. The rotation is formed by the following attributes:
x
: Rotation in the X axis in degrees per second.y
: Rotation in the Y axis in degrees per second.z
: Rotation in the Z axis in degrees per second.
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:
attr
[mandatory] this is the class atribute where the data recived by the signal is going to be saved.signal_subscriber
[mandatory] is the metawear function that enable the user to receive data from a signal.func
[optional] a user handler to process the data once received.
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:
- accelerometer: Instance of the
Accelerometer
class - gyroscope: Instance of the
Gyroscope
class
__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:
mac_address
, [optional] the MAC addres of the MetaMotion sensor that will be used in order to connect it by blutooth.
check_model
def check_model(self, model)
Check if the model of the connected device is the MetaMotionR
Parameters:
model
, [mandatory] the model of the device connected.
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:
voltage
: Voltage that feed the device.charge
: Percentage of battery that the sensor has.
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:
freq
[optional] Frequency at which the acceleration is updatea. By default, the frequency is 25Hz what means that will be sent 25 acceleration signales per second.motion_samples
[optional] Number of samples that must overpass themotion_threshold
in order to consider a motion.motion_threshold
[optional] Difference between the samples indicated inmotion_samples
to consider a motion.tap_threshold
[optional] Difference between samples acceleration to consider a tap.
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:
freq
[optional] Frequency at which the rotation is updated. By default the frequency is 25Hz. The library will try to assign the frequency closest to that indicated by the user and allowed by the sensor.
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
mode
: Mode in which the led is going to turn on. There are 3 different modes Mode.BLINK, Mode.PULSE and Mode.SOLIDcolor
: Color of the led, which could be Color.RED, Color.GREEN and Color.BLUE
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