How to calculate groundspeed

Hello
I use bluerov and am a beginner
I checked that the groundspeed can be seen in the qgc ui, how is the value calculated? I looked at the code for ardusub, but I couldn’t figure it out with my ability.
Thank you for answering my question

Hi @drone_begginer, welcome to the forum

The vehicle dynamics are calculated by an Extended Kalman Filter, which combines the data from each relevant sensor and tries to maximise the consistency/trustworthiness of the output.

Assuming no external velocity/positioning sensors, a fundamental calculation of groundspeed can be performed by using the internal gyroscope and/or accelerometer to determine the angle of the vehicle relative to the direction of gravity, and then integrate accelerometer readings to get a velocity, which is then projected onto the horizontal direction to get speed. In its simplest form consider just a single rotation angle:

From a known side and angle of a right angled triangle, it’s possible to calculate the remaining two side lengths with basic trigonometry