The solution is, the flight controller must record that initial position and velocity when the motors are first started for take off.
If the drone is sitting on the ground, that's easy enough. That spot becomes the zero location. And, since it's sitting without moving on the ground, the flight recorder marks that spot with zero velocity.
With those items properly initialized, from there on the accelerations precisely measured by the IMU can be used to integrate backwards to establish current velocity and position at any moment in time.
Except...
Let's say the acceleration plot of the x-axis alone looks more like this.
Integrating once to get velocity is already a lot more complicated. Integrating twice to establish position is going to be a lot less trustworthy.
Now consider that, when launching off my hand, I can't guarantee I was holding the drone perfectly motionless. Its position at time zero was a little wobbly. Its velocity certainly wasn't zero either.
The flight controller runs its "fusion" calculations when fed SIX separate degrees of freedom based on the IMU's measurements of linear acceleration in the x, y, and z axes, and rotational accelerations in the pitch, roll, and yaw axes.
If the drone isn't sitting perfectly still (handheld, or bouncing in a boat) when all those axes are initialized, it has a significant effect on the accuracy of any subsequent dead-reckoning calculations. And those errors propagate exponentially the longer the time runs from there onwards.
The flight controller can probably navigate relatively accurately by dead-reckoning alone based on the input from nothing other than the IMU, for a short period of time starting from properly zeroed initialization.
But, that's what the other sensors are for. The GPS marks an actual starting position on a global map, and the GPS is polled by the flight controller at some frequency to continuously update actual position and actual velocity, so the accelerations measured by the IMU and their integrations can be periodically verified and updated.
It's the same for the vertical z-axis accelerations measured by the IMU. The IMU can only measure acceleration. Any change in acceleration can be integrated backwards to determine velocity, and integrated a second time to calculate vertical position. But that can only be put to use accurately by the flight controller if it knows with certainty what the initial upward velocity was, and what the initial vertical position was.
For that it relies on updates from the barometric sensor. The flight controller near-instantly calculates height based on what the IMU is telling it, but it confirms whether that height has changed as predicted, or remained the same as predicted, by periodically polling the barometric sensor.
If the barometric pressure hasn't changed, the flight controller knows its height hasn't changed. If the IMU calculated height has drifted, due to roundoff error, from what the barometric sensor is showing, the flight controller corrects to what the barometric altimeter is currently indicating.
If the flight controller were instead taking its cue from the infrared sensor, the response would be entirely different. Unless the drone is flying over perfectly level ground, the distance measured by the infrared sensor is constantly fluctuating as the drone passes over fluctuating terrain features.
If the flight controller was polling the infrared sensor height to verify and correct the height calculated from the IMU acceleration measurements, the drone should be constantly raising or lowering its height, effectively causing the drone to do Terrain Following as it tracks the elevation changes below.
As I showed in my videos, the drone never responds to any changes measured by the infrared height sensors, unless Landing Protection is triggered when sensing anything within 0.5m (2ft).
If the drone is sitting on the ground, that's easy enough. That spot becomes the zero location. And, since it's sitting without moving on the ground, the flight recorder marks that spot with zero velocity.
With those items properly initialized, from there on the accelerations precisely measured by the IMU can be used to integrate backwards to establish current velocity and position at any moment in time.
Except...
Let's say the acceleration plot of the x-axis alone looks more like this.
Integrating once to get velocity is already a lot more complicated. Integrating twice to establish position is going to be a lot less trustworthy.
Now consider that, when launching off my hand, I can't guarantee I was holding the drone perfectly motionless. Its position at time zero was a little wobbly. Its velocity certainly wasn't zero either.
The flight controller runs its "fusion" calculations when fed SIX separate degrees of freedom based on the IMU's measurements of linear acceleration in the x, y, and z axes, and rotational accelerations in the pitch, roll, and yaw axes.
If the drone isn't sitting perfectly still (handheld, or bouncing in a boat) when all those axes are initialized, it has a significant effect on the accuracy of any subsequent dead-reckoning calculations. And those errors propagate exponentially the longer the time runs from there onwards.
The flight controller can probably navigate relatively accurately by dead-reckoning alone based on the input from nothing other than the IMU, for a short period of time starting from properly zeroed initialization.
But, that's what the other sensors are for. The GPS marks an actual starting position on a global map, and the GPS is polled by the flight controller at some frequency to continuously update actual position and actual velocity, so the accelerations measured by the IMU and their integrations can be periodically verified and updated.
It's the same for the vertical z-axis accelerations measured by the IMU. The IMU can only measure acceleration. Any change in acceleration can be integrated backwards to determine velocity, and integrated a second time to calculate vertical position. But that can only be put to use accurately by the flight controller if it knows with certainty what the initial upward velocity was, and what the initial vertical position was.
For that it relies on updates from the barometric sensor. The flight controller near-instantly calculates height based on what the IMU is telling it, but it confirms whether that height has changed as predicted, or remained the same as predicted, by periodically polling the barometric sensor.
If the barometric pressure hasn't changed, the flight controller knows its height hasn't changed. If the IMU calculated height has drifted, due to roundoff error, from what the barometric sensor is showing, the flight controller corrects to what the barometric altimeter is currently indicating.
If the flight controller were instead taking its cue from the infrared sensor, the response would be entirely different. Unless the drone is flying over perfectly level ground, the distance measured by the infrared sensor is constantly fluctuating as the drone passes over fluctuating terrain features.
If the flight controller was polling the infrared sensor height to verify and correct the height calculated from the IMU acceleration measurements, the drone should be constantly raising or lowering its height, effectively causing the drone to do Terrain Following as it tracks the elevation changes below.
As I showed in my videos, the drone never responds to any changes measured by the infrared height sensors, unless Landing Protection is triggered when sensing anything within 0.5m (2ft).