2024-11-27 23:54:47 +00:00
|
|
|
/**
|
|
|
|
|
* @file BNO08xRptRVGeneric.cpp
|
|
|
|
|
* @author Myles Parfeniuk
|
|
|
|
|
*/
|
|
|
|
|
|
2024-11-23 01:05:03 +00:00
|
|
|
#include "BNO08xRptRVGeneric.hpp"
|
|
|
|
|
|
2024-12-26 23:39:01 +00:00
|
|
|
/**
|
|
|
|
|
* @brief Enables a rotation vector report such that the BNO08x begins it.
|
|
|
|
|
*
|
|
|
|
|
* @param report_period_us The period/interval of the report in microseconds.
|
|
|
|
|
* @param sensor_cfg Sensor special configuration (optional, see
|
|
|
|
|
* BNO08xPrivateTypes::default_sensor_cfg for defaults).
|
|
|
|
|
*
|
|
|
|
|
* @return True if report was successfully enabled.
|
|
|
|
|
*/
|
|
|
|
|
bool BNO08xRptRVGeneric::enable(
|
|
|
|
|
uint32_t time_between_reports, sh2_SensorConfig_t sensor_cfg)
|
|
|
|
|
{
|
|
|
|
|
return BNO08xRpt::rpt_enable(time_between_reports, sensor_cfg);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 01:05:03 +00:00
|
|
|
/**
|
2024-12-05 04:07:40 +00:00
|
|
|
* @brief Grabs most recent rotation vector data in form of unit quaternion, rad accuracy units in
|
|
|
|
|
* radians (if available, else constant 0.0f).
|
2024-11-23 01:05:03 +00:00
|
|
|
*
|
2024-11-26 21:28:27 +00:00
|
|
|
* The following RV reports have rad accuracy data:
|
2024-11-23 01:05:03 +00:00
|
|
|
*
|
|
|
|
|
* - rotation vector
|
2024-11-24 03:22:06 +00:00
|
|
|
* - geomagnetic rotation vector
|
2024-11-23 01:05:03 +00:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return Struct containing requested data.
|
|
|
|
|
*/
|
|
|
|
|
bno08x_quat_t BNO08xRptRVGeneric::get_quat()
|
|
|
|
|
{
|
2024-12-05 02:12:10 +00:00
|
|
|
lock_user_data();
|
2024-11-23 01:05:03 +00:00
|
|
|
bno08x_quat_t rqdata = data;
|
2024-12-05 02:12:10 +00:00
|
|
|
unlock_user_data();
|
2024-11-23 01:05:03 +00:00
|
|
|
return rqdata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-12-05 04:07:40 +00:00
|
|
|
* @brief Grabs most recent rotation vector data in form of an euler angle, units are in degrees or
|
|
|
|
|
* rads.
|
2024-11-23 01:05:03 +00:00
|
|
|
*
|
|
|
|
|
* @param in_degrees If true returned euler angle is in degrees, if false in radians
|
|
|
|
|
*
|
|
|
|
|
* @return Struct containing requested data.
|
|
|
|
|
*/
|
|
|
|
|
bno08x_euler_angle_t BNO08xRptRVGeneric::get_euler(bool in_degrees)
|
|
|
|
|
{
|
|
|
|
|
bno08x_euler_angle_t rqdata;
|
|
|
|
|
bno08x_quat_t quat = get_quat();
|
|
|
|
|
|
|
|
|
|
rqdata = quat; // conversion handled by overloaded operator
|
|
|
|
|
|
|
|
|
|
// convert to degrees if requested
|
|
|
|
|
if (in_degrees)
|
|
|
|
|
rqdata *= RAD_2_DEG;
|
|
|
|
|
|
|
|
|
|
return rqdata;
|
|
|
|
|
}
|
2024-11-24 19:16:07 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Tares vector basis according to axis flags.
|
|
|
|
|
*
|
|
|
|
|
* @param x If true tare x axis.
|
|
|
|
|
* @param y If true tare y axis.
|
|
|
|
|
* @param z If true tare z axis.
|
|
|
|
|
* @param basis Rotation vector basis to undergo tare operation.
|
|
|
|
|
*
|
|
|
|
|
* @return True if tare operation succeeded.
|
|
|
|
|
*/
|
|
|
|
|
bool BNO08xRptRVGeneric::tare(bool x, bool y, bool z, sh2_TareBasis_t basis)
|
|
|
|
|
{
|
|
|
|
|
int success = SH2_ERR;
|
|
|
|
|
|
|
|
|
|
uint8_t axis_flag = 0U;
|
|
|
|
|
|
|
|
|
|
if (x)
|
|
|
|
|
axis_flag |= SH2_TARE_X;
|
|
|
|
|
|
|
|
|
|
if (y)
|
|
|
|
|
axis_flag |= SH2_TARE_Y;
|
|
|
|
|
|
|
|
|
|
if (z)
|
|
|
|
|
axis_flag |= SH2_TARE_Z;
|
|
|
|
|
|
2024-12-05 02:12:10 +00:00
|
|
|
lock_sh2_HAL();
|
2024-11-24 19:16:07 +00:00
|
|
|
success = sh2_setTareNow(axis_flag, basis);
|
2024-12-05 02:12:10 +00:00
|
|
|
unlock_sh2_HAL();
|
2024-11-24 19:16:07 +00:00
|
|
|
|
|
|
|
|
if (success != SH2_OK)
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return true;
|
|
|
|
|
}
|