Skip to content

Update mpu6050driver.cpp#1

Open
JosefGst wants to merge 4 commits into
hiwad-aziz:mainfrom
JosefGst:main
Open

Update mpu6050driver.cpp#1
JosefGst wants to merge 4 commits into
hiwad-aziz:mainfrom
JosefGst:main

Conversation

@JosefGst

Copy link
Copy Markdown

the called parameter to calc the duration should be "frequency"

@JosefGst

Copy link
Copy Markdown
Author

Sorry, I actually only want to commit 'Update mpu6050driver.cpp'. the other commits are only specific to my usecase

@leeyunhome leeyunhome left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, @JosefGst @hiwad-aziz

Thank you for your nice article
I have some questions.

  1. What is the license for this library?
  2. I want to get angles like below url.
    url : https://github.com/tockn/MPU6050_tockn
    How can I get angles using this mpu6050driver?
  3. Can I substitute sensor_msgs::msg::Imu to custom msg?
    like below.
    builtin_interfaces/Time stamp int16 accx int16 accy int16 accz int16 gyrx int16 gyry int16 gyrz float32 angx float32 angy float32 angz

Thank you very much.

@JosefGst

JosefGst commented Nov 26, 2022

Copy link
Copy Markdown
Author

hello @leeyunhome

  1. IDK
  2. the angles are not implemented in the code yet. you may need to integrate all the angular velocities and devide over time.
  3. Is it you want to get all the accel data?

@leeyunhome

Copy link
Copy Markdown

Hello,

Thank you for your answer.

you may need to integrate all the angular velocities and devide over time.
=> I'm a beginner, so I'm not sure if I just read the description.
Could you please explain it in simple pseudo code?

Let me explain what I think

In the project I referenced above (https://github.com/tockn/MPU6050_tockn)

The angle was calculated with the raw data as shown below.
Is the calculation process below correct? Is the interval here the time multiplied by the angular velocity?

` rawAccX = wire->read() << 8 | wire->read();
rawAccY = wire->read() << 8 | wire->read();
rawAccZ = wire->read() << 8 | wire->read();
rawTemp = wire->read() << 8 | wire->read();
rawGyroX = wire->read() << 8 | wire->read();
rawGyroY = wire->read() << 8 | wire->read();
rawGyroZ = wire->read() << 8 | wire->read();

temp = (rawTemp + 12412.0) / 340.0;

accX = ((float)rawAccX) / 16384.0;
accY = ((float)rawAccY) / 16384.0;
accZ = ((float)rawAccZ) / 16384.0;

angleAccX = atan2(accY, sqrt(accZ * accZ + accX * accX)) * 360 / 2.0 / PI;
angleAccY = atan2(accX, sqrt(accZ * accZ + accY * accY)) * 360 / -2.0 / PI;

gyroX = ((float)rawGyroX) / 65.5;
gyroY = ((float)rawGyroY) / 65.5;
gyroZ = ((float)rawGyroZ) / 65.5;

gyroX -= gyroXoffset;
gyroY -= gyroYoffset;
gyroZ -= gyroZoffset;

interval = (millis() - preInterval) * 0.001;

angleGyroX += gyroX * interval;
angleGyroY += gyroY * interval;
angleGyroZ += gyroZ * interval;

angleX = (gyroCoef * (angleX + gyroX * interval)) + (accCoef * angleAccX);
angleY = (gyroCoef * (angleY + gyroY * interval)) + (accCoef * angleAccY);
angleZ = angleGyroZ;`

Thank you.

Comment thread README.md Outdated
Co-authored-by: Anas Derkaoui <115218309+anasderkaoui@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants