Split it into 2 parts, the PID control, and the autotuning,
Each of these have a number of approaches, but lets say we stick to the normal PID control
So you now want to auto-tune it, the most common approach is called "step response", where it fixes the output, wait for it to stabilize, change the output by a step of x% wait for it to stabalise, and using the data between those 2 points to work out which values you want (sometimes PI or PD control can behave better than PID)
I would begin by putting together the PID or reusing an existing one, you can do auto-tuning with normal PID libraries,