This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TivaWare sensorlib example compdcm_mpu9150 bug



I found a small bug in the compdcm_mpu9150 example.

Prior to the UARTprintf for all 9dof data, values between 0 and -1 drop their sign and appear as positive numbers.  This is due to the math on the integer and decimal components of the float for display.

-0.5 will be converted to 0 and -500, the negative sign will subsequently be dropped and will be displayed as 0.500 when displayed as %3d.%03d

This error applies to all 16 values including 9dof + quaternions + eulers as displayed on the UART.

  • Hello Chris,

    Yes, we are aware of this issue. And we did clearly miss it during the last TivaWare release but I have now filed an internal bug on the same.

    Thanks.

    Regards
    Amit
  • My fix is here, it is not the greatest solution most likely but much simpler / lighter than rewriting UARTprintf to parse floats.

    This replaces the loop in compdcm_mpu9150.c that decomposes the float into integers and the list of UARTprintf statements that compose the table with the same net result (without the 0 to -1 bug).

                const uint8_t table_offset[16][2] = {
                		{5,17}, {5,40}, {5,63}, // Accel
    			{7,17}, {7,40}, {7,63}, // Gyro
                		{9,17}, {9,40}, {9,63}, // Mag
    			{14,17}, {14,40}, {14,63}, // Euler
    			{19,14}, {19,32}, {19,50}, {19,68} }; // Quat
    
                uint8_t neg_flag = 0; // flag for numbers between 0 and -1
    
                for(ui32Idx = 0; ui32Idx < 16; ui32Idx++)
                {
                    //
                    // Conver float value to a integer truncating the decimal part.
                    //
                    i32IPart[ui32Idx] = (int32_t) pfData[ui32Idx];
    
                    //
                    // Multiply by 1000 to preserve first three decimal values.
                    // Truncates at the 3rd decimal place.
                    //
                    i32FPart[ui32Idx] = (int32_t) (pfData[ui32Idx] * 1000.0f);
    
                    //
                    // Subtract off the integer part from this newly formed decimal
                    // part.
                    //
                    i32FPart[ui32Idx] = i32FPart[ui32Idx] -
                                        (i32IPart[ui32Idx] * 1000);
    
                    //
                    // make the decimal part a positive number for display.
                    //
                    neg_flag = 0;
                    if(i32FPart[ui32Idx] < 0)
                    {
                        i32FPart[ui32Idx] *= -1;
                        if (i32IPart[ui32Idx] == 0)
                        {
                        	neg_flag = 1; // fix for number between 0 and -1
                        }
                    }
    
                    //
    		// Print the acceleration numbers in the table.
    		//
                    if (neg_flag)
                    {
    		   UARTprintf("\033[%d;%dH -0.%03d",
    			table_offset[ui32Idx][0], table_offset[ui32Idx][1],
    			i32FPart[ui32Idx]);
                    }
                    else
                    {
                       UARTprintf("\033[%d;%dH%3d.%03d",
                    	table_offset[ui32Idx][0], table_offset[ui32Idx][1],
    			i32IPart[ui32Idx], i32FPart[ui32Idx]);
                    }
                }

  • Hello Chris

    Thanks again for posting the code. But we would like to make sure that a permanent change in most concise manner after testing is incorporated.

    Regards
    Amit
  • Amit,

    Yes I understand, thank you. This is just a fix to get people by until your permanent change comes.. Thanks for addressing this.

    Regards
    Chris