get_frs() and get_meta_data() features
This commit is contained in:
parent
2d20a89b07
commit
71e276e76a
|
|
@ -3,23 +3,19 @@
|
||||||
* @author Myles Parfeniuk
|
* @author Myles Parfeniuk
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// standard library includes
|
// standard library includes
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <cstring>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
// esp-idf includes
|
// esp-idf includes
|
||||||
#include <esp_rom_gpio.h>
|
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
#include <freertos/event_groups.h>
|
#include <freertos/event_groups.h>
|
||||||
#include <freertos/queue.h>
|
#include <freertos/queue.h>
|
||||||
#include <freertos/semphr.h>
|
#include <freertos/semphr.h>
|
||||||
#include <rom/ets_sys.h>
|
|
||||||
|
|
||||||
// in-house includes
|
// in-house includes
|
||||||
#include "BNO08x_global_types.hpp"
|
#include "BNO08x_global_types.hpp"
|
||||||
|
|
@ -74,7 +70,7 @@ class BNO08x
|
||||||
bool on();
|
bool on();
|
||||||
bool sleep();
|
bool sleep();
|
||||||
|
|
||||||
bool get_frs(BNO08xFRSID frs_ID, uint32_t* data, uint16_t* rx_data_sz);
|
bool get_frs(uint16_t frs_ID, uint32_t (&data)[16], uint16_t& rx_data_sz);
|
||||||
|
|
||||||
bool data_available();
|
bool data_available();
|
||||||
void register_cb(std::function<void(void)> cb_fxn);
|
void register_cb(std::function<void(void)> cb_fxn);
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,8 @@ class BNO08xRpt
|
||||||
bool has_new_data();
|
bool has_new_data();
|
||||||
bool flush();
|
bool flush();
|
||||||
bool get_sample_counts(bno08x_sample_counts_t& sample_counts);
|
bool get_sample_counts(bno08x_sample_counts_t& sample_counts);
|
||||||
bool clear_sample_counts();
|
bool clear_sample_counts();
|
||||||
|
bool get_meta_data(bno08x_meta_data_t& meta_data);
|
||||||
virtual void update_data(sh2_SensorValue_t* sensor_val) = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BNO08x* imu; ///< Pointer to BNO08x object for enable ,disable, and update operations.
|
BNO08x* imu; ///< Pointer to BNO08x object for enable ,disable, and update operations.
|
||||||
|
|
@ -40,6 +39,8 @@ class BNO08xRpt
|
||||||
uint32_t rpt_bit; ///< Respective enable and data bit for report in BNO08x::evt_grp_report_en and BNO08x::evt_grp_report_data
|
uint32_t rpt_bit; ///< Respective enable and data bit for report in BNO08x::evt_grp_report_en and BNO08x::evt_grp_report_data
|
||||||
uint32_t period_us; ///< The period/interval of the report in microseconds.
|
uint32_t period_us; ///< The period/interval of the report in microseconds.
|
||||||
|
|
||||||
|
virtual void update_data(sh2_SensorValue_t* sensor_val) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief BNO08xRpt report constructor.
|
* @brief BNO08xRpt report constructor.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,18 @@
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// standard library includes
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
#include <driver/gpio.h>
|
#include <driver/gpio.h>
|
||||||
#include <driver/spi_common.h>
|
#include <driver/spi_common.h>
|
||||||
#include <driver/spi_master.h>
|
#include <driver/spi_master.h>
|
||||||
|
|
||||||
|
// third-party includes
|
||||||
#include "sh2_SensorValue.h"
|
#include "sh2_SensorValue.h"
|
||||||
|
|
||||||
// macros for bno08x_tap_detector_t
|
// macros for bno08x_tap_detector_t
|
||||||
|
|
@ -46,31 +54,6 @@ enum class BNO08xAccuracy
|
||||||
};
|
};
|
||||||
using IMUAccuracy = BNO08xAccuracy; // legacy version compatibility
|
using IMUAccuracy = BNO08xAccuracy; // legacy version compatibility
|
||||||
|
|
||||||
enum class BNO08xFRSID
|
|
||||||
{
|
|
||||||
RawAccelerometer = 0xE301,
|
|
||||||
Accelerometer = 0xE302,
|
|
||||||
LinearAcceleration = 0xE303,
|
|
||||||
Gravity = 0xE304,
|
|
||||||
RawGyroscope = 0xE305,
|
|
||||||
CalGyro = 0xE306,
|
|
||||||
UncalGyro = 0xE307,
|
|
||||||
RawMagnetometer = 0xE308,
|
|
||||||
CalMagnetometer = 0xE309,
|
|
||||||
UncalMagnetometer = 0xE30A,
|
|
||||||
RV = 0xE30B,
|
|
||||||
RVGame = 0xE30C,
|
|
||||||
RVGeomagnetic = 0xE30D,
|
|
||||||
TapDetector = 0xE313,
|
|
||||||
StepCounter = 0xE315,
|
|
||||||
StabilityClassifier = 0xE317,
|
|
||||||
ShakeDetector = 0xE318,
|
|
||||||
ActivityClassifier = 0xE31C,
|
|
||||||
RVARVRStabilizedRotation = 0xE322,
|
|
||||||
RVARVRStabilizedGame = 0xE323,
|
|
||||||
RVGyroIntegrated = 0xE324,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// @brief BNO08xActivity Classifier enable bits passed to enable_activity_classifier()
|
/// @brief BNO08xActivity Classifier enable bits passed to enable_activity_classifier()
|
||||||
enum class BNO08xActivityEnable
|
enum class BNO08xActivityEnable
|
||||||
{
|
{
|
||||||
|
|
@ -542,34 +525,6 @@ typedef struct bno08x_shake_detector_t
|
||||||
|
|
||||||
} bno08x_shake_detector_t;
|
} bno08x_shake_detector_t;
|
||||||
|
|
||||||
/// @brief Struct to represent sample counts, returned from BNO08xRpt::get_sample_counts()
|
|
||||||
typedef struct bno08x_sample_counts_t
|
|
||||||
{
|
|
||||||
uint32_t offered; ///< Number of samples produced by underlying data source.
|
|
||||||
uint32_t on; ///< Number of "offered" samples while this sensor was requested by host.
|
|
||||||
uint32_t accepted; ///< Number of "on" samples that passed decimation filter.
|
|
||||||
uint32_t attempted; ///< Number of "accepted" samples that passed threshold requirements and had transmission to the host attempted.
|
|
||||||
|
|
||||||
bno08x_sample_counts_t()
|
|
||||||
: offered(0UL)
|
|
||||||
, on(0UL)
|
|
||||||
, accepted(0UL)
|
|
||||||
, attempted(0UL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// conversion from sh2_PersonalActivityClassifier_t
|
|
||||||
bno08x_sample_counts_t& operator=(const sh2_Counts_t& source)
|
|
||||||
{
|
|
||||||
this->offered = source.offered;
|
|
||||||
this->on = source.on;
|
|
||||||
this->accepted = source.accepted;
|
|
||||||
this->attempted = source.attempted;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
} bno08x_sample_counts_t;
|
|
||||||
|
|
||||||
/// @brief Struct to represent acceleration data from acceleration, linear acceleration, and gravity reports.
|
/// @brief Struct to represent acceleration data from acceleration, linear acceleration, and gravity reports.
|
||||||
typedef struct bno08x_accel_t
|
typedef struct bno08x_accel_t
|
||||||
{
|
{
|
||||||
|
|
@ -730,4 +685,104 @@ typedef struct bno08x_stability_classifier_t
|
||||||
|
|
||||||
} bno08x_stability_classifier_t;
|
} bno08x_stability_classifier_t;
|
||||||
|
|
||||||
|
/// @brief Struct to represent sample counts, returned from BNO08xRpt::get_sample_counts()
|
||||||
|
typedef struct bno08x_sample_counts_t
|
||||||
|
{
|
||||||
|
uint32_t offered; ///< Number of samples produced by underlying data source.
|
||||||
|
uint32_t on; ///< Number of "offered" samples while this sensor was requested by host.
|
||||||
|
uint32_t accepted; ///< Number of "on" samples that passed decimation filter.
|
||||||
|
uint32_t attempted; ///< Number of "accepted" samples that passed threshold requirements and had transmission to the host attempted.
|
||||||
|
|
||||||
|
bno08x_sample_counts_t()
|
||||||
|
: offered(0UL)
|
||||||
|
, on(0UL)
|
||||||
|
, accepted(0UL)
|
||||||
|
, attempted(0UL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// conversion from sh2_PersonalActivityClassifier_t
|
||||||
|
bno08x_sample_counts_t& operator=(const sh2_Counts_t& source)
|
||||||
|
{
|
||||||
|
this->offered = source.offered;
|
||||||
|
this->on = source.on;
|
||||||
|
this->accepted = source.accepted;
|
||||||
|
this->attempted = source.attempted;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
} bno08x_sample_counts_t;
|
||||||
|
|
||||||
|
/// @brief Struct to represent sensor/report meta data, returned from BNO08xRpt::get_meta_data()
|
||||||
|
typedef struct bno08x_meta_data_t
|
||||||
|
{
|
||||||
|
uint8_t me_version; ///< Motion Engine Version
|
||||||
|
uint8_t mh_version; ///< Motion Hub Version
|
||||||
|
uint8_t sh_version; ///< SensorHub Version
|
||||||
|
uint32_t range; ///< Same units as sensor reports
|
||||||
|
uint32_t resolution; ///< Same units as sensor reports
|
||||||
|
uint16_t revision; ///< Metadata record format revision
|
||||||
|
uint16_t power_mA; ///< [mA] Fixed point 16Q10 format
|
||||||
|
uint32_t min_period_us; ///< [uS] min period to use with enable_report
|
||||||
|
uint32_t max_period_us; ///< [uS] max period to use with enable_report
|
||||||
|
uint32_t fifo_reserved; ///< (Unused)
|
||||||
|
uint32_t fifo_max; ///< (Unused)
|
||||||
|
uint32_t batch_buffer_bytes; ///< (Unused)
|
||||||
|
uint16_t q_point_1; ///< q point for sensor values
|
||||||
|
uint16_t q_point_2; ///< q point for accuracy or bias fields
|
||||||
|
uint16_t q_point_3; ///< q point for sensor data change sensitivity
|
||||||
|
uint32_t vendor_id_len; ///< [bytes]
|
||||||
|
char vendor_ID[48]; ///< Vendor name and part number
|
||||||
|
uint32_t sensor_specific_len; ///< [bytes]
|
||||||
|
uint8_t sensor_specific[48]; ///< See SH-2 Reference Manual
|
||||||
|
|
||||||
|
// Default constructor
|
||||||
|
bno08x_meta_data_t()
|
||||||
|
: me_version(0)
|
||||||
|
, mh_version(0)
|
||||||
|
, sh_version(0)
|
||||||
|
, range(0)
|
||||||
|
, resolution(0)
|
||||||
|
, revision(0)
|
||||||
|
, power_mA(0)
|
||||||
|
, min_period_us(0)
|
||||||
|
, max_period_us(0)
|
||||||
|
, fifo_reserved(0)
|
||||||
|
, fifo_max(0)
|
||||||
|
, batch_buffer_bytes(0)
|
||||||
|
, q_point_1(0)
|
||||||
|
, q_point_2(0)
|
||||||
|
, q_point_3(0)
|
||||||
|
, vendor_id_len(0)
|
||||||
|
, sensor_specific_len(0)
|
||||||
|
{
|
||||||
|
memset(vendor_ID, 0, sizeof(vendor_ID));
|
||||||
|
memset(sensor_specific, 0, sizeof(sensor_specific));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Conversion constructor from sh2_SensorMetadata_t
|
||||||
|
bno08x_meta_data_t(const sh2_SensorMetadata_t& src)
|
||||||
|
{
|
||||||
|
me_version = src.meVersion;
|
||||||
|
mh_version = src.mhVersion;
|
||||||
|
sh_version = src.shVersion;
|
||||||
|
range = src.range;
|
||||||
|
resolution = src.resolution;
|
||||||
|
revision = src.revision;
|
||||||
|
power_mA = src.power_mA;
|
||||||
|
min_period_us = src.minPeriod_uS;
|
||||||
|
max_period_us = src.maxPeriod_uS;
|
||||||
|
fifo_reserved = src.fifoReserved;
|
||||||
|
fifo_max = src.fifoMax;
|
||||||
|
batch_buffer_bytes = src.batchBufferBytes;
|
||||||
|
q_point_1 = src.qPoint1;
|
||||||
|
q_point_2 = src.qPoint2;
|
||||||
|
q_point_3 = src.qPoint3;
|
||||||
|
vendor_id_len = src.vendorIdLen;
|
||||||
|
sensor_specific_len = src.sensorSpecificLen;
|
||||||
|
memcpy(vendor_ID, src.vendorId, vendor_id_len);
|
||||||
|
memcpy(sensor_specific, src.sensorSpecific, sensor_specific_len);
|
||||||
|
}
|
||||||
|
} bno08x_meta_data_t;
|
||||||
|
|
||||||
typedef bno08x_config_t imu_config_t; // legacy version compatibility
|
typedef bno08x_config_t imu_config_t; // legacy version compatibility
|
||||||
|
|
@ -126,7 +126,7 @@ bool BNO08x::initialize()
|
||||||
if (init_tasks() != ESP_OK)
|
if (init_tasks() != ESP_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#ifdef CONFIG_ESP32_BNO08x_LOG_STATEMENTS
|
#ifdef CONFIG_ESP32_BNO08x_LOG_STATEMENTS
|
||||||
ESP_LOGI(TAG, "Successfully initialized....");
|
ESP_LOGI(TAG, "Successfully initialized....");
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1196,12 +1196,23 @@ bool BNO08x::sleep()
|
||||||
return (op_success == SH2_OK);
|
return (op_success == SH2_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BNO08x::get_frs(BNO08xFRSID frs_ID, uint32_t* data, uint16_t* rx_data_sz)
|
/**
|
||||||
|
* @brief Retrieves a record from flash record system (if your goal is to retrieve meta data use the BNO08xRpt:get_meta_data() method instead)
|
||||||
|
*
|
||||||
|
* For more details on returned and data and frs_ID see ref. manual 6.3.7 & 4.3
|
||||||
|
*
|
||||||
|
* @param frs_ID The ID of the desired record to retrieve from flash.
|
||||||
|
* @param data Buffer of 16 uint32_t to store retrieved data.
|
||||||
|
* @param rx_data_sz Reference to store number of 32 bit words retrieved from flash.
|
||||||
|
*
|
||||||
|
* @return True if get flash record system operation succeeded.
|
||||||
|
*/
|
||||||
|
bool BNO08x::get_frs(uint16_t frs_ID, uint32_t (&data)[16], uint16_t& rx_data_sz)
|
||||||
{
|
{
|
||||||
int op_success = SH2_ERR;
|
int op_success = SH2_ERR;
|
||||||
|
|
||||||
lock_sh2_HAL();
|
lock_sh2_HAL();
|
||||||
op_success = sh2_getFrs(static_cast<uint16_t>(frs_ID), data, rx_data_sz);
|
op_success = sh2_getFrs(frs_ID, data, &rx_data_sz);
|
||||||
unlock_sh2_HAL();
|
unlock_sh2_HAL();
|
||||||
|
|
||||||
return (op_success == SH2_OK);
|
return (op_success == SH2_OK);
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,30 @@ bool BNO08xRpt::clear_sample_counts()
|
||||||
success = sh2_clearCounts(ID);
|
success = sh2_clearCounts(ID);
|
||||||
imu->unlock_sh2_HAL();
|
imu->unlock_sh2_HAL();
|
||||||
|
|
||||||
return (success != SH2_OK) ? false : true;
|
return (success == SH2_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Retrieves meta data for this sensor/report by reading respective record in FRS (flash record system).
|
||||||
|
*
|
||||||
|
* Can be used to retrieve the minimum period, maximum period, actual Q points, resolution, and other info for a given sensor.
|
||||||
|
*
|
||||||
|
* @return True clear get meta data operation succeeded.
|
||||||
|
*/
|
||||||
|
bool BNO08xRpt::get_meta_data(bno08x_meta_data_t& meta_data)
|
||||||
|
{
|
||||||
|
int success = SH2_OK;
|
||||||
|
|
||||||
|
sh2_SensorMetadata_t sensor_meta_data;
|
||||||
|
|
||||||
|
imu->lock_sh2_HAL();
|
||||||
|
success = sh2_getMetadata(ID, &sensor_meta_data);
|
||||||
|
imu->unlock_sh2_HAL();
|
||||||
|
|
||||||
|
if (success == SH2_OK)
|
||||||
|
meta_data = sensor_meta_data;
|
||||||
|
|
||||||
|
return (success == SH2_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue