All My Servos provides a visualization of the effect of gravity on the IMU. In the video the robot is rotated in the following sequence:
Right (90 deg), left (90 deg), backwards (90 deg), forwards (180 deg)
The input from the accelerometer is noisy and in order to isolate the effect of gravity (which is constant) the data is sent through a low pass filter. This cancels out any signals which are only present for a short time. As the robot rotates, the effect of gravity is transferred from one axis to another. This change is not instant, it's more like pouring water from one container into another. From the default position the pitch and roll of the robot can be inferred by looking at the proportion of the gravitational effect on each axis but as the yaw angle changes, the gravitational effect is not transferred. However if the robot is rotated forward 90 deg it is now the roll angle which cannot be calculated. AllMyServos leverages this to switch axis as one becomes more authoritative than another.
Once an IMU crosses the 90 deg mark on either the pitch or roll axis, an edge case emerges. An edge case is a situation which arises only outside of normal operation. In isolation both roll and pitch axis will register being upside down which is correct but if we tried to apply this rotation to a model it would invert it twice (180 deg roll + 180 pitch = original position + 180 deg yaw). The model would not be upside down. AllMyServos will counter this by describing being upside down as 180 deg on either axis, offset by the other axis.
Accelerometer data is useful for inferring the general orientation of a robot in relative space but it is insufficient to calculate a rotation in world space.
A task which only involves relative space would be turning a robot on it's side and using the accelerometer data to stand up. The goal is getting the entire effect of gravity onto the z axis and the direction it faces once stood, doesn't matter.
A task which involves world space would be turning a robot away from you and running an algorithm to turn back. The goal is to undo the yaw but this information is missing from the accelerometer data.
A gyroscope which is often integrated into an IMU will track this information. Combining the two types of data is called a complementary filter. This is demonstrated in the Orthographic Representations. As long as the original yaw is recorded and the gyroscope information is tracked during the rotation, the robot will have the relevant data available but gyroscope data is relative to the last measurement so if it isn't being polled it cannot account for any rotation during that time.
A magnetometer is sometimes integrated with an IMU or can be added on. This tracks the earths magnetic field like a compass. This would allow the robot to mark a yaw position and be turned off completely during the rotation. When the robot is turned back on, it would be able to return to the original yaw. This might be described as an offset from north for example, which is always the same. The MPU6050 doesn't include one of these and currently magnetometers are not supported by AllMyServos.