Attitude or position at more than 20hz

I’m having a problem getting the attitude at a faster rate than the default… I’m using dronekit, python and a raspberry pi connected to a pixhawk via serial 2 port (telemetry 2).

I want attitude or position, rc channels at 50hz.

First I’m changing the parameters via mavproxy.py doing the “param load file.param”… and they look like:

changed SR2_EXTRA1 from 4.000000 to 50.000000
changed SR2_EXTRA2 from 4.000000 to 50.000000
changed SR2_EXTRA3 from 4.000000 to 0.000000
changed SR2_EXT_STAT from 4.000000 to 0.000000
changed SR2_PARAMS from 10.000000 to 0.000000
changed SR2_POSITION from 4.000000 to 50.000000
changed SR2_RAW_CTRL from 4.000000 to 0.000000
changed SR2_RAW_SENS from 4.000000 to 0.000000
changed SR2_RC_CHAN from 4.000000 to 0.000000

Then my script just prints the attitude in a while loop and waits for 0.02 (50hz…):

while True:
        print "%s" % vehicle.attitude
        time.sleep(0.02)

And my result is something like this as output:

STABILIZE> api start /home/pi/DronePilot/pix-logdata.py
STABILIZE> Attitude:pitch=-0.184485912323,yaw=2.69814491272,roll=0.0249422099441
Attitude:pitch=-0.184485912323,yaw=2.69814491272,roll=0.0249422099441
Attitude:pitch=-0.18460611999,yaw=2.68849396706,roll=0.0253130663186
Attitude:pitch=-0.18460611999,yaw=2.68849396706,roll=0.0253130663186
Attitude:pitch=-0.18460611999,yaw=2.68849396706,roll=0.0253130663186
Attitude:pitch=-0.18460611999,yaw=2.68849396706,roll=0.0253130663186
Attitude:pitch=-0.18460611999,yaw=2.68849396706,roll=0.0253130663186
Attitude:pitch=-0.18460611999,yaw=2.68849396706,roll=0.0253130663186
Attitude:pitch=-0.18460611999,yaw=2.68849396706,roll=0.0253130663186
Attitude:pitch=-0.18460611999,yaw=2.68849396706,roll=0.0253130663186
Attitude:pitch=-0.18460611999,yaw=2.68849396706,roll=0.0253130663186
Attitude:pitch=-0.18460611999,yaw=2.68849396706,roll=0.0253130663186
Attitude:pitch=-0.18460611999,yaw=2.68849396706,roll=0.0253130663186
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184569865465,yaw=2.67855548859,roll=0.0254606325179
Attitude:pitch=-0.184660226107,yaw=2.66909885406,roll=0.0252662654966
Attitude:pitch=-0.184660226107,yaw=2.66909885406,roll=0.0252662654966

Its on average 12 same readings each 0.02 seconds, so… its working at something like 4hz… that means it is not changing the parameters… is there anything I can do, to get 50hz attitude readings?

I also tried to change those parameters via apm planner… but so far, same result. Apparently the changes I made to SR2 are never applied… Maybe its hard coded??

I’ll really appreciate some help.

Cheers!

Your delay needs to be 0.02-time to display print statements. Also how multithreaded is drone kit, you are probably sleeping the thread and getting no updates.

Did you check MAVLink Inspector widget in APM Planner as it will show you the Hz messages are being received at. Look in the Tools Widgets menu with advanced mode enabled.

Ps. You may need to check the granularity of the sleep method. It may be longer than you think, you might only need to pass it sleep(1) just to pause the thread long enough, but no longer. And calculate Hz received only on messages being changed which is hard with the vehicle API as it changes the value only if it changes not if a message was sent