cancel
Showing results for 
Search instead for 
Did you mean: 

I want to know correct degree and direction using lis2dh12 and lis3mdl.

Mpraj.19
Associate II

when hand held device is flat i get roll and pitch degree -2 and +2.

during pitch measurement :

moving upwards from a flat level front , and then i get -90 degree.moving flat level from upward i get -2 degree. moving downward from a flat level, and then i get 90 degree.moving flat level from upward i get +2 degree.

during roll measurement :

moving downward from a flat level right side, and then i get -90 degree.moving flat level from downward i get 2 degree.

moving upwards from a flat level at left , and then i get 90 degree.moving flat level from upward i get 2 degree.

means i get pitch and roll degree with range +90 to -90. with out roll and pitch i get the correct degree and direction but when i tilt the hand held device i not get correct degree and direction . so i use roll and pitch in below code but i not get correct degree and direction

i use below code

       float xA=(atof(qFileData_xA.simplified()));

       float yA=(atof(qFileData_yA.simplified()));

       float zA=(atof(qFileData_zA.simplified()));

       float      pitch;

       float      roll;

        pitch =(180 * atan2(xA, sqrt((yA*yA) + (zA*zA)))/M_PI);

        roll = (180 * atan2(yA, sqrt((xA*xA) + (zA*zA)))/M_PI);

      

       qFileData_xM.clear();

       if(ReadFileAndGetText(MAGNETOMETER_X_FILE, qFileData_xM))

       

       qFileData_yM.clear();

      if( ReadFileAndGetText(MAGNETOMETER_Y_FILE, qFileData_yM))

       

       qFileData_zM.clear();

      if( ReadFileAndGetText(MAGNETOMETER_Z_FILE, qFileData_zM))

       

       float xM=atof(qFileData_xM.simplified());

       float yM=atof(qFileData_yM.simplified());

       float zM=atof(qFileData_yM.simplified());

       if(xM >2655)

        xM -=8607;

       if(yM <-2655)

       yM += 9357;

       float xMD=xM*cos(pitch)+yM*sin(roll)*sin(pitch) + zM*cos(roll)*sin(pitch);

      float yMD=yM * cos(roll) -zM * sin(roll);

       float result_degree;

       result_degree=90+(180*(qAtan2(yMD,xMD))/M_PI);

       if(result_degree<0)

          result_degree +=360;

       if(result_degree>=330 && result_degree<360)

        qDebug() << "POSITION: " << result_degree<<"N";

       if(result_degree>=0 && result_degree<30)

        qDebug() << "POSITION: " << result_degree<<"N";

       if(result_degree>=30 && result_degree<60)

        qDebug() << "POSITION: " << result_degree<<"NE";

       if(result_degree>=60 && result_degree<120)

        qDebug() << "POSITION: " << result_degree<<"E";

       if(result_degree>=120 && result_degree<150)

        qDebug() << "POSITION: " << result_degree<<"SE";

       if(result_degree>=150 && result_degree<210)

        qDebug() << "POSITION: " << result_degree<<"S";

       if(result_degree>=210 && result_degree<240)

        qDebug() << "POSITION: " << result_degree<<"SW";

       if(result_degree>=240 && result_degree<300)

        qDebug() << "POSITION: " << result_degree<<"W";

       if(result_degree>=300 && result_degree<330)

        qDebug() << "POSITION: " << result_degree<<"NW";

////////////////////////

so please tell me is i use correct equation if yes then where i make the mistake ? please guide me to get correct degree and direction

       

0 REPLIES 0