Home        Store        Docs        Blog

Position calculation based on IMU data


I’m currently attempting to write a script in Python that will enable me to fetch IMU data (currently streaming at a rate of 2 outputs per second-- or 1 output each 0.5 seconds) from the BlueROV, and I would like to take the double integral to (albeit roughly) calculate the position, in the given discrete time interval, of the ROV. I plan on storing these values of position in a .csv file to analyze at a later time. I’m wondering what would be the most efficient method to continually retrieve IMU data and then perform the integration, and finally write this new position data to the file. I’m not quite sure as to how I should go about retrieving the data at each given time interval, and then performing the integration (over the same discrete time interval?) continuously for the duration of the ROV’s motion.

For reference, I am trying to track the position (from the on-board IMU) with the ultimate goal of identifying an error estimate (from a given command to the actual distance moved) to be later implemented in a Kalman Filter.

My apologies for any poor phrasing or description, I’m an undergrad and still pretty new to all of this, any help would be appreciated!



To test a Kalman filter you can do post-processing, right?

Take a look at our documentation on log analysis. I advise you to get this data from the dataflash log, as it usually has a higher rate. You should be able to get this data into a CSV by using mavlogdump the get the IMU messages.

Hi Willian,
Thank you for the quick reply. Yes, my goal is to gain some understanding of error accumulation (from drift, noise in IMU data, etc.) and will test the filter in post-processing (most likely through MATLAB).

I’ll whip something up using mavlogdump and see how far I can get.

Thank you again.

No problem, get in touch if you need any more help.

Thought I might post an update here in case others come across the this thread, I managed to abstract the code for fetching IMU data, and can now produce a matrix of all the values

def get_imu_data(master):
    return master.recv_match(type='SCALED_IMU2', blocking=True)

def get_imu_matrix(master):
    msg = get_imu_data(master)
    # return np.matrix([msg.roll, msg.pitch, msg.yaw, msg.rollspeed, msg.pitchspeed, msg.yawspeed])
    return [msg.xacc, msg.yacc, msg.zacc, msg.xgyro, msg.ygyro, msg.zgyro]

Now I just need to figure out how to roughly integrate over the same time interval to produce a displacement matrix, a question probably more suited for StackOverflow :slight_smile: Thanks again for the help @williangalvani

Cool, thank you for sharing that! Let us know how it goes.

@mseskar, I will point out that what you are trying to do will probably not work well. The imu data from the autopilot board is not suitable (precise) for dead reckoning.

Here is some more information:

1 Like

@jwalser I fully agree, in fact I’m really gathering the data to prove that statement true. I want to show the noise from the IMU and resulting error accumulation is too significant to ignore/ make useful predictions from. Thank you for the link, I’ll read through it and see what I can find.

1 Like