Does anyone know how I can get the GPS track heading to the degree of the drone body heading?
I also noticed this black line in MP keeps changing over time at the same location.

I am using this command to move the drone, but the movement direction in angle is not what I expected.
function vehicle:set_target_velocity_NED(vel_ned) end

The objective I hope to achieve is shown in the picture below.

yaw_cos = math.cos(g_yaw_rad) -- ahrs:get_yaw()
yaw_sin = math.sin(g_yaw_rad)
vel_X = vel * yaw_cos - vel * yaw_sin
vel_Y = vel * yaw_sin + vel * yaw_cos
local target_vel = Vector3f()
target_vel:x(vel_X)
target_vel:y(vel_Y)
target_vel:z(0)
vehicle:set_target_velocity_NED(target_vel)

Is it I need to upgrade the drone to 4.5.5 and above and use gps:gps_yaw_deg?

function gps:gps_yaw_deg(instance) end
function ahrs:get_yaw() end

What you looking for is the gps ground course (the black line represents that in MP). Use gps:ground_course(instance) in LUA. But this is simply calculated from two consecutive position readings. So it is not â€śvalidâ€ť while the vehicle is stationary.

These two borrowed formulas are not ideal in my case. Problem solved.
ahrs:get_yaw() return is with reference to the Earth frame. No other Lua API needed for the new formula.

I notice the problem when I was unable to get these values from the old formula regardless of the angle I input.