Hey,

As a part of an experiment, I needed to swap the Multi-ranger and Flow (v2) decks. That means, the Flow deck is on top of the quad, and the Multi-ranger now points to the ground.

The hardware flip worked, and I am left with flipping one thing in the firmware: I need the altitude estimator to use the sensor of the Multi-ranger because as mentioned, now the Multi-ranger points to the floor.

However, after starting to delve in the code, starting from this file, I see that there is a `state` parameter. I tried to find where the distance from the ground is inserted into `state`, but couldn't find it. If I'll know where it is, I will be able to make it take the data from the Multi-ranger instead of the Flow deck (because normally, the Flow deck points to the ground).

Any other methods of achieving this goal will be welcome.

Thanks a lot!

## Using Multi-ranger deck for altitude control

### Re: Using Multi-ranger deck for altitude control

You need to push the range in the kalman filter as TOF measurement. So you need to disable pushing the range in the zranger driver: https://github.com/bitcraze/crazyflie-f ... #L139-L150 and copy similar code in the multiranger driver: https://github.com/bitcraze/crazyflie-f ... ger.c#L111.

All ranges are pushed in a central module, range.c, and ideally that should be the place where measurement are pushed to the Kalman filter, this way you would not have to copy-paste the Kalman push code. I am not so sure how that would look like exactly but I am creating a ticket to track the idea. In the mean time, copy-pasting the code like I described should work for you to achieve height control with reverse sensors.

All ranges are pushed in a central module, range.c, and ideally that should be the place where measurement are pushed to the Kalman filter, this way you would not have to copy-paste the Kalman push code. I am not so sure how that would look like exactly but I am creating a ticket to track the idea. In the mean time, copy-pasting the code like I described should work for you to achieve height control with reverse sensors.

### Re: Using Multi-ranger deck for altitude control

Hi, thanks for your reply! Sorry for my late response.

So I managed to do the copy-paste you suggested. I couldn't test my code on a real Crazyflie, but it seems the code has compiled without errors. I will be able to test the code on a physical Crazyflie only on Wednesday, I will update here.

Thanks again!

So I managed to do the copy-paste you suggested. I couldn't test my code on a real Crazyflie, but it seems the code has compiled without errors. I will be able to test the code on a physical Crazyflie only on Wednesday, I will update here.

Thanks again!

### Re: Using Multi-ranger deck for altitude control

Hi, sorry for my late reply.

So the copy-paste you suggested worked, and the height estimator does use the Multi-ranger deck now and not the Flow deck.

However, we encountered another problem: the quadcopter is commanded to take off and land. It takes off kinda smoothly, but then it starts to drift in one direction (negative X-axis). We think that might be related to the fact that now, for velocity calculations, the Flow deck uses the height measurement from the Multi-ranger (because that's where the height estimator takes its data from). The problem is that the numbers diverge and become very large, very quickly (probably).

So, how can we make the Flow deck use

Thanks!

So the copy-paste you suggested worked, and the height estimator does use the Multi-ranger deck now and not the Flow deck.

However, we encountered another problem: the quadcopter is commanded to take off and land. It takes off kinda smoothly, but then it starts to drift in one direction (negative X-axis). We think that might be related to the fact that now, for velocity calculations, the Flow deck uses the height measurement from the Multi-ranger (because that's where the height estimator takes its data from). The problem is that the numbers diverge and become very large, very quickly (probably).

So, how can we make the Flow deck use

*its*Z-ranger, and not the Multi-ranger's Z-ranger, for X- and Y-axes velocities calculations?Thanks!

### Re: Using Multi-ranger deck for altitude control

Actually, after a second look, we see that the Flowand the height estimator does use the Multi-ranger deck now and not the Flow deck.

*does*influence the height estimator. If we graph `stateEstimate.z`, it changes with influences from the Flow deck's Z-ranger:

Here is the graph of `StateEstimate.z` when the quad is stable on the table, Flow deck is completely covered: https://imgur.com/a/x2aG85i

Quad stable on the table (Multi-ranger looking down), Flow deck is completely uncovered: https://imgur.com/a/XVe6x0J

Quad stable on the table, an object passes above the Flow deck a few times: https://imgur.com/a/ZEEMQzV

The spike you see in the graph happens when the Flow deck was briefly covered.

While the spikes aren't large, they do seem weird because I did comment-out lines 136-147 in `zranger2.c` as you have suggested.

So how can we fix this problem (and the one above)?

Thanks a lot!