How to control 4 motors which are conected to a flight controller using Raspberry Pi?
It seems that the KK 2.1.5 flight controller has four separate, "old fashioned" PPM inputs, while most modern controller use a serial link with the receiver, such as DBUS.

Your best bet would be to first implement a way for the raspi to generate the four PPM signals. This can surely be done with a ton of different, already written and proven libraries. Your interface would then just be a file, where you write the value you want the PPM signal to go to, and this can be done with pretty much anything you want on the raspi.

So basically your program on the raspberry would not run the control loop, that stays on the FC, but just some sort of autopilot, high level control loop, that would send just "wanted attitudes" to the FC, pretty much like you would do with a standard TX/RX setup.

disclaimer: bear in mind that the raspberry pi is not a real time system. This can lead to a number of problems, inherent to the system you want to setup, on top of the "normal" problems like software bugs, or hardware failures.

It is your primary responsability to make sure your system is safe for you, for others, and for everything that is around you. Also, make sure to adhere to your local regulations about UAVs.