Increasing IMU frequency using Dronekit

Hello,

I created a code using Dronekit where I save in a txt file some data from the Drone. The data I saved is GPS data, airspeed, data from external sensors, barometer data and IMU data (accelerometer and gyroscope).

The data I extract is in a loop that has a time.sleep = 0.02 sec. In the txt file created, it seems that the frequency of the sensors data is less than this 50 Hz. I changed the parameters SR0_xxx to the maximum frequency but it looks like is not working.

The way I suspect that it’s not working is because in the txt file created, most of the data is the same for half a second or sometimes a little bit more.

Any suggest to increase the IMU data rate for the USB port?

I am running the code in a Raspberry Pi 3 connected directly top the microUSB port of the Pixhawk.

Thank you so much.

To be on the safe side, replace dronekit with pymavlink.

Hello,

I replaced Dronekit with mavlink and I obtained this code:

from pymavlink import mavutil
import time
from datetime import datetime

#Start a connection listening to a UDP port
the_connection = mavutil.mavlink_connection(‘com4’, baud=115200)

#Wait for the first heartbeat
#This sets the system and component ID of remote system for the link
the_connection.wait_heartbeat()

xacc = None
yacc = None
zacc = None
xgyro = None
ygyro = None
zgyro = None
yaw = None
pitch = None
roll = None

start_time = time.time()

count = 1
now = datetime.now()
timestamp = now.strftime(“%Y-%m-%d_%H-%M-%S”)

filename = f"{timestamp}.txt"
f = open(filename, ‘a’)
while 1:
current_time = time.time()
elapsed_time = round(current_time - start_time, 2)
the_connection.mav.command_long_send(1, 0, 512, 0, 27, 1e6/50, 0, 0, 0, 0, 0)
the_connection.mav.command_long_send(1, 0, 512, 0, 30, 1e6/50, 0, 0, 0, 0, 0) # ATTITUDE

msg = the_connection.recv_match(type=['RAW_IMU', 'ATTITUDE'], blocking=True)

if msg.get_type() == 'RAW_IMU':
    xacc = msg.xacc
    yacc = msg.yacc
    zacc = msg.zacc
    xgyro = msg.xgyro
    ygyro = msg.ygyro
    zgyro = msg.zgyro

elif msg.get_type() == 'ATTITUDE':
    yaw = round(msg.yaw, 2)
    pitch = round(msg.pitch, 2)
    roll = round(msg.roll, 2)

f.write(str(elapsed_time) +' ' + str(xacc) +' ' + str(yacc) +' ' + str(zacc) +' ' + str(xgyro) +' ' + str(ygyro) +' ' + str(zgyro) +' ' + str(yaw) +' ' + str(ygyro) +' ' + str(zgyro)+'\n')

What I want is to obtain the maximum IMU frequency when connected to the USB port of the pixhawk, and read this IMU data using the code, and save it to a txt file. The same with the ATTITUDE and other parameters

Modifying the SR0_xxx parameters, it looks like the frequency is not changing

In the txt file is created, some values do not respect the requested frequency. Also, during some lines, the values are repeated, showing a false higher frequency.

0.0 None None None None None None -2.44 None None
0.0 None None None None None None -2.44 None None
0.06 -196 185 -953 -1 2 -3 -2.44 2 -3
0.06 -196 185 -953 -1 2 -3 -2.44 2 -3
0.13 -196 182 -949 -12 2 -3 -2.44 2 -3
0.13 -196 182 -949 -12 2 -3 -2.44 2 -3
0.19 -195 181 -953 -4 -1 -2 -2.44 -1 -2
0.19 -195 181 -953 -4 -1 -2 -2.44 -1 -2
0.25 -196 180 -954 2 0 -5 -2.44 0 -5
0.25 -196 180 -954 2 0 -5 -2.44 0 -5
0.25 -196 180 -954 2 0 -5 -2.44 0 -5
0.31 -197 185 -952 3 -3 -5 -2.44 -3 -5
0.31 -197 185 -952 3 -3 -5 -2.44 -3 -5
0.37 -194 183 -951 -13 5 0 -2.44 5 0
0.37 -194 183 -951 -13 5 0 -2.44 5 0
0.44 -198 181 -952 6 -3 -6 -2.44 -3 -6
0.44 -198 181 -952 6 -3 -6 -2.44 -3 -6
0.5 -197 183 -953 7 -3 -8 -2.44 -3 -8
0.5 -197 183 -953 7 -3 -8 -2.44 -3 -8
0.5 -197 183 -953 7 -3 -8 -2.44 -3 -8
0.56 -195 185 -952 -4 2 -3 -2.44 2 -3
0.56 -195 185 -952 -4 2 -3 -2.44 2 -3
0.63 -199 180 -954 -8 1 -2 -2.44 1 -2
0.63 -197 181 -950 6 -1 -8 -2.44 -1 -8
0.63 -197 181 -950 6 -1 -8 -2.43 -1 -8
0.75 -194 185 -949 -6 1 -2 -2.43 1 -2
0.75 -194 185 -949 -6 1 -2 -2.43 1 -2
0.75 -194 185 -949 -6 1 -2 -2.43 1 -2
0.81 -199 182 -952 4 0 -5 -2.43 0 -5
0.81 -199 182 -952 4 0 -5 -2.43 0 -5
0.87 -194 184 -953 1 -2 -6 -2.43 -2 -6
0.87 -194 184 -953 1 -2 -6 -2.43 -2 -6
0.87 -194 184 -953 1 -2 -6 -2.43 -2 -6
0.94 -197 185 -954 -9 2 -3 -2.43 2 -3
0.94 -197 185 -954 -9 2 -3 -2.43 2 -3
1.0 -196 177 -956 2 0 -6 -2.43 0 -6
1.0 -196 177 -956 2 0 -6 -2.43 0 -6
1.06 -199 189 -949 1 -1 -4 -2.43 -1 -4
1.06 -199 189 -949 1 -1 -4 -2.43 -1 -4
1.12 -196 180 -954 -4 1 -5 -2.43 1 -5

In cocnlusion, I want to save in a txt file some sensor data from the pixhawk using a Raspberry pi running this code. I know that the sensor onboard are capable of higher frequencies that what I’m reading from the serial port.

Is there another way to obtain these values from another source?

In the .log files, the frequencies observed are higher, meaning that is seems posible to obtain what I want.

Any help on that?

Thank you