Simple question : Access Height of a Rangefinder

Hi all,

I’m trying to get the height value of a height sensor, which is wired on the I2C port of a Pixhawk. I want to compute a gain scheduling controller depending on the height of my vehicle. I am using the Arduplane code.

If I want to get the height value in cm or mm, can I call state.distance_cm() in for exemple Attitude.cpp? And will it return me the measured height of the sensor?

In more details I would like to write a stabilizing function in Attitude.cpp and say something like:

if(state.distance_cm() > particularValue){
UseThisController();
}
else{
UseTheOther();
}

Hope it’s clear :wink:

Thanks

Best

Valentin