Autonomous plane with obstacle avoidance

I am working on a fixed wing and want to give it an automous flight. I also want to do obstacle detection during the automous flight and then avoid it. Will sending MAV link commands using raspberry pi when plane is in automous mode do the job for me? Kindly help me achieving this goal.