Inverted pendulum project - need some input

Hi,
I'm working on an 1d inverted pendulum project right now. It would be awesome if any arduino experts/students could read it and give ANY input. I'm a beginner when it comes to arduino, so no matter how basic your advice is, it is really appreciated.

So my inverted pendulum is really a 1d pendulum and not a self-balancing robot.

My inverted pendulum will not be moving on a cart but on a bar. I took an old ink-jet printer with a stepper motor, removed the useless parts and put the home-made pendulum in the place where the cartridge was (printhead assembly). So the stepper motor moves the belt which moves the printhead assembly left and right on the stabilizer bar.

Picture with printer parts for easier visualisation:

Components I am using:
Arduino nano
6 DOF IMU - MPU-6050 -
A4988 Stepper Motor Driver
Voltage converter to run the stepper on 12v via USB

So far I have been able to properly connect and read the MPU-6050 data. I have also managed to connect the stepper with the driver and control it via arduino. So I can say all my parts are working and they are connected, now comes the hard part of translating the MPU data and using it with a PID regulator to stabilize the pendulum.

And this is where things get rough. I have been trying to translate and use this Kalman filter code for the MPU - GITHUB CODE

Next step is understanding that code and using its output: kalAngleY, kalAngleX to control the stepper for stabilization.
I have read about Kalman filter in general and the Kalman.h used in this code but i still don't know what exactly are those two values (deg/s, just deg?)

Should I use the arduino PID regulator to control the assembly? Should I mathematically describe this system, is it necessary, will it help? Or maybe I should determine the PID parameters by trial and error?

I am interested in anything you can tell me about using the Kalman filter data to determine the movement of the assembly, any tips or trick you feel could be helpful, any flaws you see in this system as a whole.

As I continue to work on it I will post some updates here with some new questions, the community were very helpful to me before, thank you :slight_smile: