3-axis digital compass. More...
#include <sg_101020034_3AxisCompass.hpp>
Public Member Functions | |
virtual | ~ThreeAxisDigitalCompass (void) |
Destructor. More... | |
ThreeAxisDigitalCompass (const std::string &name="", const SG::GroveI2CDigital::I2CAddress addr=0) | |
Constructor. If not specified, the I2C address will be obtained using get_address_from_type(). More... | |
virtual ThreeAxisDigitalCompass & | reset (void) |
Reset the configuration to default values. More... | |
virtual ThreeAxisDigitalCompass & | set_mode (const EMode mode=EMode::kSingleMeasurement) |
Set the operating mode. More... | |
virtual EMode | get_mode (void) |
Get the operating mode. More... | |
virtual ThreeAxisDigitalCompass & | set_config (const EDataOutputRate output_rate, const EMeasurements measurements) |
Set the output rate and measurement bias. More... | |
virtual ThreeAxisDigitalCompass & | get_config (EDataOutputRate &output_rate, EMeasurements &measurements) |
Get the output rate and measurement bias. More... | |
virtual ThreeAxisDigitalCompass & | set_config (const EGain gain) |
Set the device gain. More... | |
virtual ThreeAxisDigitalCompass & | get_config (EGain &gain) |
Get the device gain. More... | |
virtual ThreeAxisDigitalCompass & | get_data (int16_t &x, int16_t &y, int16_t &z) |
Get the measurement data stored in the HMC5883. More... | |
virtual bool | get_single_measurement (int16_t &x, int16_t &y, int16_t &z, const size_t milliseconds_to_wait=1000) |
This sets the mode to EMode::kSingleMeasurement, waits for a new measurement to have been made, and returns the new data. More... | |
virtual bool | wait_for_significant_change (int16_t &x, int16_t &y, int16_t &z, const size_t milliseconds_to_wait=0, const int16_t delta=10) |
Repeatedly call get_single_measurement() until the data values are significantly different than the initial values for x , y , and z . More... | |
virtual ThreeAxisDigitalCompass & | get_status (bool ®ulator_enabled, bool &data_locked, bool &data_ready) |
Get status information. More... | |
virtual ThreeAxisDigitalCompass & | set_declination (const double declination) |
Set the magnetic declination to compensate for differences between magnetic north and geographic north. More... | |
virtual double | get_direction (void) |
Get the direction in radians. This uses the most recent values read by get_data(). More... | |
virtual double | get_heading (void) |
Get the compass heading in degrees, where east is 0 , north is 90 , west is 180 , and south is 270 . More... | |
double | gain_to_digital_resolution (const EGain gain) |
Convert the gain to digital resolution. More... | |
virtual bool | is_analog (void) const |
This is always false for GroveI2CDigital. More... | |
virtual bool | is_digital (void) const |
This is always true for GroveI2CDigital. More... | |
I2CAddress | get_address_from_type (void) const |
Get the address for this Grove type. More... | |
virtual uint8_t | read8 (const I2CRegister reg) |
Read a byte (8 bits) from the specificed register. More... | |
virtual uint16_t | read16 (const I2CRegister reg) |
Read a 16-bit word from the specified register. More... | |
virtual uint16_t | read12 (const I2CRegister reg) |
Read a 16-bit word from the specified register, but only keep the bottom 12 bits. More... | |
virtual I2CBlock | read_block (const I2CRegister reg) |
Read a consecutive block of bytes, anywhere between 1 and 32 bytes in length. More... | |
virtual GroveI2CDigital & | write_byte (const uint8_t value) |
Write a single byte to the I2C bus. More... | |
virtual GroveI2CDigital & | write_block (const I2CRegister reg, const I2CBlock &v) |
Write a consecutive block of bytes, anywhere between 1 and 32 bytes in length. More... | |
virtual GroveI2CDigital & | write_block (const I2CBlock &v) |
Write a consecutive block of bytes directly to the I2C file handle. More... | |
virtual bool | is_grove_uart (void) const |
This is always false for GroveI2C. More... | |
virtual bool | is_grove_i2c (void) const |
This is always true for GroveI2C. More... | |
virtual bool | is_grove_gpio (void) const |
This is always false for GroveI2C. More... | |
virtual uint32_t | get_sku (void) const |
Return a guess as to the Seeed SKU number based on the grove type. More... | |
virtual std::string | get_type_name (void) const |
Return a short text string representing the grove type. More... | |
virtual EGroveType | get_type (void) const |
Return the grove type. More... | |
virtual std::string | get_name (void) const |
Return the user-supplied name. More... | |
virtual std::string | get_description (void) const |
Return a multi-word 1-line description of this object. More... | |
virtual bool | is_regulator_enabled (void) |
Alias for the given field from get_status(). More... | |
virtual bool | is_data_locked (void) |
Alias for the given field from get_status(). More... | |
virtual bool | is_data_ready (void) |
Alias for the given field from get_status(). More... | |
virtual double | get_direction (const int16_t x, const int16_t y) |
Get the direction in radians. More... | |
virtual double | get_direction (const int16_t x, const int16_t y, const EGain gain) |
virtual double | get_heading (const int16_t x, const int16_t y) |
Get the compass heading in degrees, where east is 0 , north is 90 , west is 180 , and south is 270 . More... | |
virtual double | get_heading (const int16_t x, const int16_t y, const EGain gain) |
virtual GroveI2CDigital & | write8 (const I2CRegister reg, const uint8_t value) |
Write the given value to the specified register. More... | |
virtual GroveI2CDigital & | write16 (const I2CRegister reg, const uint16_t value) |
bool | operator== (const GroveBase &rhs) const |
Test object equality. More... | |
bool | operator!= (const GroveBase &rhs) const |
Test object equality. More... | |
Static Public Member Functions | |
static I2CBus | detect_i2c_bus_number (const bool force_detect=false, const int force_bus_number=-1) |
Detect the I2C bus to use to talk to Grove I2C devices. More... | |
static I2CAddress | get_address_from_type (const EGroveType &type) |
Get the default I2C address for a given type. More... | |
static std::string | to_string (const EMode mode) |
Convert the enum to a string. More... | |
static std::string | to_string (const EDataOutputRate output_rate) |
Convert the enum to a string. More... | |
static std::string | to_string (const EMeasurements measurements) |
Convert the enum to a string. More... | |
static std::string | to_string (const EGain gain) |
Convert the enum to a string. More... | |
Public Attributes | |
I2CBus | i2c_bus_number |
The bus number to use for I2C Grove twigs. More... | |
I2CAddress | i2c_address |
The I2C address used to communicate with the Grove device. More... | |
int | i2c_file_handle |
The file handle to /dev/i2c-* used to communicate with the Grove device. More... | |
EGroveType | grove_type |
Grove type. More... | |
std::string | grove_name |
User-supplied name. More... | |
Protected Attributes | |
EGain | most_recent_gain |
Most recent gain. More... | |
double | declination_degrees |
Magnetic declination. More... | |
double | declination_radians |
Magnetic declination. More... | |
int16_t | most_recent_x |
Most recent value read by get_data(). More... | |
int16_t | most_recent_y |
Most recent value read by get_data(). More... | |
int16_t | most_recent_z |
Most recent value read by get_data(). More... | |
3-axis digital compass.
Description | Image |
---|---|
Relative size of 3-axis digital compass. | |
3-axis digital compass connected to BBG. |
Connect the digital compass to the left-hand-side digital I2C interface. The I2C address for this device is 0x1e
.
Example source:
Example source:
|
inherited |
I2C addresses.
|
inherited |
Block of sequential bytes to read or write.
|
inherited |
I2C bus.
|
inherited |
I2C register.
|
strong |
The rate at which new data readings are done when running in continuous measurement mode.
|
strong |
Device gain.
These are specific to the HMC5883. The newer HMC5883L has different gain values which are slightly different, and which will also impact gain_to_digital_resolution(). Unfortunately, both the HMC5883 and HMC5883L identify themselves identically.
|
strong |
Measurement bias.
Enumerator | |
---|---|
kNormal | default value |
kPositiveBias | |
kNegativeBias |
|
strong |
Mode register (0x02).
|
strong |
I2C registers.
|
virtual |
Destructor.
SG::ThreeAxisDigitalCompass::ThreeAxisDigitalCompass | ( | const std::string & | name = "" , |
const SG::GroveI2CDigital::I2CAddress | addr = 0 |
||
) |
Constructor. If not specified, the I2C address will be obtained using get_address_from_type().
|
staticinherited |
Detect the I2C bus to use to talk to Grove I2C devices.
This is normally 1
or 2
. The detection consists of looking at /dev/i2c* devices.
[in] | force_detect | The detected bus number is usually remembered to prevent having to re-detect it every time a new GroveI2C object is instantiated. If force_detect is set to true , then this will force GroveI2C to ignore the previously cached bus number and re-detect the I2C bus. |
[in] | force_bus_number | If an explicit bus number should be used, then force_bus_number can be set to the correct bus value. This will prevent calls to detect_i2c_bus_number() from attempting to auto-detect the I2C bus. Setting the I2C bus number this way wont change existing GroveI2C objects that have already been instantiated. Only new objects will use the new bus number. The actual bus number used by specific objects is i2c_bus_number. |
std::system_error | if /dev cannot be opened. |
std::runtime_error | if the I2C bus cannot be found in /dev. |
Referenced by SG::GroveI2CDigital::is_digital().
double SG::ThreeAxisDigitalCompass::gain_to_digital_resolution | ( | const EGain | gain | ) |
Convert the gain to digital resolution.
References k0_9Ga, k1_2Ga, k1_9Ga, k2_5Ga, k4_0Ga, k4_6Ga, k5_5Ga, and k7_9Ga.
Referenced by get_direction().
|
staticinherited |
Get the default I2C address for a given type.
Note that several Grove types have multiple addresses. This only returns the first address.
References SG::k3AxisDigitalAccelerometer16g, SG::k3AxisDigitalAccelerometer1_5g, SG::k3AxisDigitalAccelerometer400g, SG::k3AxisDigitalCompass, SG::k3AxisDigitalGyro, SG::k6AxisAccelerometerAndCompassV1, SG::k6AxisAccelerometerAndCompassV2, SG::kBarometerHighAccuracy, SG::kBarometerSensor, SG::kBarometerSensorBMP180, SG::kDigitalInfraredTemperatureSensor, SG::kDigitalLightSensor, SG::kGestureV1, SG::kI2CADC, SG::kI2CColorSensor, SG::kI2CFMReceiver, SG::kI2CMotorDriverV10, SG::kI2CMotorDriverV12, SG::kIMU10DOF, SG::kIMU9DOFV1, SG::kIMU9DOFV2, SG::kLCDRGBBacklight, SG::kMultichannelGasSensor, SG::kNFCTag, SG::kOLEDDisplay0_96, SG::kOLEDDisplay1_12, SG::kQTouchSensor, SG::kRTC, SG::kTemperatureAndHumiditySensor, and SG::kTouchSensor.
|
inlineinherited |
Get the address for this Grove type.
References SG::GroveI2CDigital::get_address_from_type(), SG::GroveBase::get_type(), SG::GroveI2CDigital::read16(), and SG::GroveI2CDigital::read8().
Referenced by SG::GroveI2CDigital::get_address_from_type(), SG::GroveI2CDigital::GroveI2CDigital(), and SG::GroveI2CDigital::is_digital().
|
virtual |
Get the output rate and measurement bias.
Example source:
References k15Hz, kConfigRegA, kNormal, and SG::GroveI2CDigital::read8().
Referenced by compass().
|
virtual |
Get the device gain.
References k1_2Ga, kConfigRegB, and SG::GroveI2CDigital::read8().
|
virtual |
Get the measurement data stored in the HMC5883.
If the mode has been set to EMode::kContinuousMeasurement, then this call may obtain a new measurement (but also see EDataOutputRate).
Example source:
References kXMSB, most_recent_x, most_recent_y, most_recent_z, and SG::GroveI2CDigital::read8().
Referenced by get_single_measurement().
|
virtualinherited |
Return a multi-word 1-line description of this object.
References SG::demangle(), SG::GroveBase::get_name(), SG::GroveBase::get_sku(), SG::GroveBase::get_type_name(), SG::GroveBase::is_grove_gpio(), SG::GroveBase::is_grove_i2c(), SG::GroveBase::is_grove_uart(), and SG::BeagleBone::Detect::to_string().
Referenced by buzzer(), chainable_rgb_led(), common_oled(), SG::GroveBase::get_name(), SG::GroveI2CDigital::GroveI2CDigital(), SG::CommonOLED::set_display_bitmap(), SG::CommonOLED::set_orientation(), temperature(), variable_led(), and SG::GroveI2CDigital::write_block().
|
virtual |
Get the direction in radians. This uses the most recent values read by get_data().
Hmc5883l::direction()
in https://github.com/intel-iot-devkit/upm/blob/master/src/hmc5883l/hmc5883l.cxx References most_recent_gain, most_recent_x, and most_recent_y.
Referenced by compass(), get_direction(), and get_heading().
|
virtual |
Get the direction in radians.
Hmc5883l::direction()
in https://github.com/intel-iot-devkit/upm/blob/master/src/hmc5883l/hmc5883l.cxx References get_direction(), and most_recent_gain.
|
virtual |
Hmc5883l::direction()
in https://github.com/intel-iot-devkit/upm/blob/master/src/hmc5883l/hmc5883l.cxx References declination_radians, and gain_to_digital_resolution().
|
virtual |
Get the compass heading in degrees, where east is 0
, north is 90
, west is 180
, and south is 270
.
This uses the most recent values read by get_data().
Hmc5883l::heading()
in https://github.com/intel-iot-devkit/upm/blob/master/src/hmc5883l/hmc5883l.cxx References most_recent_gain, most_recent_x, and most_recent_y.
Referenced by compass(), and get_heading().
|
virtual |
Get the compass heading in degrees, where east is 0
, north is 90
, west is 180
, and south is 270
.
Hmc5883l::heading()
in https://github.com/intel-iot-devkit/upm/blob/master/src/hmc5883l/hmc5883l.cxx References get_heading(), and most_recent_gain.
|
virtual |
Hmc5883l::heading()
in https://github.com/intel-iot-devkit/upm/blob/master/src/hmc5883l/hmc5883l.cxx References get_direction().
|
virtual |
Get the operating mode.
Example source:
References kModeReg, and SG::GroveI2CDigital::read8().
Referenced by compass().
|
inlinevirtualinherited |
Return the user-supplied name.
References SG::GroveBase::get_description(), SG::GroveBase::grove_name, SG::GroveBase::is_grove_gpio(), SG::GroveBase::is_grove_i2c(), and SG::GroveBase::is_grove_uart().
Referenced by SG::GroveBase::get_description(), SG::GroveBase::operator=(), and SG::GroveBase::operator==().
|
virtual |
This sets the mode to EMode::kSingleMeasurement, waits for a new measurement to have been made, and returns the new data.
This method may be called multiple times, where each time it is called a new measurement will be made.
[out] | x | Measurement value from channel X . |
[out] | y | Measurement value from channel Y . |
[out] | z | Measurement value from channel Z . |
[in] | milliseconds_to_wait | The length of time to wait for data to be available. If set to zero, then get_single_measurement() will wait as long as necessary. It normally takes less than 10 milliseconds for data to be available. |
TRUE
if a reading was obtained. FALSE
if a timeout occurred. This can only happen when milliseconds_to_wait
is non-zero.Source example:
References get_data(), is_data_ready(), kSingleMeasurement, and set_mode().
Referenced by wait_for_significant_change().
|
inlinevirtualinherited |
Return a guess as to the Seeed SKU number based on the grove type.
References SG::get_sku_from_grove_type(), and SG::GroveBase::grove_type.
Referenced by SG::GroveBase::get_description().
|
virtual |
Get status information.
[out] | regulator_enabled | This is set when the internal voltage regulator is enabled. This is cleared when the internal regulator is disabled. |
[out] | data_locked | This is set when some but not all of the data output registers have been read. When this is set, the data output is locked and new data will not be stored. |
[out] | data_ready | This is set once data has been stored in the data registers, and cleared when the device initiates a write to the data output registers. |
References kStatusReg, and SG::GroveI2CDigital::read8().
Referenced by compass(), is_data_locked(), is_data_ready(), and is_regulator_enabled().
|
inlinevirtualinherited |
Return the grove type.
References SG::GroveBase::grove_type.
Referenced by SG::GroveI2CDigital::get_address_from_type(), SG::GroveBase::operator=(), and SG::GroveBase::operator==().
|
inlinevirtualinherited |
Return a short text string representing the grove type.
References SG::GroveBase::grove_type, and SG::to_string().
Referenced by SG::GroveBase::get_description().
|
inlinevirtualinherited |
This is always false
for GroveI2CDigital.
Implements SG::GroveI2C.
|
virtual |
Alias for the given field from get_status().
References get_status().
|
virtual |
Alias for the given field from get_status().
References get_status().
Referenced by get_single_measurement().
|
inlinevirtualinherited |
This is always true
for GroveI2CDigital.
Implements SG::GroveI2C.
References SG::GroveI2CDigital::detect_i2c_bus_number(), and SG::GroveI2CDigital::get_address_from_type().
|
inlinevirtualinherited |
This is always false
for GroveI2C.
Implements SG::GroveBase.
References SG::GroveI2C::is_analog(), and SG::GroveI2C::is_digital().
|
inlinevirtualinherited |
This is always true
for GroveI2C.
Implements SG::GroveBase.
|
inlinevirtualinherited |
This is always false
for GroveI2C.
Implements SG::GroveBase.
|
virtual |
Alias for the given field from get_status().
References get_status().
|
inlineinherited |
Test object equality.
References SG::GroveBase::operator==().
|
inherited |
Test object equality.
References SG::GroveBase::get_name(), and SG::GroveBase::get_type().
Referenced by SG::GroveBase::operator!=(), SG::Buzzer::operator==(), SG::TemperatureAndHumiditySensor::operator==(), SG::TemperatureSensor::operator==(), and SG::I2CADC::operator==().
|
inlinevirtualinherited |
Read a 16-bit word from the specified register, but only keep the bottom 12 bits.
Some devices such as the I2CADC return 12-bit values.
References SG::GroveI2CDigital::read16(), SG::GroveI2CDigital::read_block(), SG::GroveI2CDigital::write16(), SG::GroveI2CDigital::write8(), SG::GroveI2CDigital::write_block(), and SG::GroveI2CDigital::write_byte().
Referenced by SG::I2CADC::read12().
|
virtualinherited |
Read a 16-bit word from the specified register.
std::system_error | if the register cannot be read. |
Referenced by SG::GroveI2CDigital::get_address_from_type(), and SG::GroveI2CDigital::read12().
|
virtualinherited |
Read a byte (8 bits) from the specificed register.
std::system_error | if the register cannot be read. |
Referenced by SG::GroveI2CDigital::get_address_from_type(), get_config(), get_data(), get_mode(), get_status(), and SG::I2CADC::read8().
|
virtualinherited |
Read a consecutive block of bytes, anywhere between 1 and 32 bytes in length.
std::system_error | if the register cannot be read. |
Referenced by SG::GroveI2CDigital::read12().
|
virtual |
Reset the configuration to default values.
The default configuration is:
References k15Hz, k1_2Ga, kNormal, kSingleMeasurement, set_config(), and set_mode().
Referenced by compass().
|
virtual |
Set the output rate and measurement bias.
Example source:
References kConfigRegA, and SG::GroveI2CDigital::write8().
Referenced by compass(), and reset().
|
virtual |
Set the device gain.
Note that the very first measurement after a gain change maintains the same gain as the previous setting. The new gain setting is effective from the second measurement and on.
References kConfigRegB, most_recent_gain, and SG::GroveI2CDigital::write8().
|
virtual |
Set the magnetic declination to compensate for differences between magnetic north and geographic north.
This is specific to the geographic location where the device runs, and can be obtained from places such as http://www.magnetic-declination.com/ .
[in] | declination | Set the declination in decimal degrees format. For example, 15 degrees 54 minutes of declination would be specified as 15.9 (15 + 54/60). |
References declination_degrees, and declination_radians.
|
virtual |
Set the operating mode.
The default when first powered on is EMode::kSingleMeasurement which leads to EMode::kIdle after having stored the data. To get compass data to continuously update, set the mode to EMode::kContinuousMeasurement, or call get_single_measurement().
Example source:
References kContinuousMeasurement, kIdle, kModeReg, kSingleMeasurement, kSleep, SG::BeagleBone::Detect::to_string(), and SG::GroveI2CDigital::write8().
Referenced by compass(), get_single_measurement(), and reset().
|
static |
Convert the enum to a string.
References kContinuousMeasurement, kIdle, kSingleMeasurement, and kSleep.
Referenced by compass().
|
static |
|
static |
Convert the enum to a string.
References kNegativeBias, kNormal, and kPositiveBias.
|
static |
|
virtual |
Repeatedly call get_single_measurement() until the data values are significantly different than the initial values for x
, y
, and z
.
[in,out] | x | Measurement value from channel X . |
[in,out] | y | Measurement value from channel Y . |
[in,out] | z | Measurement value from channel Z . |
[in] | milliseconds_to_wait | The length of time to wait for a signficant change. If set to zero, then wait_for_significant_change() will wait forever. |
[in] | delta | Determines how different X , Y , or Z must be from their original values for the difference to be considered "significant". |
TRUE
if a significantly different reading was obtained. FALSE
if a timeout occurred. This can only happen when milliseconds_to_wait
is non-zero. References get_single_measurement().
Referenced by compass().
|
virtualinherited |
std::system_error | if the value cannot be written. |
Referenced by SG::GroveI2CDigital::read12(), and SG::I2CADC::write16().
|
virtualinherited |
Write the given value to the specified register.
std::system_error | if the value cannot be written. |
Referenced by SG::GroveI2CDigital::read12(), set_config(), set_mode(), and SG::I2CADC::write8().
|
virtualinherited |
Write a consecutive block of bytes, anywhere between 1 and 32 bytes in length.
std::length_error | if the block is too long to write. |
std::system_error | if the block failed to write. |
References SG::GroveBase::get_description(), SG::GroveI2CDigital::i2c_address, and SG::BeagleBone::Detect::to_string().
Referenced by SG::CommonOLED::flood(), SG::GroveI2CDigital::read12(), SG::OLED096::reset(), SG::CommonOLED::send_command(), SG::CommonOLED::set_display_bitmap(), SG::CommonOLED::set_orientation(), and SG::CommonOLED::show().
|
virtualinherited |
Write a consecutive block of bytes directly to the I2C file handle.
std::system_error | if the block failed to write. |
References SG::GroveBase::get_description(), SG::GroveI2CDigital::i2c_address, SG::GroveI2CDigital::i2c_file_handle, and SG::BeagleBone::Detect::to_string().
|
virtualinherited |
Write a single byte to the I2C bus.
std::system_error | if the value cannot be writen. |
Referenced by SG::OLED096::all_off_display(), SG::OLED096::all_on_display(), SG::OLED096::invert_display(), SG::OLED096::normal_display(), SG::GroveI2CDigital::read12(), and SG::CommonOLED::set_display_bitmap().
|
protected |
Magnetic declination.
Referenced by set_declination().
|
protected |
Magnetic declination.
Referenced by get_direction(), and set_declination().
|
inherited |
User-supplied name.
Referenced by SG::GroveBase::get_name(), and SG::GroveBase::operator=().
|
inherited |
Grove type.
Referenced by SG::GroveBase::get_sku(), SG::GroveBase::get_type(), SG::GroveBase::get_type_name(), and SG::GroveBase::operator=().
|
inherited |
The I2C address used to communicate with the Grove device.
Referenced by SG::GroveI2CDigital::GroveI2CDigital(), SG::I2CADC::operator==(), and SG::GroveI2CDigital::write_block().
|
inherited |
The bus number to use for I2C Grove twigs.
The exposed I2C bus is usually 1
or 2
. This is normally auto-detected by detect_i2c_bus_number() called by the constructor, and doesn't need to be manually set.
Referenced by SG::GroveI2CDigital::GroveI2CDigital().
|
inherited |
The file handle to /dev/i2c-* used to communicate with the Grove device.
Referenced by SG::GroveI2CDigital::GroveI2CDigital(), SG::GroveI2CDigital::write_block(), and SG::GroveI2CDigital::~GroveI2CDigital().
|
protected |
Most recent gain.
Referenced by get_direction(), get_heading(), and set_config().
|
protected |
Most recent value read by get_data().
Referenced by get_data(), get_direction(), and get_heading().
|
protected |
Most recent value read by get_data().
Referenced by get_data(), get_direction(), and get_heading().
|
protected |
Most recent value read by get_data().
Referenced by get_data().