Hi, I am using BHY2_SENSOR_ID_RV and parse_quaternion to find magnetic north. It works fine to find north, just that it requires calibration everytime the device restart. I want to get and save the calibration profile to shorter the calibration period. Now what I am doing is the moment the accuracy value of parse_quaternion is lower than a threshold(now is 30), I regard it as calibrated and get the calibration profile. Then I manually copy the value to the array and apply them to bhy2_set_calibration_profile. 1.But it doesnt make it quicker to get the accuracy value of parse_quaternion lower than the threshold. 2.And after it goes into the lower than threshold function again, and jump to bhy2_get_calibration_profile again, I get nothing from the functions - actual_len=0. What could be the reason? Attach part of my code for your reference. Thanks /CJ static void parse_quaternion(const struct bhy2_fifo_parse_data_info *callback_info, void *callback_ref)
{
(void)callback_ref;
struct bhy2_data_quaternion data;
uint32_t s, ns;
//uint32_t actual_len;
if (callback_info->data_size != 11) /* Check for a valid payload size. Includes sensor ID */
{
return;
}
bhy2_parse_quaternion(callback_info->data_ptr, &data);
uint64_t timestamp = *callback_info->time_stamp; /* Store the last timestamp */
timestamp = timestamp * 15625; /* Timestamp is now in nanoseconds */
s = (uint32_t)(timestamp / UINT64_C(1000000000));
ns = (uint32_t)(timestamp - (s * UINT64_C(1000000000)));
printf("SID: %u; T: %u.%09u; x: %f, y: %f, z: %f, w: %f; acc: %.2f\r\n",
callback_info->sensor_id,
s,
ns,
data.x / 16384.0f,
data.y / 16384.0f,
data.z / 16384.0f,
data.w / 16384.0f,
((data.accuracy * 180.0f) / 16384.0f) / 3.141592653589793f);
if((((data.accuracy * 180.0f) / 16384.0f) / 3.141592653589793f) < 30 && !is_calibrated)
{
is_calibrated = true;
is_time_save_calibration = true;
}
}
uint16_t acc_prof_len = 72;
const uint8_t acc_calib_prof[72] = {0x01,0x52,0x00,0x04,0x7f,0x30,0x01,0x40,0x04,0x00,0x6f,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x0b,0x00,0x10,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0b,0x00,0x08,0x00,0x00,0x04,0x00,0x00,0x06,0x00,0x10,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x08,0x00,0x00,0x02,0x00,0x10,0x00,0x00,0x20,0x00,0xb1,0x00};
uint16_t gyro_prof_len = 200;
const uint8_t gyro_calib_prof[200] = {0x01,0x52,0x00,0x04,0x7f,0xb0,0x01,0x40,0x0e,0x00,0x6f,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x0c,0x00,0x10,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x00,0x08,0x00,0x00,0x02,0x00,0x00,0x0c,0x00,0x10,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x00,0x08,0x00,0x00,0x07,0x00,0x00,0x0c,0x00,0x10,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x00,0x10,0x00,0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x00,0x10,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x00};
uint16_t mag_prof_len = 408;
const uint8_t mag_calib_prof[408] = {0x01,0x52,0x00,0x04,0x7f,0x80,0x01,0x40,0x0e,0x00,0x6f,0x01,0x00,0x00,0xff,0x00,0x00,0x00,0x0d,0x34,0x10,0x42,0x00,0x01,0x00,0x00,0x90,0xe8,0x00,0xc1,0x00,0x42,0x00,0x01,0x0d,0x00,0x08,0x00,0x00,0x04,0x00,0x00,0x0d,0x00,0x08,0x00,0x00,0x05,0x00,0x00,0x0d,0x08,0x08,0x43,0x00,0x07,0x00,0x01,0x0d,0x00,0x08,0x00,0x00,0x06,0x00,0x00,0x0d,0x34,0x10,0x42,0x00,0x02,0x00,0x00,0x90,0xe8,0x00,0x3f,0x90,0xe4,0x6b,0xc1,0x96,0x42,0xd5,0x00,0x07,0x00,0x7c,0x00,0x00,0x43,0x00,0x21,0x0d,0x0c,0x48,0x39,0x0c,0x0e,0xad,0x0e,0x0f,0x07,0x41,0xb9,0xcb,0x38,0x2b,0x48,0xea,0x0f,0x5d,0x38,0xad,0xb8,0x3f,0x12,0x22,0xc2,0x52,0xb7,0x3a,0x74,0x9c,0xbc,0xd9,0xbd,0xac,0x78,0x2d,0x2a,0x9e,0xbb,0x74,0x3c,0xfb,0x51,0x12,0x2e,0xfe,0x3c,0xad,0x3e,0xc7,0x8c,0x2a,0x12,0x02,0xbd,0x2e,0x3c,0x99,0x79,0x70,0x4c,0x44,0x3c,0xb9,0xbc,0xad,0x46,0x2e,0x2c,0x50,0x3e,0x34,0x3c,0x1a,0x28,0x0e,0x9a,0x5a,0xbc,0x0b,0xbd,0x5d,0x9b,0x53,0x3a,0x44,0xbd,0xb5,0xbd,0xc7,0x5a,0x2a,0x0e,0x02,0xbd,0x1a,0x3c,0x18,0x12,0x6e,0x0a,0x22,0x3c,0x72,0x3d,0xf8,0x44,0x18,0x74,0x1b,0xbc,0xd9,0x3c,0x2e,0x26,0x12,0x9a,0x8b,0xbc,0x0b,0xbd,0x72,0xa7,0x0a,0x2a,0x11,0x3d,0xcf,0x3c,0xbc,0x9d,0x61,0x2d,0xc7,0x3c,0xac,0x3c,0x99,0x44,0x70,0x53,0x44,0xbd,0x5d,0xbc};
void BHI260AP_init()
{
......
rslt = bhy2_register_fifo_parse_callback(BHY2_SENSOR_ID_RV, parse_quaternion, NULL, &bhy2);
print_api_error(rslt, &bhy2);
......
//Set calibration profile
#if 1
bhy2_set_calibration_profile(BHY2_PHYS_SENSOR_ID_ACCELEROMETER, acc_calib_prof, acc_prof_len, &bhy2);
bhy2_set_calibration_profile(BHY2_PHYS_SENSOR_ID_GYROSCOPE, gyro_calib_prof, gyro_prof_len, &bhy2);
bhy2_set_calibration_profile(BHY2_PHYS_SENSOR_ID_MAGNETOMETER, mag_calib_prof, mag_prof_len, &bhy2);
#endif
..........................
//---------------------------------Enable QUAT------------------------------
#if 1
sample_rate = 20;//100.0; /* Read out data measured at 100Hz */
report_latency_ms = 0; /* Report immediately */
rslt = bhy2_set_virt_sensor_cfg(BHY2_SENSOR_ID_RV, sample_rate, report_latency_ms, &bhy2);
print_api_error(rslt, &bhy2);
printf("Enable %s at %.2fHz.\r\n", get_sensor_name(BHY2_SENSOR_ID_RV), sample_rate);
#endif
}
void main()
{
BHI260AP_init();
...........
for(;;)
{
if(is_time_save_calibration)
{
is_time_save_calibration = false;
#if 1
int i;
memset(bhi260_calib_prof, 0, sizeof(bhi260_calib_prof));
actual_len = 0;
bhy2_get_calibration_profile(BHY2_PHYS_SENSOR_ID_ACCELEROMETER, bhi260_calib_prof, bhi260_prof_len, &actual_len, &bhy2);
printf("BHY2_PHYS_SENSOR_ID_ACCELEROMETER profile----------------------------bhi260_prof_len=%d, actual_len=%d---------------------\r\n", bhi260_prof_len, actual_len);
for(i=0; i < actual_len; i++)
{
printf("0x%02x,", bhi260_calib_prof[i]);
}
printf("\r\n");
memset(bhi260_calib_prof, 0, sizeof(bhi260_calib_prof));
actual_len = 0;
bhy2_get_calibration_profile(BHY2_PHYS_SENSOR_ID_GYROSCOPE, bhi260_calib_prof, bhi260_prof_len, &actual_len, &bhy2);
printf("BHY2_PHYS_SENSOR_ID_GYROSCOPE profile----------------------------bhi260_prof_len=%d, actual_len=%d---------------------\r\n", bhi260_prof_len, actual_len);
for(i=0; i < actual_len; i++)
{
printf("0x%02x,", bhi260_calib_prof[i]);
}
printf("\r\n");
memset(bhi260_calib_prof, 0, sizeof(bhi260_calib_prof));
actual_len = 0;
bhy2_get_calibration_profile(BHY2_PHYS_SENSOR_ID_MAGNETOMETER, bhi260_calib_prof, bhi260_prof_len, &actual_len, &bhy2);
printf("BHY2_PHYS_SENSOR_ID_MAGNETOMETER profile----------------------------bhi260_prof_len=%d, actual_len=%d---------------------\r\n", bhi260_prof_len, actual_len);
for(i=0; i < actual_len; i++)
{
printf("0x%02x,", bhi260_calib_prof[i]);
}
printf("\r\n");
#endif
}
}
}
... View more