This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

There seems to be a problem with the float value output.

Hello!

I handle mpu6050 sensor in SDK v14.
Output of sensor values was successful. And I'm going to use this value to get the angle of the sensor.

The code below is to obtain the sensor value and angle.

                app_mpu_read_accel(&accel_values);
                app_mpu_read_gyro(&gyro_values);
                .
                .
                .
                float accel_x = accel_values.x * 4.0 / 32768.0; //similar to nano33ble lsm9ds1 example.
                float accel_y = accel_values.y * 4.0 / 32768.0;
                float accel_z = accel_values.z * 4.0 / 32768.0;

                //Angle formula
                float RADIAN_TO_DEGREES = 180/3.14139;
                float val_x = atan(accel_y/sqrt(pow(accel_x,2) + pow(accel_z,2))) * RADIAN_TO_DEGREES; //X angle
                float val_y = atan(accel_x/sqrt(pow(accel_y,2) + pow(accel_z,2))) * RADIAN_TO_DEGREES; //Y angle
    
                //aceel value
                NRF_LOG_INFO("Accel_X : "NRF_LOG_FLOAT_MARKER"", NRF_LOG_FLOAT(accel_x)); //float print
                NRF_LOG_INFO("Accel_Y : "NRF_LOG_FLOAT_MARKER"", NRF_LOG_FLOAT(accel_y));
                NRF_LOG_INFO("Accel_Z : "NRF_LOG_FLOAT_MARKER"", NRF_LOG_FLOAT(accel_z));
                
                //angel value
                NRF_LOG_INFO("X-Angle : "NRF_LOG_FLOAT_MARKER"", NRF_LOG_FLOAT(val_x)); //float print
                NRF_LOG_INFO("Y-Angle : "NRF_LOG_FLOAT_MARKER"", NRF_LOG_FLOAT(val_y));

And this is the result of this code.

                 

The accel value is well output, but the angle value is only zero.
I don't think there will be any problem with that formula for angle.(Maybe...?)

Can I know about this problem?

Thank you always for your help!

Parents Reply Children
No Data
Related