How much code can we modify?

Hi there,
I am very new to APM and just wondering how much code can be modified? I know it’s open-sourced but I’m not very familiar with this kind of hardware and need some suggestions.

In short, what I need to do is to rewrite the controller for a fixed wing UAV to fly autonomously, by using PID or predictive control. Will the APM or PX4 allow me to do this? Also what are the differences between PX4 and APM?

Thank you in advance.