Implementing Collision Avoidance with Range Finders in SITL

Hello,

I am currently attempting to configure obstacle avoidance for a copter in SITL using MissionPlanner 1.3.68 and ArduCopter 3.7.0. I have configured the following parameters via MissionPlanner:

  • RNGFND#_ORIENT = 25 ( down )
  • RNGFND#_PIN = 0
  • RNGFND#_TYPE = 1 ( analog )
  • PRX_TYPE = 4 ( use rangefinders for proximity sensors )
  • AVOID_ENABLE = 7 ( use sensors for collision detection )
  • AVOID_BEHAVE = 1 ( stop when encountering an obstacle )

To check if the range finder was enabled and was reporting valid input I graphed RANGEFINDER.distance and was able to see accurate readings on takeoff and landing. Additionally, when I set the rangefinder to be orientated forward instead of down and enabled the radar view in MissionPlanner via ctrl-f, I was able to see the rangefinder field in front of the drone.

It is worth noting that the drone was flown in guided mode. Upon reading several doc pages on collision detection, I believe collision avoidance is available in guided, loiter, and a few other modes.

However, in both cases, the drone crashed when encountering an obstacle ( SITL console reported APM: Crash: Disarming ). In the case of the downward facing sensor, we told the drone to fly straight into the ground ( using right click - fly to command on the sitl map window ) which it did, instead of stopping before crashing. With the forward facing sensor, we told the drone to fly horizontally outwards and when it encountered an obstacle in front of it, it crashed again instead of stopping in front of the obstacle.

EDIT
Upon further investigation, I have found out how to run collision avoidance while using fences ( I believe ).
When I enable fences via FENCE_ENABLE = 1 and set AVOID_ENABLE = 1 to use those fences as an obstacle source, the drone does exhibit the behavior of AVOID_BEHAVIOR. So I suppose the new question should rather be if I am missing a parameter to enable the rangefinders to actually detect the SITL environment or if it simply not possible for them to detect the environment in SITL. In which case, I wonder if it is possible to add obstacle to the SITL world. I can add objects through gazebo, but I do not believe they can be sensed by the rangefinders simulated in SITL. I have yet to finish running tests on this possibility, however.

Any help with resolving this issue would be much appreciated.
Thanks,
Varun