Human tracking guidance using pymavlink - Delay problem between attitude and guidance commands

Hi,

We want to guide drone using camera feed to track a human. We use pymavlink libraries to get drone attitude and send guidance commands as follows. In the below commands, “guiCmd” struct is guidance commands and “getAttFreq” is 30 Hz.


connection.mav.set_position_target_local_ned_send(
int(1e3 * (currentTime - bootTime)), # ms since boot
target, component, mavutil.mavlink.MAV_FRAME_BODY_OFFSET_NED, type_mask,
guiCmd.x,guiCmd.y,guiCmd.z,guiCmd.vx,guiCmd.vy,guiCmd.vz,guiCmd.ax,guiCmd.ay,guiCmd.az,guiCmd.yaw,guiCmd.yawSpeed)


message = connection.mav.command_long_encode(target, component, mavutil.mavlink.MAV_CMD_SET_MESSAGE_INTERVAL, 0, 30, 1000000/getAttFreq, 0, 0, 0, 0,0)
connection.mav.send(message)
attitude = connection.recv_match(type=‘ATTITUDE’, blocking=True)


To simply test the pymavlink libraries, we sent a yaw rate command (using the set_position_target_local_ned_send) and compare it with the achieved yaw rate (using the command_long_encode). However there is a long delay (about 0.35 seconds) between the yaw rate command and achieved yaw rate. Plots are in the following folder.

https://drive.google.com/drive/folders/13r8OB-cjlga2L9iEng6jpUtKdwVvFUhW?usp=sharing

We are receiving attitude and sending commands using telemetry. In other words, guidance python code runs on an offboard windows computer.

We can not decrease 0.3-0.35 seconds delay although we tried different things such as running attitude loop faster than main loop via time sleeps or using threads for each function, etc.

When we look at the yaw rate repsonse of the drone to RC commands, delay is much smaller about 50-60 ms, so drone’s own yaw rate response is quite good without pymavlink commands.

Do you have any suggestions on this topic?