Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    Read RPY Data from BHI160B IMU using STM32-L053R8

    Read RPY Data from BHI160B IMU using STM32-L053R8

    vamshi
    Established Member

    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.

    7 REPLIES 7

    BSTRobin
    Community Moderator
    Community Moderator

    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.

    vamshi
    Established Member

    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 ?

    BSTRobin
    Community Moderator
    Community Moderator

    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*/
    ...
    }

    vamshi
    Established Member

    Thank you for the reply @BSTRobin,

    Ok, Present I'm working on it. Could you please suggest functions to change Acc, Gyr, and Mag scale factors?
    Do those functions exist in the above code files?

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist