Questions about the sketch of my self balancing robot

hello everyone, I need your help.
I assembled for a month my first self balancing robot; after studying in depth the hardware issues, and I think I have reached a good goal for the hardware.
However I am afraid that the sketch that I have created has something wrong ... But to be sure I need your help, and I am very grateful for your advice and comments.

Robot features:

  • Arduino UNO
  • MPU_6050 = accelerometer and gyroscope, implemented with kalman filter gives me the correct angle.
  • GY-271 = magnetometer, for future projects
  • LCD 16x2
  • L298N motors driver
  • 2x 12v 200rpm geared motors

The sketch uses a PID control, and the PID constants are set with three 10K potentiometers. I tried to adjust the constants with method, but I have not reached the result that the robot remain stable in equilibrium =( =( =(
Please help me, it's really frustrating not to get good results and have wasted hours and hours to try ...

complete code in the link, thanks Pauls!

P.S: libraries needed: I2C and kalman.h

NUOVO_RIPRESO.ino (11.4 KB)

Here is the code:

Not all of it, by a long shot. And, do not paste another snippet in another post.

Use the Additional Options link to attach ALL of your code as ONE file.

Ok PaulS thanks