I have tried to figure out how to get the distance from two different rangefinders in my lua script, but I am just not bright enough. Both have readings and work.
Which code do I have to use in order to get both readings?
“rangefinder:distance” or “RangeFinder_State_ud:distance()” seems to be the method, but I cannot see how you access multiple.
I tried
local rf1_dist = rangefinder:distance(0)
local rf2_dist = rangefinder:distance(1)
to no avail.
I am sure this is trivial and would greatly appreciate any help!
There is no such binding, rangefinder:distance(). The rangefinder object expects orientation, not instance number as an argument to rangefinder:distance_cm_orient().
Thank you for your help! Of course I did take a look in the provided example, however I was unable to get readings from two rangefinders. I got it to work now with following code:
local backend_1 = rangefinder:get_backend(0)
local backend_2 = rangefinder:get_backend(1)
This give me the readings of both rangefinders.
Maybe I should add, that I want to use two downward facing rangefinders for altitude control. As I have understood it, AP does not have this functionality yet. I am trying to create a script that fuses the inputs of both to get perfect altitude control when flying low. (Big drone, hence two rangefinders)