I’m working on integrating a Nanoradar MR72 with ArduPilot (Copter 4.6.2) for obstacle avoidance, and I’ve run into an issue where the Lua proximity API returns incorrect values whereas the Mission Planner Proximity UI shows the correct values.
My final goal is the fly the drone in AUTO mode and when an obstacle is too close it should switch to LOITER mode.
Here is a minimal Lua test script the should print the distances and angle of the detected obstacles by the MR72:
function update()
local count = proximity:get_object_count()
gcs:send_text(0, "Objects: " .. tostring(count))
for i = 0, count - 1 do
local dist_cm, angle = proximity:get_object_angle_and_distance(i)
if dist_cm and angle then
gcs:send_text(0, string.format("Obj %d: %.2f m at %.1f°", i, dist_cm/100, angle))
else
gcs:send_text(0, string.format("Obj %d: invalid", i))
end
end
return update, 100
end
return update()
Hello!
I am using the Teraranger Hub Evo 360-degree sensor.
When I tried your code, I found that the values for dist_cm and angle were switched—the sensor angle (eight directions, every 45°) was assigned to dist_cm, and the distance in meters was assigned to angle.
I hope this information helps.
Hello!
Thanks for your reply! You are right in the test code I switch the angle and distance, thanks for pointing that out.
But even with switching theses, I get strange readings.
On your example picture you also have distance readings that are different from the proximity UI, for example on the UI you have some sectors with a distance of 5.3m or more and these don’t seem to appear in your logs. Maybe I am missing something trivial but why are you not getting the same readings between your log messages and the proximity UI?
In my screenshot, the measurement error was around 0.1 m, so your program appeared to be working correctly.
In your screenshot, however, the UI window shows a detection of 20.8 m at 45°, while the message indicates 13.1 m at 31°.
It’s possible that the UI displays the distance recognized by the flight controller (FC), while the values referenced in Lua come directly from the sensor. (I haven’t read the code in detail, so I might be wrong.)
If PRX_LOG_RAW = 1 is enabled, both values are recorded in the bin log as PRX and PRXR.
My sensor consists of eight individual rangefinders facing different directions, so the raw sensor readings are almost directly recognized by the FC as obstacle distances.
Your sensor, on the other hand, can scan over a range of angles at once, so the difference may arise when the scanned data is converted into specific directions such as 45° or 315°.
I don’t have a sensor like the MR72 to verify this myself, but I hope this information helps you.