How to replace mc_att/rate_control and other modules for quadrocopter?

Are you willing to share the code if you are successful?

You mean you want to use ekf2 and rc as input, and use motor speed as output instead of going through the mixer, right?

If so,The output of the current angular velocity controller is mixed here and finally output to esc

As for which module to replace, it depends on which loop you use lqr control.If you plan to use the lqr algorithm in angular velocity control, then just replacing/modifying mc_rate_control is enough