# How to do transformation to get correct linear velocity from linear acceleration IMU data?

I have IMU sensor that gives me the raw data such as orientation, Angular and Linear acceleration. Im using ROS and doing some Gazebo UUV simulation. Furthermore, I want to get linear velocity from the raw IMU data. If I do integration over time there will be accumulated error and will not be accurate with the time when for example the robot makes turns. So If I use

acceleration_x = (msg->linear_acceleration.x + 9.81 * sin(pitch)) * cos(pitch);

acceleration_y = (msg->linear_acceleration.y - 9.81 * sin(roll)) * cos(roll);

So integrating linear acceleration is very bad,

Velocity_x= Velocity_old_x+acceleration_x*dt;

because integrates the acceleration without taking into account any possible rotation of the sensor, which means that the results will probably be terrible if the sensor rotates at all. So I need some ROS package that takes into account all this transformation and gives me the most accurate estimation of the linear velocity. Any Help? Thanks

What you have stumbled upon here is a classic problem in robotics; where am I? Localization is a hard to solve problem. Every sensor will have associated noise and accurately figuring out velocity and position is hard. The most widely used package in ros is robot_localization that will take in arbitrary number of sensor inputs and produce output poses (position and velocity). I'd recommend using the ekf state estimation node.

Unfortunately, if you are stuck with using one IMU, you will have to deal with noise. I'd recommend using additional sources of odometry for better estimates.

• my first step is to use only IMU to estimate velocity. Then will do sensor fusion of IMU and Pressure for example. But first only get linear velocity using only IMU. So docs.ros.org/en/noetic/api/robot_localization/html/index.html and docs.ros.org/en/noetic/api/robot_localization/html/… can give me linear velocity using only IMU?
– bob
Sep 23, 2021 at 6:02
• Maybe. I have never tried it with only 1 source but they claim its possible. So give it a try Sep 23, 2021 at 19:53
• That doesn't solve the integration problem. In order to get velocity need to integrate the acceleration. And with the time that error will accumulate and will be huge. So my problem is how to minimize that error. Understand?
– bob
Sep 24, 2021 at 8:51
• I understand your question. I am only sharing a ROS package that I think might be helpful! Sep 24, 2021 at 15:07
• ok Im looking for more as mathematical approach to minimize the integration error.
– bob
Sep 25, 2021 at 11:58