KerJoe / MPU6050-Cemuhook-gyro

Gyroscope for Cemuhook based on ESP8266 microcontroller and MPU6050 accelerometer and gyroscope IC

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question regarding drifting

LegendaryBoyA12 opened this issue · comments

Hello! I've previously posted on here and you were kind enough to help me out. I've since gotten the parts and set up the sensors. While everything works fine and I can use PadTest to see how my controller is reacting, it does suffer from drifting yaw. After some quick research, I found that at least for other projects using DMP could fix this issue. Is it possible to use this for the program, or would it not work?

Hmm, I don't really know any way to prevent yaw drift except using a magnetometer. Can you post links to those projects, which provide a fix?

https://howtomechatronics.com/tutorials/arduino/arduino-and-mpu6050-accelerometer-and-gyroscope-tutorial/

And the original Youtube Video with the time stamp

https://youtu.be/UxABxSADZ6U?t=415

Here is where I first found it. Halfway through explaining the MPU6050 he mentions the yaw drift and using another board like a magnetometer, before saying that the Digital Motion Processor can correct it, along with a 3d model showing the difference

http://www.geekmomprojects.com/mpu-6050-dmp-data-from-i2cdevlib/

And a video example with another 3d model

https://www.youtube.com/watch?v=T2igMNMBsjI&feature=emb_title

I guess I will look more into DMP later. For now I think that simply calculating and subtracting an offset from gyroYF can considerably decrease the effect of yaw drift.
I have updated the .ino file, try the new version and report on the changes.

The drifting doesn't seem to have changed very much from testing. I can try to see if there's any special things I could do on my end. Thank you again for looking through this for me, I appreciate it

Can you send a screenshot of padTest while the sensor is motionless?

Padtest

Sorry for the delay, here is the screenshot of padtest while the sensor is not being moved

It seems you didn't correctly set the offset values.
Here's how the padtest should look when the sensor is in horizontal position:
Снимок экрана (26)
And here's a video demonstrating different sensor positions:
https://youtu.be/w_UOZ-U79Ew

As I mention in the source code you need to plug your values here:

// Set offsets to values calculated by IMU_ZERO example sketch
accgyr.setXAccelOffset(-2741);
accgyr.setYAccelOffset(2456);
accgyr.setZAccelOffset(1400);
accgyr.setXGyroOffset(-37);
accgyr.setYGyroOffset(-24);
accgyr.setZGyroOffset(167);

And you also need to shuffle accXF, accYF, accZF gyrPF, gyrRF, gyrYF. According to theese rules:

To transform data from gyroscope to the form used by cemuhook use these guidelines
(You can also use a demonstration image from the github page):
-----
1) In the default position (i.e. when the controller is lying on a flat surface) the values 
   of the controller are accXF = 0, accYF = -1, accZF = 0, gyrPF = 0, gyrRF = 0, gyrYF = 0;
2) When the face side of the controller points down accelerometer values are accXF = 0, accYF = 1, accZF = 0
   When the underside of the controller points down accelerometer values are accXF = 0, accYF = -1, accZF = 0
   When the left side of the controller points down accelerometer values are accXF = -1, accYF = 0, accZI = 0
   When the right side of the controller points down accelerometer values are accXF = 1, accYF = 0, accZI = 0
   When the front side of the controller points down accelerometer values are accXF = 0, accYF = 0, accZI = -1
   When the back side of the controller points down accelerometer values are accXF = 0, accYF = 0, accZI = 1
3) When rotating controller from left to right gyrYF increases
   When rotating controller from right to left gyrYF decreases
   When rotating controller from down to up gyrPF increases
   When rotating controller from up to down gyrPF decreases
   When rotating controller from left grip pointing down to left grip pointing up gyrRF increases
   When rotating controller from left grip pointing up to left grip pointing dwon gyrRF decreases 
std::swap(accXF, accYF); //float tmp; tmp = accYF; accYF = accZF; accZF = tmp;
std::swap(accZF, accYF); //float tmp; tmp = accYF; accYF = accZF; accZF = tmp;
accZF = -accZF;
std::swap(gyrPF, gyrRF); //float tmp; tmp = accYF; accYF = accZF; accZF = tmp;
gyrPF = -gyrPF;
gyrRF = -gyrRF;

You also may set the gyrOffYF after the first calibration, and then disable further ones by setting gyrYOffsetCallibration = false:

if (gyrYOffsetCallibration)
{
  Serial.print("Additional Yaw callibration");  
  for (uint8_t i = 0; i < 10; i++) // Use simple arithmetic mean
  {
    accgyr.getMotion6(&accXI, &accYI, &accZI, &gyrPI, &gyrRI, &gyrYI);
    gyrOffYF += gyrYI / gyroLSB; // Instead of gyrYI use your actual Yaw axis
    Serial.print("."); delay(100);
  }  
  gyrOffYF /= 10; Serial.println(gyrOffYF);
}
else gyrOffYF = 0.5f; // Make offset constant after a single callibration

As of now it seems that the drift is caused only by a miscallibration of the sensor and not the problem of the code, so I am closing the issue.