I am using pymavlink for communication with our drone.
Our goal is to get the position data of the drone (GLOBAL_POSITION_INT, LOCAL_POSITION_NED). We just focus on LOCAL_POSITION_NED in this example.
After receiving the position message(s) I have some time consuming code which blocks the loop that collects the messages (it would not be a problem if drone messages would get lost while the loop is blocked).
However from the output of a test code i assume that the drone messages are somehow cached on the drone.
The code:
- Sets the message Interval for " LOCAL_POSITION_NED" to 100 microseconds
- in a loop receives messages from the drone
- if the message is LOCAL_POSITION_NED:
- Calculates the “Code time delta” using the python timestamp of the last
LOCAL_POSITION_NED received and the current timestamp - Calculates the “Drone time delta” using the time_boot_ms field of the last
LOCAL_POSITION_NED received and the current LOCAL_POSITION_NED - Sleeps for 78ms
- Calculates the “Code time delta” using the python timestamp of the last
- Prints the deltas
The output shows that after approx. 79.0ms of python time delta between two messages the drone time delta is just 3-5 ms what lets me assume that the drone is caching the messages.
Also after some time (the output is shortened) a peak is visible where the drone “skips” approx. 7 seconds of position data (maybe when the cache is full)?
Can someone verify if the drone is caching data or am I missing something?
If the drone is caching data is it possible to disable the cache? (like I said, i would be ok with “loosing” data)
Thank you in advance.
connection = mavutil.mavlink_connection("com4", dialect='all', mavlink20=1)
connection.recv_match(type='HEARTBEAT', blocking=True, timeout=10)
set_message_interval_and_wait_for_ack(connection, 32, 1_00)
time_since_ned = time.time()
first_tsb = 0
last_tsb = 0
for i in range(0,10000):
msg_ned = connection.recv_match(blocking=False)
if msg_ned is not None and msg_ned.id == 32:
ned_recv_time = time.time()
ned_delta_ms = round((ned_recv_time - time_since_ned)*1000, 0)
tsb = msg_ned.time_boot_ms
tsb_delta = tsb-last_tsb
print("Delta", ned_delta_ms, tsb_delta, tsb, msg_ned.id)
time_since_ned = ned_recv_time
if last_tsb == 0:
first_tsb = tsb
last_tsb = tsb
time.sleep(78/1000)
connection.close()
Output:
Colums (from left to right)
- ned_delta_ms: time delta between current and previous message according to time() delta in code
- tsb_delta: time delta between current and previous message according to drone message time_boot_ms field
- time_boot_ms: value as sent by the drone
- msg.id (32==local_position_ned)
Delta 79.0 3 5436610 32
Delta 79.0 5 5436615 32
Delta 79.0 2 5436617 32
Delta 79.0 3 5436620 32
Delta 79.0 2 5436622 32
Delta 80.0 3 5436625 32
Delta 79.0 5 5436630 32
Delta 79.0 7370 5444000 32
Delta 80.0 5 5444005 32
Delta 86.0 2 5444007 32
Delta 79.0 3 5444010 32
Delta 79.0 2 5444012 32
Delta 79.0 3 5444015 32
Delta 79.0 5 5444020 32
Delta 79.0 2 5444022 32