esp32_BNO08x 1.4
C++ BNO08x IMU driver component for esp-idf.
BNO08x Class Reference

BNO08x IMU driver class. More...

#include <BNO08x.hpp>

Collaboration diagram for BNO08x:

Classes

struct  bno08x_reports_t
 Contains report implementations. More...
 

Public Types

typedef struct BNO08x::bno08x_reports_t bno08x_reports_t
 Contains report implementations. More...
 

Public Member Functions

 BNO08x (bno08x_config_t imu_config=bno08x_config_t())
 BNO08x imu constructor. More...
 
 ~BNO08x ()
 BNO08x imu deconstructor. More...
 
bool initialize ()
 Initializes BNO08x sensor. More...
 
bool hard_reset ()
 Hard resets BNO08x device. More...
 
bool soft_reset ()
 Soft resets BNO08x device by sending RESET (1) command on "device" channel. More...
 
bool disable_all_reports ()
 Disables all currently enabled reports. More...
 
BNO08xResetReason get_reset_reason ()
 Returns reason for previous reset via product ID report. More...
 
bool on ()
 Places BNO08x device in on state by sending ON (2) command on "device" channel. More...
 
bool sleep ()
 Places BNO08x device in sleep state by sending SLEEP (3) command on "device" channel. More...
 
bool dynamic_calibration_enable (BNO08xCalSel sensor)
 Starts simple calibration, see ref. manual 6.4.10.1. More...
 
bool dynamic_calibration_disable (BNO08xCalSel sensor)
 Disables dynamic/motion engine calibration for specified sensor(s), see ref. manual 6.4.6.1. More...
 
bool dynamic_calibration_autosave_enable ()
 Enables the automatic saving of dynamic/ME calibration data to BNO08x internal flash See ref manual 6.4.7.1. More...
 
bool dynamic_calibration_autosave_disable ()
 Disables the automatic saving of dynamic/ME calibration data to BNO08x internal flash See ref manual 6.4.7.1. More...
 
bool dynamic_calibration_save ()
 Saves dynamic/motion engine calibration data to BNO08x internal flash immediately. See ref manual 6.4.5.1. More...
 
bool dynamic_calibration_data_clear_ram ()
 Clears dynamic/motion engine calibration data from ram and resets BNO08x device. See ref manual 6.4.9.1. More...
 
bool dynamic_calibration_data_delete ()
 Deletes dynamic calibration data from BNO08x internal flash and resets the device. Follows the steps outlined in ref. manual 6.4.9. More...
 
bool dynamic_calibration_run_routine ()
 Example calibration routine using dynamic/ME calibration commands. More...
 
bool set_system_orientation (float w, float x, float y, float z)
 Sets the system orientation of the BNO08x device and persist it in flash (FRS). More...
 
bool get_system_orientation (float &w, float &x, float &y, float &z)
 Retrieves the system orientation of the BNO08x device and converts to float. More...
 
bool get_frs (BNO08xFrsID frs_ID, uint32_t(&data)[16], uint16_t &rx_data_sz)
 Retrieves a record from flash record system (if your goal is to retrieve sensor specific meta data use the BNO08xRpt:get_meta_data() method instead) More...
 
bool write_frs (BNO08xFrsID frs_ID, uint32_t *data, const uint16_t tx_data_sz)
 Writes a record to flash record system. More...
 
sh2_ProductIds_t get_product_IDs ()
 Returns product ID info sent by IMU at initialization. More...
 
bool data_available ()
 Polls for new data/report to become available. More...
 
bool register_cb (std::function< void(void)> cb_fxn)
 Registers a callback to execute when new data from a report is received. More...
 
bool register_cb (std::function< void(uint8_t report_ID)> cb_fxn)
 Registers a callback to execute when new data from a report is received, overloaded with callback param for most recent report ID. More...
 
void print_product_ids ()
 Prints product IDs received at initialization. More...
 
void print_system_orientation ()
 Retrieves and prints system orientation. More...
 

Public Attributes

bno08x_reports_t rpt
 

Static Public Attributes

static constexpr float SQRT2OVER2 = 0.7071067811865476f
 

Friends

class BNO08xSH2HAL
 
class BNO08xTestHelper
 

Detailed Description

BNO08x IMU driver class.

Member Typedef Documentation

◆ bno08x_reports_t

Contains report implementations.

Constructor & Destructor Documentation

◆ BNO08x()

BNO08x::BNO08x ( bno08x_config_t  imu_config = bno08x_config_t())

BNO08x imu constructor.

Construct a BNO08x object for managing a BNO08x sensor.

Parameters
imu_configConfiguration settings (optional), default settings can be seen in bno08x_config_t
Returns
void, nothing to return

◆ ~BNO08x()

BNO08x::~BNO08x ( )

BNO08x imu deconstructor.

Deconstructs a BNO08x object and releases any utilized resources.

Returns
void, nothing to return.

Member Function Documentation

◆ data_available()

bool BNO08x::data_available ( )

Polls for new data/report to become available.

Returns
True if new data/report became available before DATA_AVAILABLE_TIMEOUT_MS.
Here is the caller graph for this function:

◆ disable_all_reports()

bool BNO08x::disable_all_reports ( )

Disables all currently enabled reports.

Returns
True if all currently enabled reports were disabled successfully.
Here is the caller graph for this function:

◆ dynamic_calibration_autosave_disable()

bool BNO08x::dynamic_calibration_autosave_disable ( )

Disables the automatic saving of dynamic/ME calibration data to BNO08x internal flash See ref manual 6.4.7.1.

Returns
True if dynamic/ME calibration autosave data enable succeeded.

◆ dynamic_calibration_autosave_enable()

bool BNO08x::dynamic_calibration_autosave_enable ( )

Enables the automatic saving of dynamic/ME calibration data to BNO08x internal flash See ref manual 6.4.7.1.

Returns
True if dynamic/ME calibration autosave data enable succeeded.

◆ dynamic_calibration_data_clear_ram()

bool BNO08x::dynamic_calibration_data_clear_ram ( )

Clears dynamic/motion engine calibration data from ram and resets BNO08x device. See ref manual 6.4.9.1.

Returns
True if save dynamic/ME calibration data succeeded.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dynamic_calibration_data_delete()

bool BNO08x::dynamic_calibration_data_delete ( )

Deletes dynamic calibration data from BNO08x internal flash and resets the device. Follows the steps outlined in ref. manual 6.4.9.

Returns
True if delete dynamic calibration data operation succeeded.
Here is the call graph for this function:

◆ dynamic_calibration_disable()

bool BNO08x::dynamic_calibration_disable ( BNO08xCalSel  sensor)

Disables dynamic/motion engine calibration for specified sensor(s), see ref. manual 6.4.6.1.

Parameters
sensorThe sensor(s) to disable dynamic/ME calibration for.
Returns
True if disable dynamic/ME calibration succeeded.
Here is the caller graph for this function:

◆ dynamic_calibration_enable()

bool BNO08x::dynamic_calibration_enable ( BNO08xCalSel  sensor)

Starts simple calibration, see ref. manual 6.4.10.1.

Parameters
period_usThis interval should be set to whatever rate the sensor hub is expected to run at after calibration.

After the calibration is started, the IMU should be rotated 180 degrees. After the IMU has been rotated call calibration_end(). See ref. manual 6.4.10 for more detailed instructions.

Returns
True if start simple calibration operation succeeded.

Ends turn-table calibration, see ref. manual 6.4.10.2

Parameters
statusReturned status bits indicating result of turntable calibration.
Returns
True if enable start turn-table calibration operation succeeded.

Enables dynamic/motion engine calibration for specified sensor(s), see ref. manual 6.4.6.1

Parameters
sensorThe sensor(s) to enable dynamic/ME calibration for.
Returns
True if enable dynamic/ME calibration succeeded.
Here is the caller graph for this function:

◆ dynamic_calibration_run_routine()

bool BNO08x::dynamic_calibration_run_routine ( )

Example calibration routine using dynamic/ME calibration commands.

Routine does the following:alignas

1) disables all enabled reports 2) sends a command to enable dynamic/motion engine calibration for all possible options (SH2_CAL_ACCEL | SH2_CAL_GYRO | SH2_CAL_MAG | SH2_CAL_PLANAR) 3) enables game rotation vector reports and calibrated magnetic field reports 4) moving window average for accuracy received through reports 5) deems calibration accuracy threshold met when magf accuracy avg is >=2 (MED) and quat accuracy avg >=3 (HIGH) for longer than 5 seconds 6) sends command to save dynamic calibration data 7) disables all enabled reports

Note the DCD commands don't have to be used this way, this is just an example, but the dynamic_calibration_autosave_enable() allows calibration to be run and saved constantly even while data is used for other operations.

Returns
True if calibration routine succeeded.
Here is the call graph for this function:

◆ dynamic_calibration_save()

bool BNO08x::dynamic_calibration_save ( )

Saves dynamic/motion engine calibration data to BNO08x internal flash immediately. See ref manual 6.4.5.1.

Returns
True if save dynamic/ME calibration data succeeded.
Here is the caller graph for this function:

◆ get_frs()

bool BNO08x::get_frs ( BNO08xFrsID  frs_ID,
uint32_t(&)  data[16],
uint16_t &  rx_data_sz 
)

Retrieves a record from flash record system (if your goal is to retrieve sensor specific meta data use the BNO08xRpt:get_meta_data() method instead)

For more details on returned and data and frs_IDs see ref. manual 6.3.7 & 4.3

Parameters
frs_IDThe ID of the desired record to retrieve from flash.
dataBuffer of 16 uint32_t to store retrieved data.
rx_data_szReference to store number of 32 bit words retrieved from flash.
Returns
True if get flash record system operation succeeded.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_product_IDs()

sh2_ProductIds_t BNO08x::get_product_IDs ( )

Returns product ID info sent by IMU at initialization.

Returns
The product ID info returned at initialization.

◆ get_reset_reason()

BNO08xResetReason BNO08x::get_reset_reason ( )

Returns reason for previous reset via product ID report.

Returns
Enum object containing reset reason, BNO08xResetReason::UNDEFINED if failure.
Here is the caller graph for this function:

◆ get_system_orientation()

bool BNO08x::get_system_orientation ( float &  Qw,
float &  Qx,
float &  Qy,
float &  Qz 
)

Retrieves the system orientation of the BNO08x device and converts to float.

Parameters
QwReference to save real component of mapping quaternion.
QxReference to save X (i) component of mapping quaternion.
QyReference to save Y (j) component of mapping quaternion.
QzReference to save Z (k) component of mapping quaternion.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hard_reset()

bool BNO08x::hard_reset ( )

Hard resets BNO08x device.

Returns
True if reset was success.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize()

bool BNO08x::initialize ( )

Initializes BNO08x sensor.

Resets sensor and goes through initialization process. Configures GPIO, required ISRs, and launches two tasks, one to manage SPI transactions, another to process any received data.

Returns
True if initialization was success, false if otherwise.

◆ on()

bool BNO08x::on ( )

Places BNO08x device in on state by sending ON (2) command on "device" channel.

Returns
True if on operation succeeded.

◆ print_product_ids()

void BNO08x::print_product_ids ( )

Prints product IDs received at initialization.

Returns
void, nothing to return

◆ print_system_orientation()

void BNO08x::print_system_orientation ( )

Retrieves and prints system orientation.

Returns
void, nothing to return
Here is the call graph for this function:

◆ register_cb() [1/2]

bool BNO08x::register_cb ( std::function< void(uint8_t report_ID)>  cb_fxn)

Registers a callback to execute when new data from a report is received, overloaded with callback param for most recent report ID.

Parameters
cb_fxnPointer to the call-back function should be of void return type with single input param of uint8_t for most recent report ID.
Returns
void, nothing to return

◆ register_cb() [2/2]

bool BNO08x::register_cb ( std::function< void(void)>  cb_fxn)

Registers a callback to execute when new data from a report is received.

Parameters
cb_fxnPointer to the call-back function should be of void return type void input param.
Returns
void, nothing to return

◆ set_system_orientation()

bool BNO08x::set_system_orientation ( float  Qw,
float  Qx,
float  Qy,
float  Qz 
)

Sets the system orientation of the BNO08x device and persist it in flash (FRS).

Note
Datasheet Figure 4.3 for reference of physical mounting position relative to mapping quaternion.
Use SQRT2OVER2 as a constant for sqrt(2)/2
that a reset is required to apply changes.
This configuration seems only to work if reports are already enabled. e.g. set .rpt.rv.enable(PERIOD) prior this call
Parameters
QwReal component of mapping quaternion.
QxX (i) component of mapping quaternion.
QyY (j) component of mapping quaternion.
QzZ (k) component of mapping quaternion.

◆ sleep()

bool BNO08x::sleep ( )

Places BNO08x device in sleep state by sending SLEEP (3) command on "device" channel.

Returns
True if sleep operation succeeded.

◆ soft_reset()

bool BNO08x::soft_reset ( )

Soft resets BNO08x device by sending RESET (1) command on "device" channel.

Returns
True if soft reset operation succeeded.
Here is the call graph for this function:

◆ write_frs()

bool BNO08x::write_frs ( BNO08xFrsID  frs_ID,
uint32_t *  data,
const uint16_t  tx_data_sz 
)

Writes a record to flash record system.

For more details on flash records and frs_IDs see ref. manual 6.3.6 & 4.3

Parameters
frs_IDThe ID of the desired to write to flash.
dataBuffer of 16 uint32_t to store data to send.
tx_data_szLength of data, amount of 32 bit words to write to flash.
Returns
True if get flash record system operation succeeded.
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ BNO08xSH2HAL

friend class BNO08xSH2HAL
friend

◆ BNO08xTestHelper

friend class BNO08xTestHelper
friend

Member Data Documentation

◆ rpt

bno08x_reports_t BNO08x::rpt

◆ SQRT2OVER2

constexpr float BNO08x::SQRT2OVER2 = 0.7071067811865476f
staticconstexpr

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