How can i detect 360 degree rotation from sensor

#include <Geometry.h>

#include "MPU6050_6Axis_MotionApps20.h"

#include "I2Cdev.h"

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE

    #include "Wire.h"

#endif

MPU6050 mpu ;


int16_t ax, ay, az;

int16_t gx, gy, gz;

uint16_t fifoCount;     // count of all bytes currently in FIFO

uint8_t fifoBuffer[64]; // FIFO storage buffer

int val;

int prevVal;
 
int valax; 

int valay;

int valaz;


float euler[3];         // [psi, theta, phi]    Euler angle container


Quaternion q;           // [w, x, y, z]         quaternion container



void setup()

{
 
 Serial.begin(9600);

  Wire.begin();      

  Serial.println("Initialize MPU");

  mpu.initialize();

  Serial.println(mpu.testConnection() ? "Connected" : "Connection failed");
 
}   


void loop()

{

mpu.dmpGetQuaternion(&q,fifoBuffer);

mpu.dmpGetEuler(euler, &q);

 
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

valax = map(ax, -17000, 17000, 0, 255) ;

valay = map(ay, -17000, 17000, 0, 255);

valaz = map(az, -17000, 17000, 0, 255);
 
Serial.println("ax: ");

Serial.println(valax);

Serial.println("ay:");

Serial.println(valay);

Serial.println("az: ");

Serial.println(valaz);

Serial.println("");

Serial.println("");

Serial.print("euler\t");

Serial.print(euler[0] * 180 /M_PI);

Serial.print("\t");

Serial.print(euler[1] * 180/M_PI);

Serial.print("\t");

Serial.println(euler[2] * 180/M_PI);


delay(1000);

}```

[quote="agreyg, post:1, topic:866719, full:true"]

I want to know how can i detect 360 rotation when sensor is s not on 0 degree and is at different angel such as 50 degrees it does not completes 360 degree rotation and i have to change code again and again to meet with conditions . do u have any idea to auto correct sensor by itself .
[/quote]

Are you asking how to correct for yaw drift in a 6DoF sensor?

yes , i don't know how can correct my hidden mistakes . and also i don't know much about euler' angel . if u could correct my code please do it.

please tell how can i check the offset e.g. 50 deg when you start your program. Then on rotation you'll need 50 to 360 and 360 to 50 for full 360 rotation. So what you want is know what start postion the sensor was in and measure relative rotation instead of absolute.

Are you trying to calibrate the rotation angle when the sensor is off by some factor then? I still not sure what the problem is - perhaps you could explain what you do and the positions and readings you are getting that are in error?

can u make a code which can 50 deg when you start your program. Then on rotation you'll need 50 to 360 and 360 to 50 for full 360 rotation. So what you want is know what start postion the sensor was in and measure relative rotation instead of absolute. Because i think we are not getting anywhere . and also the code i had posted it not doing what i wanted it should calculate euler angel and report 360 degree rotation . thanks for listening

no , i am not trying to calibrate the rotation angle when the sensor is off . i am just asking how can i detect rotation . forget the readings , is it possible to save first reading of sensor and then find it if the sensor completes 360 rotation . can it be done ?

The MPU-6050 is useless as an absolute orientation sensor, because it has no yaw reference and will always drift.

However, in the short term you can integrate the rate gyro outputs, and use that to detect a reasonably fast 360 degree rotation about an axis. This code does that, but first the gyro should be calibrated to remove the zero offset.

thank you so much for your kind help , but i didn't get that how can i integrate the rate of gyro .
will u explain me a little bit.

once again thank u :grinning: :grinning:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.