There are possibilities to work auto with the advanced avoidance library.
I suggest you look at work from @rishabsingh3003 on that matter.
I think it would be better if you open a thread at discuss.ardupilot.org as it is not directly related to cubepilot.
Hi, in Copter 4.1 you can do this via Lua scripting. As far as I have understood, you want to switch from Auto -> Loiter when an obstacle is detected?
I have done a similar script in the past and I think I might be able to find it… let me know if you need it.