Pitch/Roll/Yaw Angle Estimated data in ulog files

I’m using PlotJuggler and FlightPlot for log analysis. I managed to get almost everything I need compared to Flight Review tool.
I got Pitch/Roll/Yaw Rates Setpoint from vehicle_rates_setpoints
I got Pitch/Roll/Yaw Rates Estimated from vehicle_angular_velocity
I got Pitch/Roll/Yaw Setpoint from vehicle_attitude_setpoint
But I can’t find anything that matches Pitch/Roll/Yaw Angle Estimated in ulog file as it is shown in Flight Review tool.
Do I need some kind of formula to calculate it?
I tried to look at Flight Review sources ( https://github.com/PX4/flight_review/blob/master/plot_app/configured_plots.py ) and it was confusing because it seems like there should be fields called roll, pitch, yaw in ‘vehicle_attitude’ but there are only following fields: q[0],q[1],q[2],q[3],delta_q_reset[0],delta_q_reset[1],delta_q_reset[2],delta_q_reset[3],quat_reset_counter.
q[0],q[1],q[2],q[3] are somehow similar to Pitch/Roll/Yaw Angle Estimated but not the same.
So how do I get Pitch/Roll/Yaw Angle Estimated from my ulog files?

There’s also vehicle_local_position/yaw that is very similar to Yaw Angle Estimated. But not exactly, and there’s no Pitch or Roll fields.

Let me ping @facontidavide here, I’m sure he can help :wink:

Let me ping @facontidavide again and hope for help.
I’m absolutely shure that there’s an answer because I can see angle estimated in Flight Review online tool, the first graph for roll. The only question is how do they get it from ulogs.

So I have an answer for my question.
For FlightPlot you should select vehicle_attitude/q[0],q[1],q[2],q[3] from field list, then select processor EulerFromQuaternion and voilà! you have Pitch/Roll/Yaw angles just like in Flight Review.
For PlotJuggler it’s more complex, you should implement the conversion with our own functions.
Thanks to wiki article, I made the following finctions in Lua.

QuaternionToRoll:

-- value is not used but should be mentioned to trick PJ check
z = $$vehicle_attitude/q.00$$
y = $$vehicle_attitude/q.01$$
x = $$vehicle_attitude/q.02$$
w = $$vehicle_attitude/q.03$$
t1 = 2 * (w * x + y * z)
t2 = 1 - 2 * (x^2 + y^2)
return math.atan(t1, t2)

QuaternionToPitch:

-- value is not used but should be mentioned to trick PJ check
z = $$vehicle_attitude/q.00$$
y = $$vehicle_attitude/q.01$$
x = $$vehicle_attitude/q.02$$
w = $$vehicle_attitude/q.03$$
sinp = 2 * (w * y - z * x)
pitch = 0
if math.abs(sinp) >= 1 then
    if sinp >= 0 then
        pitch = math.pi / 2
    else
        pitch = math.pi / -2
    end
else
    pitch = math.asin(sinp);
end
return (-1) * pitch

Here I had to invert pitch value to match Flight Review graph.

QuaternionToYaw:

-- value is not used but should be mentioned to trick PJ check
z = $$vehicle_attitude/q.00$$
y = $$vehicle_attitude/q.01$$
x = $$vehicle_attitude/q.02$$
w = $$vehicle_attitude/q.03$$
t1 = 2 * (w * z + x * y)
t2 = 1 - 2 * (y * y + z * z)
return math.atan(t1, t2)

Yaw angle here is also inverted and has something like 180° offset, but I decided to leave it this way.

1 Like