Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mpu6050driver.cpp #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

JosefGst
Copy link

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

@JosefGst
Copy link
Author

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

Copy link

@leeyunhome leeyunhome left a comment

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
Copy link
Author

JosefGst commented Nov 26, 2022

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

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.


Grant user access to i2c, need to reboot afterwards:

sudo usermod <user-name> -aG i2c
Copy link

@anasderkaoui anasderkaoui Mar 6, 2024

Choose a reason for hiding this comment

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

Suggested change
sudo usermod <user-name> -aG i2c
sudo usermod <user-name> -aG i2c # or this: sudo chmod +777 /dev/i2c-*

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.

None yet

3 participants