awesome library
0.5
Library for tutorial guiding through the library creation process
|
This Propeller C library was created for the Parallax 9-axis IMU Sensor, based on the STMicroelectronics LSM9DS1 inertial motion sensor chip. More...
Go to the source code of this file.
Functions | |
int | imu_init (int pinSCL, int pinSDIO, int pinAG, int pinM) |
Initializes the LSM9DS1 IMU module. More... | |
void | imu_calibrateAG () |
Calibrates the Accelerometer and Gyroscope on the LSM9DS1 IMU module. More... | |
void | imu_calibrateMag () |
Calibrates the Magnetometer on the LSM9DS1 IMU module. More... | |
void | imu_getMagCalibration (int *mxBias, int *myBias, int *mzBias) |
Retrieves the Magnetometer's calibration biases. More... | |
void | imu_getAccelCalibration (int *axBias, int *ayBias, int *azBias) |
Retrieves the Accelreometer's calibration biases. More... | |
void | imu_getGyroCalibration (int *gxBias, int *gyBias, int *gzBias) |
Retrieves the Gyroscope's calibration biases. More... | |
void | imu_setMagCalibration (int mxBias, int myBias, int mzBias) |
Sets the Magnetometer's calibration biases. More... | |
void | imu_setAccelCalibration (int axBias, int ayBias, int azBias) |
Sets the Accelerometer's calibration biases. More... | |
void | imu_setGyroCalibration (int gxBias, int gyBias, int gzBias) |
Sets the Gyroscope's calibration biases. More... | |
unsigned char | imu_accelAvailable () |
Polls the Accelerometer status register to check if new data is available. More... | |
unsigned char | imu_gyroAvailable () |
Polls the Gyroscope status register to check if new data is available. More... | |
unsigned char | imu_tempAvailable () |
Polls the Thermometer status register to check if new data is available. More... | |
unsigned char | imu_magAvailable () |
Polls the Magnetometer status register to check if new data is available. More... | |
void | imu_readGyro (int *gx, int *gy, int *gz) |
Reads the Gyroscope output registers. More... | |
void | imu_readAccel (int *ax, int *ay, int *az) |
Reads the Accelerometer output registers. More... | |
void | imu_readMag (int *mx, int *my, int *mz) |
Reads the Magnetometer output registers. More... | |
void | imu_readTemp (int *temperature) |
Reads the Temperature output registers. More... | |
void | imu_readGyroCalculated (float *gx, float *gy, float *gz) |
Reads the Gyroscope output registers and scales the outputs to degrees of rotation per second (DPS). More... | |
void | imu_readAccelCalculated (float *ax, float *ay, float *az) |
Reads the Accelerometer output registers and scales the outputs to g's (1 g = 9.8 m/s/s). More... | |
void | imu_readMagCalculated (float *mx, float *my, float *mz) |
Reads the Magnetometer output registers and scales the outputs to gauss'. More... | |
void | imu_readTempCalculated (float *temperature, char tempUnit) |
Reads the Thermometer output registers and scales the outputs to degrees Celsius, Fahrenheit, or Kelvin. More... | |
void | imu_setGyroScale (unsigned int gScl) |
Sets the full-scale range of the Gyroscope. More... | |
void | imu_setAccelScale (unsigned char aScl) |
Sets the full-scale range of the Accelerometer. More... | |
void | imu_setMagScale (unsigned char mScl) |
Sets the full-scale range of the Magnetometer. More... | |
int | imu_getGyroScale () |
Retrieves the full-scale range of the Gyroscope. More... | |
int | imu_getAccelScale () |
Retrieves the full-scale range of the Accelerometer. More... | |
int | imu_getMagScale () |
Retrieves the full-scale range of the Magnetometer. More... | |
void | imu_clearAccelInterrupt () |
Clears out any interrupts set up on the Accelerometer and resets all Accelerometer interrupt registers to their default values. More... | |
void | imu_clearGyroInterrupt () |
Clears out any interrupts set up on the Gyroscope and resets all Gyroscope interrupt registers to their default values. More... | |
void | imu_clearMagInterrupt () |
Clears out any interrupts set up on the Magnetometer and resets all Magnetometer interrupt registers to their default values. More... | |
void | imu_setAccelInterrupt (char axis, float threshold, char duration, char overUnder, char andOr) |
Configures the Accelerometer interrupt output to the INT_A/G pin. More... | |
void | imu_setGyroInterrupt (char axis, float threshold, char duration, char overUnder, char andOr) |
Configures the Gyroscope interrupt output to the INT_A/G pin. More... | |
void | imu_setMagInterrupt (char axis, float threshold, char overPos, char underNeg, char lowHigh) |
Configures the Magnetometer interrupt output to the INT_M pin. More... | |
void | imu_SPIwriteByte (unsigned char csPin, unsigned char subAddress, unsigned char data) |
Writes a byte to the specified LSM9DS1 register. | |
void | imu_SPIreadBytes (unsigned char csPin, unsigned char subAddress, unsigned char *dest, unsigned char count) |
Reads a specified number of bytes from the specified LSM9DS1 register. | |
This Propeller C library was created for the Parallax 9-axis IMU Sensor, based on the STMicroelectronics LSM9DS1 inertial motion sensor chip.
unsigned char imu_accelAvailable | ( | ) |
Polls the Accelerometer status register to check if new data is available.
void imu_calibrateAG | ( | ) |
Calibrates the Accelerometer and Gyroscope on the LSM9DS1 IMU module.
This is a function that uses the FIFO to accumulate sample of accelerometer and gyro data, averages them, scales them to gs and deg/s, respectively, and then passes the biases to variables in the library for subtraction from all subsequent data. Results in a more accurate measurement in general and can remove errors due to imprecise or varying initial placement.
void imu_calibrateMag | ( | ) |
Calibrates the Magnetometer on the LSM9DS1 IMU module.
This is a function accumulates samples from the magnetometer, averages them, and then passes the biases back to the LSM9DS1 for subtraction from all subsequent data. Results in a more accurate measurement in general and can remove errors due to imprecise or varying initial placement.
void imu_clearAccelInterrupt | ( | ) |
Clears out any interrupts set up on the Accelerometer and resets all Accelerometer interrupt registers to their default values.
void imu_clearGyroInterrupt | ( | ) |
Clears out any interrupts set up on the Gyroscope and resets all Gyroscope interrupt registers to their default values.
void imu_clearMagInterrupt | ( | ) |
Clears out any interrupts set up on the Magnetometer and resets all Magnetometer interrupt registers to their default values.
void imu_getAccelCalibration | ( | int * | axBias, |
int * | ayBias, | ||
int * | azBias | ||
) |
Retrieves the Accelreometer's calibration biases.
This function retrieves the calibration biases for each Accelreometer axis. Biases can be retrieved after a Accelreometer calibration has been performed.
*axBias | variable to store Accelreometer x-axis bias into. |
*ayBias | variable to store Accelreometer y-axis bias into. |
*azBias | variable to store Accelreometer z-axis bias into. |
int imu_getAccelScale | ( | ) |
Retrieves the full-scale range of the Accelerometer.
This function can be called to get the scale of the Accelerometer.
void imu_getGyroCalibration | ( | int * | gxBias, |
int * | gyBias, | ||
int * | gzBias | ||
) |
Retrieves the Gyroscope's calibration biases.
This function retrieves the calibration biases for each Gyroscope axis. Biases can be retrieved after a Gyroscope calibration has been performed.
*gxBias | variable to store Gyroscope x-axis bias into. |
*gyBias | variable to store Gyroscope y-axis bias into. |
*gzBias | variable to store Gyroscope z-axis bias into. |
int imu_getGyroScale | ( | ) |
Retrieves the full-scale range of the Gyroscope.
This function can be called to get the scale of the Gyroscope.
void imu_getMagCalibration | ( | int * | mxBias, |
int * | myBias, | ||
int * | mzBias | ||
) |
Retrieves the Magnetometer's calibration biases.
This function retrieves the calibration biases for each Magnetometer axis. Biases can be retrieved after a Magnetometer calibration has been performed.
*mxBias | variable to store Magnetometer x-axis bias into. |
*myBias | variable to store Magnetometer y-axis bias into. |
*mzBias | variable to store Magnetometer z-axis bias into. |
int imu_getMagScale | ( | ) |
Retrieves the full-scale range of the Magnetometer.
This function can be called to get the scale of the Magnetometer.
unsigned char imu_gyroAvailable | ( | ) |
Polls the Gyroscope status register to check if new data is available.
int imu_init | ( | int | pinSCL, |
int | pinSDIO, | ||
int | pinAG, | ||
int | pinM | ||
) |
Initializes the LSM9DS1 IMU module.
This function initializes the LSM9DS1 IMU module. It sets the chip to 3-wire SPI mode and starts up the accelerometer, gyroscope, and magnetometer.
pinSCL | I/O Pin connected to the module's SCL pin. |
pinSDIO | I/O Pin connected to the module's SDIO pin. |
pinAG | I/O Pin connected to the module's CS_AG pin. |
pinM | I/O Pin connected to the module's CS_M pin. |
unsigned char imu_magAvailable | ( | ) |
Polls the Magnetometer status register to check if new data is available.
void imu_readAccel | ( | int * | ax, |
int * | ay, | ||
int * | az | ||
) |
Reads the Accelerometer output registers.
This function will read all six Accelerometer output registers. The readings are stored in the specified variables.
*ax | Variable to store Raw x-axis Accelerometer reading into. |
*ay | Variable to store Raw y-axis Accelerometer reading into. |
*az | Variable to store Raw z-axis Accelerometer reading into. |
void imu_readAccelCalculated | ( | float * | ax, |
float * | ay, | ||
float * | az | ||
) |
Reads the Accelerometer output registers and scales the outputs to g's (1 g = 9.8 m/s/s).
This function will read all six Accelerometer output registers. The scaled readings in g's are stored in the specified variables.
*ax | Variable to store scaled x-axis Accelerometer reading into. |
*ay | Variable to store scaled y-axis Accelerometer reading into. |
*az | Variable to store scaled z-axis Accelerometer reading into. |
void imu_readGyro | ( | int * | gx, |
int * | gy, | ||
int * | gz | ||
) |
Reads the Gyroscope output registers.
This function will read all six Gyroscope output registers. The readings are stored in the specified variables.
*gx | Variable to store Raw x-axis Gyroscope reading into. |
*gy | Variable to store Raw y-axis Gyroscope reading into. |
*gz | Variable to store Raw z-axis Gyroscope reading into. |
void imu_readGyroCalculated | ( | float * | gx, |
float * | gy, | ||
float * | gz | ||
) |
Reads the Gyroscope output registers and scales the outputs to degrees of rotation per second (DPS).
This function will read all six Gyroscope output registers. The scaled readings ins DPS are stored in the specified variables.
*gx | Variable to store scaled x-axis Gyroscope reading into. |
*gy | Variable to store scaled y-axis Gyroscope reading into. |
*gz | Variable to store scaled z-axis Gyroscope reading into. |
void imu_readMag | ( | int * | mx, |
int * | my, | ||
int * | mz | ||
) |
Reads the Magnetometer output registers.
This function will read all six Magnetometer output registers. The readings are stored in the specified variables.
*mx | Variable to store Raw x-axis Magnetometer reading into. |
*my | Variable to store Raw y-axis Magnetometer reading into. |
*mz | Variable to store Raw z-axis Magnetometer reading into. |
void imu_readMagCalculated | ( | float * | mx, |
float * | my, | ||
float * | mz | ||
) |
Reads the Magnetometer output registers and scales the outputs to gauss'.
This function will read all six Magnetometer output registers. The scaled readings in gauss' are stored in the specified variables.
*mx | Variable to store scaled x-axis Magnetometer reading into. |
*my | Variable to store scaled y-axis Magnetometer reading into. |
*mz | Variable to store scaled z-axis Magnetometer reading into. |
void imu_readTemp | ( | int * | temperature | ) |
Reads the Temperature output registers.
This function will read all six Temperature output registers. The readings are stored in the specified variables.
*temperature | Variable to store Raw Temperature reading into. |
void imu_readTempCalculated | ( | float * | temperature, |
char | tempUnit | ||
) |
Reads the Thermometer output registers and scales the outputs to degrees Celsius, Fahrenheit, or Kelvin.
This function reads the Thermometer output registers. The scaled reading in are stored in the specified variables.
*temperature | Variable to store scaled Thermometer reading into. |
tempUnit | Value to set the unit to scale the output to. Acceptable values are CELSIUS (0), FAHRENHEIT (1), KELVIN (2). |
void imu_setAccelCalibration | ( | int | axBias, |
int | ayBias, | ||
int | azBias | ||
) |
Sets the Accelerometer's calibration biases.
This function sets the calibration biases for each Accelerometer axis. Biases can be retrieved after the Accelerometer calibration has been set.
axBias | Value to set Accelerometer x-axis bias to. |
ayBias | Value to set Accelerometer y-axis bias to. |
azBias | Value to set Accelerometer z-axis bias tp. |
void imu_setAccelInterrupt | ( | char | axis, |
float | threshold, | ||
char | duration, | ||
char | overUnder, | ||
char | andOr | ||
) |
Configures the Accelerometer interrupt output to the INT_A/G pin.
axis | Sets which axis (or all axes) to be configured to send out an interrupt. Values can be X_AXIS (0), Y_AXIS (1), Z_AXIS (2), or ALL_AXIS (3). |
threshold | Sets the threshold magnitude (as a floating point value in g's) for triggering an interrupt. The Accelerometer interrupt threshold is an absolute value, so it triggers on accelerations crossing the threshold in both the positive and negative directions. The thershold can be up to 50% of the full scale value. |
duration | Sets how long the INT_A/G pin is held high once an interrupt is triggered. The duration is measured in samples - since samples are taken approximetly every 10ms, a duration of 100 is roughly 1 second. The duration can be any integer value from 0 to 255. |
overUnder | Sets whether the interrupt is triggered when the acceleration is a greater (1) or lesser (0) magnitude than the threshold. |
andOr | If interrupts for multiple axis have been set, this sets whether the interrupts for the individual axis must all be triggered (AND condition - 1), or if only one of them has to be triggered (OR condition - 0). |
void imu_setAccelScale | ( | unsigned char | aScl | ) |
Sets the full-scale range of the Accelerometer.
This function can be called to set the scale of the Accelerometer to 2, 4, 8, or 16 g's.
aScl | Value of the desired Accelerometer scale. Must be 2, 4, 8, or 16. |
void imu_setGyroCalibration | ( | int | gxBias, |
int | gyBias, | ||
int | gzBias | ||
) |
Sets the Gyroscope's calibration biases.
This function sets the calibration biases for each Gyroscope axis. Biases can be retrieved after the Gyroscope calibration has been set.
gxBias | Value to set Gyroscope x-axis bias to. |
gyBias | Value to set Gyroscope y-axis bias to. |
gzBias | Value to set Gyroscope z-axis bias tp. |
void imu_setGyroInterrupt | ( | char | axis, |
float | threshold, | ||
char | duration, | ||
char | overUnder, | ||
char | andOr | ||
) |
Configures the Gyroscope interrupt output to the INT_A/G pin.
axis | Sets which axis (or all axes) to be configured to send out an interrupt. Values can be X_AXIS (0), Y_AXIS (1), Z_AXIS (2), or ALL_AXIS (3). |
threshold | Sets the threshold (as a floating point value in gauss) for triggering an interrupt. The Gyroscope interrupt thresholds can be positive or negative, so it triggers on rotations occuring in one direction. The thershold can be up to 50% of the full scale value. |
duration | Sets how long the INT_A/G pin is held high once an interrupt is triggered. The duration is measured in samples - since samples are taken approximetly every 10ms, a duration of 100 is roughly 1 second. The duration can be any integer value from 0 to 255. |
overUnder | Sets whether the interrupt is triggered when the rotational speed is above (1) or below (0) than the threshold. |
andOr | If interrupts for multiple axis have been set, this sets whether the interrupts for the individual axis must all be triggered (AND condition - 1), or if only one of them has to be triggered (OR condition - 0). |
void imu_setGyroScale | ( | unsigned int | gScl | ) |
Sets the full-scale range of the Gyroscope.
This function can be called to set the scale of the Gyroscope to 245, 500, or 2000 degrees per second.
gScl | Value of the desired Gyroscope scale. Must be 245, 500, or 2000. |
void imu_setMagCalibration | ( | int | mxBias, |
int | myBias, | ||
int | mzBias | ||
) |
Sets the Magnetometer's calibration biases.
This function sets the calibration biases for each Magnetometer axis. Biases can be retrieved after the Magnetometers calibration has been set.
mxBias | Value to set Magnetometer x-axis bias to. |
myBias | Value to set Magnetometer y-axis bias to. |
mzBias | Value to set Magnetometer z-axis bias tp. |
void imu_setMagInterrupt | ( | char | axis, |
float | threshold, | ||
char | overPos, | ||
char | underNeg, | ||
char | lowHigh | ||
) |
Configures the Magnetometer interrupt output to the INT_M pin.
axis | Sets which axis (or all axes) to be configured to send out an interrupt. Values can be X_AXIS (0), Y_AXIS (1), Z_AXIS (2), or ALL_AXIS (3). |
threshold | Sets the threshold (as a floating point value in Degrees Per Second) for triggering an interrupt. The Magnetometer interrupt threshold is an absolute value, so it sets triggers for magnetic field strengths crossing the threshold in both positive and negative directions. The threshold can be up to 50% of the full scale value. |
overPos | If set (1), the interrupt triggers when the magnetic field strength is larger than the threshold in the positive direction. |
underNeg | If set (1), the interrupt triggers when the magnetic field strength is larger (more negative) than the threshold in the negative direction. |
lowHigh | When the interrupt is triggered, sets the INT_M pin high (1) or low (0). |
void imu_setMagScale | ( | unsigned char | mScl | ) |
Sets the full-scale range of the Magnetometer.
This function can be called to set the scale of the Magnetometer to 2, 4, 8, or 12 gauss.
mScl | Value of the desired Magnetometer scale. Must be 4, 8, 12 or 16. |
unsigned char imu_tempAvailable | ( | ) |
Polls the Thermometer status register to check if new data is available.