Yaw Query Help

Hi Guys
Recently i’ve been into MAVSDK and PX4 firmware but im almost new to it.
I’ve been reading a lot but I can’t figure out how can I querry the pixhawk to get the current Heading.

In mission planer or qgroundcontrol you can seet heading degrees, usually seen in compass.
I’m trying to use mavsdk or raw mavlink messages to recreate and get the same result.

Thanks
André

Hi,
you can use MAVSDK’s Telemetry API to query the attitude. See attitude_quaternion and attitude_euler_angle. The second call will return an EulerAngle struct containing the current yaw in degrees.

1 Like

But is there anyway way to convert to single degree where north is 0?
I tried this on the simulator JMAV and I was comparing directly to the HUD compass of it and the values are completely different :open_mouth:

I know that they are in radians at least the Euler, the one I tried, but comparing to the simulator it seems way different…

It’s definitely possible. Here is a shot of a quick test:

Although im calculating the value directly from the Quaternion, the EulerAngles you are seeing are most likely in the range of -180/+180 degrees. So you need to convert to 0-360 and it should match.

I’m trying via MAVSDK c++ , yes it gives me between 180 and -180. However by some reason I get delayed results on the command line interface, here’s the code if you want give me a little help…

   while (true) {
    Telemetry::EulerAngle teste = telemetry->attitude_euler_angle();
    std::cout << "Yaw Degrees: " << teste.yaw_deg << std::endl;
}

I get the measurements but if my yaw is suppose at 210 degres… My output still takes time to get the current result