08-01-2022 01:19 PM - edited 08-01-2022 01:19 PM
Hi Team,
I have got the quaternion values from BHI160 using MCU. Now we need to read RPY data from the BHI160B IMU. I found that if we change VS_TYPE to "VS_TYPE_ORIENTATION", will that helps to get RPY data?
because we have one call-back function which gives only Quaterninons x,y,z, and w data.
Is there any process to read RPY or the same function enough based VS_TYPE? If Yes, where is that RPY data located?
Could you let me know the way to get RPY?
Any help would be very thankful.
Solved! Go to Solution.
08-01-2022 04:13 PM
Hi vamshi,
As you have got quaternion values, you could convert them to RPY values by formula calculation.
If you hardware used accel, gyro, mag sensor, you could enable virtual sensor VS_TYPE_ORIENTATION and get RPY values.
08-02-2022 07:06 AM - edited 08-02-2022 07:08 AM
Thank you for the reply @BSTRobin ,
Yes, the hardware used Acc, Gyr, Mag sensors.
I accept your suggestion. But, In Program I have only one function named the call-back function of the Rotation vector which gives Quaternions.
Can I use the below configuration and Reading function to get RPY or Should I need to do modifications for RPY data?
if (bhy_install_sensor_callback(VS_TYPE_ORIENTATION, VS_WAKEUP,
sensors_callback_orientation)) {
//DEBUG("Fail to install sensor callback\n");
}
if (bhy_enable_virtual_sensor(VS_TYPE_ORIENTATION, VS_WAKEUP,
ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0)) {
//DEBUG("Fail to enable sensor id=%d\n", VS_TYPE_ROTATION_VECTOR);
}
static void sensors_callback_rotation_vector(bhy_data_generic_t *sensor_data,
bhy_virtual_sensor_t sensor_id) {
float temp;
uint8_t index;
temp = sensor_data->data_quaternion.w / 16384.0f; /* change the data unit by dividing 16384 */
out_buffer[3] = temp < 0 ? '-' : ' ';
temp = temp < 0 ? -temp : temp;
out_buffer[4] = floor(temp) + '0';
for (index = 6; index <= 8; index++) {
temp = (temp - floor(temp)) * 10;
out_buffer[index] = floor(temp) + '0';
}
temp = sensor_data->data_quaternion.x / 16384.0f;
out_buffer[13] = temp < 0 ? '-' : ' ';
temp = temp < 0 ? -temp : temp;
out_buffer[14] = floor(temp) + '0';
for (index = 16; index <= 18; index++) {
temp = (temp - floor(temp)) * 10;
out_buffer[index] = floor(temp) + '0';
}
temp = sensor_data->data_quaternion.y / 16384.0f;
out_buffer[23] = temp < 0 ? '-' : ' ';
temp = temp < 0 ? -temp : temp;
out_buffer[24] = floor(temp) + '0';
for (index = 26; index <= 28; index++) {
temp = (temp - floor(temp)) * 10;
out_buffer[index] = floor(temp) + '0';
}
temp = sensor_data->data_quaternion.z / 16384.0f;
out_buffer[33] = temp < 0 ? '-' : ' ';
temp = temp < 0 ? -temp : temp;
out_buffer[34] = floor(temp) + '0';
for (index = 36; index <= 38; index++) {
temp = (temp - floor(temp)) * 10;
out_buffer[index] = floor(temp) + '0';
}
//DEBUG("x=%d, y=%d, z=%d, w=%d\n", sensor_data->data_quaternion.x, sensor_data->data_quaternion.y, sensor_data->data_quaternion.z, sensor_data->data_quaternion.w);
}
What I have to modify in that function to get RPY ?
08-03-2022 08:16 AM
Hi vamshi,
You could refer this callback function. But we didn't have function converting quaternion data to euler data, it needs to be implemented by yourself.
typedef struct {
double w, x, y, z;
}Quaternion;
static void sensors_callback_rotation_vector(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
...
float qx, qy, qw, qz;
Quaternion q;
qw = sensor_data->data_quaternion.w / 16384.0f;
qz = sensor_data->data_quaternion.z / 16384.0f;
qy = sensor_data->data_quaternion.y / 16384.0f;
qx = sensor_data->data_quaternion.x / 16384.0f;
q.w = (double)qw;
q.x = (double)qx;
q.y = (double)qy;
q.z = (double)qz;
/*convert quaternion data to euler data by yourself*/
...
}
08-03-2022 11:20 AM