Safe trace to HOME

Hi all,

I am trying to write safe way to get back to HOME from any position avoiding some of places that lead to collision. Can I do that? I want to call function HOME() and have everything there (checking current position, how far is restricted area etc.)

Thank you for your help in advance