DUDS
Distributed Update of Data from Something
duds::hardware::devices::instruments::LSM9DS1AccelGyro Class Reference

Initial support of the accelerometer and gyroscope on the LSM9DS1. More...

#include <LSM9DS1.hpp>

Inheritance diagram for duds::hardware::devices::instruments::LSM9DS1AccelGyro:
Collaboration diagram for duds::hardware::devices::instruments::LSM9DS1AccelGyro:

Classes

union  RawSample
 Stores the sample data as reported by the device. More...
 
struct  Settings
 The various settings for the device packed into an integer to avoid passing a lot of parameters. More...
 

Public Types

enum  AccelRange {
  AccelRange2g, AccelRange16g, AccelRange4g, AccelRange8g,
  AccelRange19m61ps2 = 0, AccelRange156m9ps2, AccelRange39m23ps2, AccelRange78m45ps2
}
 The maximum magnitude options for the accelerometer. More...
 
typedef duds::data::QuantityXyz ConvertedQuantity
 The sample data converted to known units. More...
 
enum  GyroRange {
  GyroRange245dps, GyroRange500dps, GyroRange2000dps = 3, GyroRange4r276ps = 0,
  GyroRange8r727ps, GyroRange34r91ps = 3
}
 The maximum magnitude options for the gyroscope. More...
 

Public Member Functions

 LSM9DS1AccelGyro (std::unique_ptr< duds::hardware::interface::I2c > &i2c)
 Attempts to identify the device, then suspends the device's operation. More...
 
 ~LSM9DS1AccelGyro ()
 Calls suspend(). More...
 
void accelerometerQuantity (ConvertedQuantity &ps) const
 Provides the accelerometer data in meters per second squared. More...
 
void configure (float freq, Settings settings)
 Configures the device. More...
 
void gyroscopeQuantity (ConvertedQuantity &ps) const
 Provides the gyroscope data in radians per second. More...
 
const RawSamplerawAccelerometer () const
 Returns the accelerometer data as read from the device. More...
 
const RawSamplerawGyroscope () const
 
void resume ()
 Resumes operation after a call to suspend(). More...
 
bool sample ()
 Reads sampled data from the device. More...
 
float sampleRate () const
 Returns the confiured sampling rate. More...
 
void start ()
 Tells the device to start sampling. More...
 
void suspend ()
 Suspends operation by putting the device into a low-power mode that discontinues sampling. More...
 

Private Attributes

RawSample accl
 The values supplied by the device. More...
 
std::unique_ptr< duds::hardware::interface::I2cagcom
 The I2C communication interface. More...
 
float agdatarate
 The currently configured sample rate. More...
 
std::int8_t agdrval
 The data rate value given to the device. More...
 
duds::hardware::interface::Conversation agsample
 The conversation used to read in samples from the device. More...
 
Settings cfg
 The current various configuration options. More...
 
RawSample gyro
 
duds::hardware::interface::Conversation initialize
 The conversation used to initialize the device. More...
 
duds::hardware::interface::Conversation statq
 

Detailed Description

Initial support of the accelerometer and gyroscope on the LSM9DS1.

The magnetometer is supported by LSM9DS1Mag because it acts like an independent device. The documentation makes it seem as though the LSM9DS1 is really two devices stuck together.

The Sparkfun board I've got uses I2C address 0x6B for the accelerometer and gyroscope.

Author
Jeff Jackowski

Definition at line 49 of file LSM9DS1.hpp.

Member Typedef Documentation

◆ ConvertedQuantity

The sample data converted to known units.

The accelerometer data is a bit of a guess since its units are vaugely defined and callibration is done based on the local pull of Earth's gravity.

Definition at line 68 of file LSM9DS1.hpp.

Member Enumeration Documentation

◆ AccelRange

The maximum magnitude options for the accelerometer.

The ordering is strange, but that is how the device does it.

Enumerator
AccelRange2g 

Selects the +/-2g accelerometer range.

AccelRange16g 

Selects the +/-16g accelerometer range.

AccelRange4g 

Selects the +/-4g accelerometer range.

AccelRange8g 

Selects the +/-8g accelerometer range.

AccelRange19m61ps2 

19.6133m/(s*s)

AccelRange156m9ps2 

156.9064m/(s*s)

AccelRange39m23ps2 

39.2266m/(s*s)

AccelRange78m45ps2 

78.4532m/(s*s)

Definition at line 73 of file LSM9DS1.hpp.

◆ GyroRange

The maximum magnitude options for the gyroscope.

Enumerator
GyroRange245dps 

245 degrees per second

GyroRange500dps 

500 degrees per second

GyroRange2000dps 

2000 degrees per second

GyroRange4r276ps 

4.276 radians per second

GyroRange8r727ps 

8.727 radians per second

GyroRange34r91ps 

34.91 radians per second

Definition at line 98 of file LSM9DS1.hpp.

Constructor & Destructor Documentation

◆ LSM9DS1AccelGyro()

duds::hardware::devices::instruments::LSM9DS1AccelGyro::LSM9DS1AccelGyro ( std::unique_ptr< duds::hardware::interface::I2c > &  i2c)

Attempts to identify the device, then suspends the device's operation.

This resets the device, which requires 2ms to complete.

Sparkfun's board uses device address 0x6B.

Postcondition
The device is suspended.
Parameters
i2cThe I2C object to use to communicate with the accelerometer/gyroscope part of the device. This LSM9DS1 object will take ownership over the communicator.
Postcondition
The provided i2c unique_ptr no longer contains an object upon success. If any exception is thrown, the unique_ptr will retain the object.
Exceptions
DeviceMisidentifiedThe reported device ID is incorrect.

Definition at line 188 of file LSM9DS1.cpp.

◆ ~LSM9DS1AccelGyro()

duds::hardware::devices::instruments::LSM9DS1AccelGyro::~LSM9DS1AccelGyro ( )

Calls suspend().

Definition at line 232 of file LSM9DS1.cpp.

Member Function Documentation

◆ accelerometerQuantity()

void duds::hardware::devices::instruments::LSM9DS1AccelGyro::accelerometerQuantity ( ConvertedQuantity ps) const

Provides the accelerometer data in meters per second squared.

Definition at line 352 of file LSM9DS1.cpp.

◆ configure()

void duds::hardware::devices::instruments::LSM9DS1AccelGyro::configure ( float  freq,
Settings  settings 
)

Configures the device.

Postcondition
The device will be suspended.
Parameters
freqThe minimum sample frequency. If the rate is too high, LSM9DS1BadDataRate will be thrown.
settingsThe requested device configuration.
Exceptions
LSM9DS1NoInsturmentThe configuration does not select either the accelerometer or magnetometer for use.
LSM9DS1BadMagnitudeThe requested maximum magnetude for the accelerometer is either not supported or an invalid value.
LSM9DS1BadDataRate

Definition at line 236 of file LSM9DS1.cpp.

◆ gyroscopeQuantity()

void duds::hardware::devices::instruments::LSM9DS1AccelGyro::gyroscopeQuantity ( ConvertedQuantity ps) const

Provides the gyroscope data in radians per second.

Definition at line 359 of file LSM9DS1.cpp.

◆ rawAccelerometer()

const RawSample& duds::hardware::devices::instruments::LSM9DS1AccelGyro::rawAccelerometer ( ) const
inline

Returns the accelerometer data as read from the device.

The data will be shifted, if needed, so that the LSb of the sample data will be in the LSb of the integers. Otherwise, the data is unchanged from what the device reported.

Note
The values will change when the device is sampled and the accelerometer is in use.

Definition at line 248 of file LSM9DS1.hpp.

◆ rawGyroscope()

const RawSample& duds::hardware::devices::instruments::LSM9DS1AccelGyro::rawGyroscope ( ) const
inline

Definition at line 251 of file LSM9DS1.hpp.

◆ resume()

void duds::hardware::devices::instruments::LSM9DS1AccelGyro::resume ( )
inline

Resumes operation after a call to suspend().

Seems to be a nice name that I used with other device drivers, so I put it here until I do more to figure out a consistent interface that I like.

Exceptions
DeviceUninitalizedinit() hasn't been called.

Definition at line 225 of file LSM9DS1.hpp.

◆ sample()

bool duds::hardware::devices::instruments::LSM9DS1AccelGyro::sample ( )

Reads sampled data from the device.

Returns
True if the device had new data.

Definition at line 333 of file LSM9DS1.cpp.

◆ sampleRate()

float duds::hardware::devices::instruments::LSM9DS1AccelGyro::sampleRate ( ) const
inline

Returns the confiured sampling rate.

The value will be zero if configure() has not yet been called, or if it failed.

Definition at line 237 of file LSM9DS1.hpp.

◆ start()

void duds::hardware::devices::instruments::LSM9DS1AccelGyro::start ( )
inline

Tells the device to start sampling.

Precondition
configure() has been called and succeeded.

Definition at line 209 of file LSM9DS1.hpp.

◆ suspend()

void duds::hardware::devices::instruments::LSM9DS1AccelGyro::suspend ( )

Suspends operation by putting the device into a low-power mode that discontinues sampling.

This may require as much as 300ms to complete if the magnetometer is in use.

Definition at line 322 of file LSM9DS1.cpp.

Referenced by configure(), and ~LSM9DS1AccelGyro().

Member Data Documentation

◆ accl

RawSample duds::hardware::devices::instruments::LSM9DS1AccelGyro::accl
private

The values supplied by the device.

Definition at line 153 of file LSM9DS1.hpp.

Referenced by accelerometerQuantity(), and sample().

◆ agcom

std::unique_ptr<duds::hardware::interface::I2c> duds::hardware::devices::instruments::LSM9DS1AccelGyro::agcom
private

The I2C communication interface.

Definition at line 140 of file LSM9DS1.hpp.

Referenced by configure(), LSM9DS1AccelGyro(), sample(), and suspend().

◆ agdatarate

float duds::hardware::devices::instruments::LSM9DS1AccelGyro::agdatarate
private

The currently configured sample rate.

Definition at line 157 of file LSM9DS1.hpp.

Referenced by configure().

◆ agdrval

std::int8_t duds::hardware::devices::instruments::LSM9DS1AccelGyro::agdrval
private

The data rate value given to the device.

Definition at line 165 of file LSM9DS1.hpp.

Referenced by configure().

◆ agsample

duds::hardware::interface::Conversation duds::hardware::devices::instruments::LSM9DS1AccelGyro::agsample
private

The conversation used to read in samples from the device.

Definition at line 149 of file LSM9DS1.hpp.

Referenced by configure(), and sample().

◆ cfg

Settings duds::hardware::devices::instruments::LSM9DS1AccelGyro::cfg
private

The current various configuration options.

Definition at line 161 of file LSM9DS1.hpp.

Referenced by accelerometerQuantity(), configure(), gyroscopeQuantity(), and sample().

◆ gyro

RawSample duds::hardware::devices::instruments::LSM9DS1AccelGyro::gyro
private

Definition at line 153 of file LSM9DS1.hpp.

Referenced by gyroscopeQuantity(), and sample().

◆ initialize

duds::hardware::interface::Conversation duds::hardware::devices::instruments::LSM9DS1AccelGyro::initialize
private

The conversation used to initialize the device.

It is created in init() and held for later use by resume().

Definition at line 145 of file LSM9DS1.hpp.

◆ statq

duds::hardware::interface::Conversation duds::hardware::devices::instruments::LSM9DS1AccelGyro::statq
private

Definition at line 149 of file LSM9DS1.hpp.

Referenced by configure(), and sample().


The documentation for this class was generated from the following files: