ECE 4760 Final Project
 All Files Functions Variables Enumerations Enumerator Macros
Macros | Functions
imu.c File Reference
#include <avr/io.h>
#include "i2cmaster.h"
#include "imu.h"

Go to the source code of this file.

Macros

#define ga   (LSM9DS0_G)
 
#define xma   (LSM9DS0_XM)
 
#define g_rb(x)   (imu_rb(ga,x))
 
#define g_rbs(x, y, z)   (imu_rbs(ga,x,y,z))
 
#define g_wb(x, y)   (imu_wb(ga,x,y))
 
#define xm_rb(x)   (imu_rb(xma,x))
 
#define xm_rbs(x, y, z)   (imu_rbs(xma,x,y,z))
 
#define xm_wb(x, y)   (imu_wb(xma,x,y))
 
#define multiple(x)   (x | 0x80)
 

Functions

int16_t readTemp ()
 Returns the temperature in Celcius. Will be 25 degrees, which is the optimal temparture for the gyroscope. Is used internally for self-calibration. More...
 
uint16_t init_imu (enum gyro_scale gScl, enum accel_scale aScl, enum mag_scale mScl, enum gyro_odr gODR, enum accel_odr aODR, enum mag_odr mODR)
 Initilizes the IMU and enables all 9 axes and set the respective scales and data rates. More...
 
void initGyro ()
 initialize the gyroscope, must be done before reading from the gyroscope More...
 
void assert (char v)
 
void initAccel ()
 initilize the accelometer, this must be called before using any accelometer fucntions More...
 
void initMag ()
 
void readAccel (int16_t *ax, int16_t *ay, int16_t *az)
 
void readMag (int16_t *mx, int16_t *my, int16_t *mz)
 
void readGyro (int16_t *gx, int16_t *gy, int16_t *gz)
 
void read_gyro (float *x, float *y, float *z)
 Reads the gyroscope and calculates the real value from the raw reading. More...
 
void read_accel (float *x, float *y, float *z)
 Reads the accelometer and calculates the real value from the raw reading. More...
 
void read_mag (float *x, float *y, float *z)
 Reads the magnemeter and calculates the real value from the raw reading. More...
 
float calcGyro (int16_t gyro)
 takes a raw gyro reading and returns the actual value More...
 
float calcAccel (int16_t accel)
 
float calcMag (int16_t mag)
 
void setGyroScale (enum gyro_scale gScl)
 set the scale of the gyroscope see enum gyro_Scale to see what values this can take. More...
 
void setAccelScale (enum accel_scale aScl)
 see the setGyroScle function More...
 
void setMagScale (enum mag_scale mScl)
 see the setGyroScale function More...
 
void setGyroODR (enum gyro_odr gRate)
 set the data capture rate of the gyroscope see the enum gyro_odr to see what values this can take. More...
 
void setAccelODR (enum accel_odr aRate)
 see setGyroODR function More...
 
void setAccelABW (enum accel_abw abwRate)
 
void setMagODR (enum mag_odr mRate)
 see the setGyroODR function More...
 
void calcgRes ()
 sets the gRes variable to the correct resolution of the gyroscope readings More...
 
void calcaRes ()
 sets the aRes variable to the correct resolution of the accelometer readings More...
 
void calcmRes ()
 sets the mRes variable to the correct resolution of the magenmeter readings More...
 
void imu_wb (uint8_t address, uint8_t subAddress, uint8_t data)
 Writes a byte to the register at the address specified by subAddress. More...
 
uint8_t imu_rb (uint8_t address, uint8_t subAddress)
 Read one byte from the device. More...
 
void imu_rbs (uint8_t address, uint8_t subAddress, uint8_t *dest, uint8_t count)
 read multiple bytes from the imu More...
 

Macro Definition Documentation

#define g_rb (   x)    (imu_rb(ga,x))

Definition at line 16 of file imu.c.

#define g_rbs (   x,
  y,
 
)    (imu_rbs(ga,x,y,z))

Definition at line 17 of file imu.c.

#define g_wb (   x,
 
)    (imu_wb(ga,x,y))

Definition at line 18 of file imu.c.

#define ga   (LSM9DS0_G)

Definition at line 12 of file imu.c.

#define multiple (   x)    (x | 0x80)

Definition at line 22 of file imu.c.

#define xm_rb (   x)    (imu_rb(xma,x))

Definition at line 19 of file imu.c.

#define xm_rbs (   x,
  y,
 
)    (imu_rbs(xma,x,y,z))

Definition at line 20 of file imu.c.

#define xm_wb (   x,
 
)    (imu_wb(xma,x,y))

Definition at line 21 of file imu.c.

#define xma   (LSM9DS0_XM)

Definition at line 13 of file imu.c.

Function Documentation

void assert ( char  v)

Definition at line 133 of file imu.c.

float calcAccel ( int16_t  accel)
Parameters
accel
Returns
The adjusted value

Definition at line 265 of file imu.c.

void calcaRes ( )

sets the aRes variable to the correct resolution of the accelometer readings

Definition at line 397 of file imu.c.

void calcgRes ( )

sets the gRes variable to the correct resolution of the gyroscope readings

Definition at line 378 of file imu.c.

float calcGyro ( int16_t  gyro)

takes a raw gyro reading and returns the actual value

Parameters
gyroraw reading form gyroscope
Returns
The adjusted value

Definition at line 259 of file imu.c.

float calcMag ( int16_t  mag)
Parameters
mag
Returns
The adjusted value

Definition at line 271 of file imu.c.

void calcmRes ( )

sets the mRes variable to the correct resolution of the magenmeter readings

Definition at line 406 of file imu.c.

uint8_t imu_rb ( uint8_t  address,
uint8_t  subAddress 
)

Read one byte from the device.

Parameters
addressi2c device address
subAddressAddress of desired register
Returns
The byte read from the device

Definition at line 426 of file imu.c.

void imu_rbs ( uint8_t  address,
uint8_t  subAddress,
uint8_t *  dest,
uint8_t  count 
)

read multiple bytes from the imu

Parameters
addressaddress of the twi device to read from
subAddressregister to read from
destdestination buffer must be of size >= count
countNumber of bytes to read

Definition at line 437 of file imu.c.

void imu_wb ( uint8_t  address,
uint8_t  subAddress,
uint8_t  data 
)

Writes a byte to the register at the address specified by subAddress.

Parameters
addressi2c/twi address of the accelometer / gyroscope
subAddressThe address of the register that will be written to
dataThe singular data byte that is to be written to the register specified

Definition at line 416 of file imu.c.

uint16_t init_imu ( enum gyro_scale  gScl,
enum accel_scale  a_scl,
enum mag_scale  m_scl,
enum gyro_odr  g_odr,
enum accel_odr  a_odr,
enum mag_odr  m_odr 
)

Initilizes the IMU and enables all 9 axes and set the respective scales and data rates.

Parameters
gSclGyro Scale
a_sclAccelometer Scale
m_sclMagnemeter Scale
g_odrGyro data rate
a_odraccelometer data rate
m_odrmagnemeter data rate

Definition at line 32 of file imu.c.

void initAccel ( void  )

initilize the accelometer, this must be called before using any accelometer fucntions

Definition at line 139 of file imu.c.

void initGyro ( )

initialize the gyroscope, must be done before reading from the gyroscope

Definition at line 75 of file imu.c.

void initMag ( void  )

Definition at line 152 of file imu.c.

void read_accel ( float *  x,
float *  y,
float *  z 
)

Reads the accelometer and calculates the real value from the raw reading.

Parameters
xx-axis
yy-axis
zz-axis

Definition at line 241 of file imu.c.

void read_gyro ( float *  x,
float *  y,
float *  z 
)

Reads the gyroscope and calculates the real value from the raw reading.

Parameters
xx-axis
yy-axis
zz-axis

Definition at line 233 of file imu.c.

void read_mag ( float *  x,
float *  y,
float *  z 
)

Reads the magnemeter and calculates the real value from the raw reading.

Parameters
xx-axis
yy-axis
zz-axis

Definition at line 249 of file imu.c.

void readAccel ( int16_t *  ax,
int16_t *  ay,
int16_t *  az 
)

Definition at line 205 of file imu.c.

void readGyro ( int16_t *  gx,
int16_t *  gy,
int16_t *  gz 
)

Definition at line 223 of file imu.c.

void readMag ( int16_t *  mx,
int16_t *  my,
int16_t *  mz 
)

Definition at line 214 of file imu.c.

int16_t readTemp ( )

Returns the temperature in Celcius. Will be 25 degrees, which is the optimal temparture for the gyroscope. Is used internally for self-calibration.

Returns
The temperature in celcius,

Definition at line 24 of file imu.c.

void setAccelABW ( enum accel_abw  abwRate)

Definition at line 354 of file imu.c.

void setAccelODR ( enum accel_odr  aRate)

see setGyroODR function

Parameters
aRate

Definition at line 343 of file imu.c.

void setAccelScale ( enum accel_scale  aScl)

see the setGyroScle function

Parameters
aScl

Definition at line 295 of file imu.c.

void setGyroODR ( enum gyro_odr  gRate)

set the data capture rate of the gyroscope see the enum gyro_odr to see what values this can take.

Parameters
gRate

Definition at line 332 of file imu.c.

void setGyroScale ( enum gyro_scale  gScl)

set the scale of the gyroscope see enum gyro_Scale to see what values this can take.

Parameters
gScl

Definition at line 277 of file imu.c.

void setMagODR ( enum mag_odr  mRate)

see the setGyroODR function

Parameters
mRate

Definition at line 366 of file imu.c.

void setMagScale ( enum mag_scale  mScl)

see the setGyroScale function

Parameters
mScl

Definition at line 314 of file imu.c.