Mavlink FailureDetector Logic

Hello everyone.

How does Mavlink decide that an event is categorized as MAV_STATE_CRITICAL, MAV_STATE_EMERGENCY, or freefall condition?

I think this is needed to expect the UAV’s state, hence it could be coupled with another system. I’ve searched around the Documentations, as well as the Mavlink’s Github, but didn’t found the FailureDetector algorithm. Does someone knows where is it?

Does this also have relationship with QGroundControl’s params? Such as if the UAV simply exceeding the maximum pitch angle.

Thank you very much for your response.