Code Monkey home page Code Monkey logo

magum's Introduction

magum_header

Magnetometer, Accelerometer and Gyroscope UDOO Management (FXAS21002C, FXOS8700CQ)

licence python linux udoo

For full documentation visit our Site.

This Python module has been created to manage the sensors on the main board computer UDOO Neo. We tested magum on UDOO Neo rev. D with UDOObuntu RC1

Table of contents

Introduction

Magum, that stands for Magnetometer, Accelerometer and Gyroscope UDOO Management, is a Python library that allows you to completely manage all three senors built in UDOO Neo.

##The sensors

Below you can find a complete list of all sensors:

  • Gyroscope: FXAS2100C from Freescale Semiconductor Inc. (datasheet)

  • Accelerometer and Magnetometer: FXOS8700CQ from Freescale Semiconductor Inc. (datasheet)

##With Magum you can:

  • get data from all registers and write on them too
  • monitor in real time the values obtained by the sensors
  • using algorithms that use both accelerometer and gyroscope to detect orientation, and magnetometer to measure magnetic fields

##Axis orientation

magum works with this axis orientation even if the accelerometer is below the board:

![axis_orientation](http://s14.postimg.org/6v8ihdtrl/assi2_small.png {width=120px height=160px})

Bug reporting

To submit a bugreport use the GitHub bugtracker, opening an issue for the project:

Open an issue

Development

You can get the latest version from the repository hosted at GitHub

The file regs.py contains the entire list of the registers from both sensors used by magum

Getting Started

Magum works through the Python module smbus-cffi from bivab so you need a few things before you start:

  • a C compiler (e.g. gcc)
  • i2c developement header files server.
  • cffi
  • PyPy or CPython development headers
  • libffi-dev

To install these, you have to run the following commands from your terminal:

For Debian based distributions (e.g. Ubuntu distros, Linux Mint):

sudo apt-get install build-essential libi2c-dev i2c-tools python-dev libffi-dev

For Arch Linux:

pacman -S base-devel
pacman -S i2c-tools

Finally install cffi and smbus-cffi using pip with this command, or from the Github sources: cffi, smbus-cffi

pip install cffi
pip install smbus-cffi

Installation

You can obtain magum in different ways:

  • Download the repository as zip and unpack it
  • Clone our Github repository with this command from terminal (you have to install git to do this)
sudo apt-get install git
git clone https://github.com/ubalance-team/magum.git

Now navigate in the folder where you (or git) downloaded the repository with the terminal and run this command:

python setup.py install

Magum is now installed like any other Python modules already on your computer

Usage

Here you can find a guide to getting used of the most important methods of magum

Initializing magum

Magum is a Python class that you can initialize using parameters for configuring sensors

Magum(gScaleRange,fsDouble,aScaleRange,noise)

NOTE: If no parameters are entered the class will be automatically initialized with the last register configuration.

Parameters

  • gScaleRange : represents the range of the gyroscope. It can assume the following values: 250,500,1000,2000 dps.
  • fsDouble: enables (with value 1) or disables (with value 0) the fsdouble function to double the scale range of the gyroscope
  • aScaleRange : represents the range of the accelerometer. In can assume 2 for +/- 2g, 4 for +/- 4g or 8 for +/- 8g
  • noise : enables (with value 1) or disables (with value 0) the lnoise function for the accelerometer sensor

Example

magum = Magum(2000,0,2,1)

Creates an instance of Magum called magum with 2000dps of range for the gyroscope, fsdouble disabled, +/- 2g of range for the acceleremoter and lnoise function enabled.

##toStandby(sensor)

Put in standby mode the selected sensor

Parameters

  • sensor : type 'a' for accelerometer, 'm' for magnetometer, 'g' for gyroscope

Example:

magum.toStandby('a')

toActive(sensor)

Actives the selected sensor

###Parameters:

  • sensor : type 'a' for accelerometer, 'm' for magnetometer, 'g' for gyroscope

Example:

  magum.toActive('a')

killDrivers(x)

Magum can not work if the system drivers of the sensors are managing them. So it is crucial disable them before starting (Magum does automatically when the instance is initialized). killDrivers disable or re-enable these drivers.

Parameters:

  • x : if 1 disables drivers, if 0 re-enables them

Example:

  magum.killDrivers(1) 

setSensConf(sensor,reg,hexVal)

With this method you can configure all the registers (contained in regs.py)needed by the sensors.

Parameters:

  • sensor : type 'a' for accelerometer, 'm' for magnetometer, 'g' for gyroscope
  • reg : type a register name from regs.py list
  • hexValue : type the hexadecimal value that you want to write in the chosen register

Example:

  magum.setSensConf('a','A_XYZ_DATA_CFG',0x00)

Writes the value 0x00 value in the register named A_XYZ_DATA_CFG of the accelerometer

readAData(uM)

With this method you can get data from accelerometer specifying the unit of measure. Returns an array of three elements:

  • array[0] x axis
  • array[1] y axis
  • array[2] z axis

Parameters:

  • uM : type 'raw' for raw values, 'deg' for degrees, 'rad' for radiant, or 'gcomp' for components along the axes of the gravitational acceleration

NOTE: if no parameters are entered readAData returns raw values

Example:

array = magum.readAData('gcomp')

readMData(uM)

With this method you can get data from magnetometer specifying the unit of measure Returns an array of three elements:

  • array[0] x axis
  • array[1] y axis
  • array[2] z axis

Parameters:

  • uM : type 'raw' for raw values, 'ut' for μT values

NOTE: if no parameters are entered readMData returns raw values

Example:

array = magum.readMData('ut')

readGData(uM)

With this method you can get data from gyroscope specifying the unit of measure. Returns an array of three elements:

  • array[0] x axis
  • array[1] y axis
  • array[2] z axis

Parameters:

  • uM : type 'raw' for raw values, 'deg' for degrees or 'rad' for radiant

NOTE: if no parameters are entered readGData returns raw values

Example:

array = magum.readGData('rad')

readTData(uM)

With this method you can get data from temperature sensor specifying the unit of measure. Returns the value of temperature:

Parameters:

  • uM : type 'raw' for raw values, 'C' for Celsius degrees or 'K' for Kelvin, 'F' for Fahrenheit degrees

NOTE: if no parameters are entered readGData returns raw values

Example:

temp = magum.readTData('C')

getCurrentConf(sensor,screen)

This method returns the content of the registers of the selected sensor

Parameters:

  • sensor : type 'a' for accelerometer, 'm' for magnetometer, 'g' for gyroscope
  • screen : type 1 if you want to print the values on screen or 0 if you don't

NOTE: if screen parameter is not specified, getCurrentConf will not print values on screen

Example:

magum.getCurrentConf('a',1)

calibrateSens(samples)

This method calibrates the sensors calculating an average based on a selected number of samples (we suggest to work with 1000 samples). Returns an array of 9 elements, with the offsets that you have to subtract from sensors values:

  • indexes from 0 to 2: accelerometer
  • indexes from 3 to 5: gyroscope
  • indexes from 6 to 8: magnetometer

Parameters:

  • samples : type the number of samples to base the average for the calibration

Example:

array = magum.calibrateSens(1000)

compFilter(DT,AxisOffset)

Integrates the values from accelerometer and gyroscope using a complementary filter. This filter returns more accurate measurements and less noise. Returns an array with the angles values, for the x,y,z axes.

Parameters:

  • DT: is the sampling interval
  • AxisOffset: is the array with the offsets returned by calibrateSens(samples) method. It uses the first 6 values of this array

Example:

 angles_array = magum.compFilter(0.02,AxisOffset)

kalmanFilter(DT,AxisOffset)

Integrates the values from accelerometer and gyroscope using Kalman filter. This filter is more accurate than complementary filter but requires more computational power. Return the inclination angle from the selected axis.

### Parameters:

  • DT: is the sampling interval
  • axis: type the desidered axis: 'x', 'y' or 'z'
  • axisOffset: is the array with the offsets returned by calibrateSens(samples) method.

Example:

x_angle = magum.kalmanFilter(0.02,'x',AxisOffset)
y_angle = magum.kalmanFilter(0.02,'y',AxisOffset)

madgwickQuaternionFilter(aCompArray,gCompArray,mCompArray)

Implementation of Sebastian Madgwick's algorithm, wich fuses acceleration, rotation rate and magnetic moments to produce a quaternion-based estimate of absolute device orientation. Return an array filled with quaternions (q1, q2, q3,q4)

Parameters:

  • aCompArray: array of accelerometer g-components axis values
  • gCompArray: array of gyroscope axis values in rad/s
  • mCompArray: array of magnetometer axis values in μT

Example:

qArray= magum.madgwickQuaternionFilter(aCompArray,gCompArray,mCompArray)

#UbalancedGraphs

ubalnced_graphs

In order to use UbalancedGraphs web application, you should install Frask framework. To do this you can run from terminal the following command:

pip install Flask

To install Ubalanced graphs application, move to the main directory that you've cloned from remote magum repository, then move to the /UbalancedGraphs directory and run (as root):

sudo python setup.py

To start ubalanced graphs web app start the server as a service from terminal typing (make sure you are running as root):

sudo service ubalanced start

Now, you can access to UbalancedGraphs web application from your favourite browser at this address (assuming you are connected to UDOO via USB): 192.168.7.2:5001

To stop the service just type:

sudo service ubalanced stop

#Authors

Name Twitter
Francesco Guerri [![g_tweet][1l]][2l]
Francesco Orlandi [![o_tweet][1l]][3l]
Umberto Cucini [![c_tweet][1l]][4l]

[1l]: http://s15.postimg.org/dj8qlfb2v/tweetbutton.png) [2l]: https://twitter.com/rirri93 [3l]: https://twitter.com/0rla3 [4l]: https://twitter.com/umbertocucini

#Copyright

Magum is under GPL licence. See LICENSE file for the complete documentation

magum's People

Contributors

orla11 avatar ubalance-team avatar guerrifrancesco avatar cucio92 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.