self balancing unicycle

I am trying to build a self balancing unicycle using a Hub Motor, Arduino Uno, MPU6050 and QS909 motor driver. I have used the below program for reference but the said program is build on BTS7960 motor driver. So to make it work with the QS909 motor driver what are the necessary changes I have to do in the programs. Guys I am really stuck in a jam,Pl. any help would be useful.
I have tried to delete the files #include <LiquidCrystal_I2C.h> and #include <Adafruit_NeoPixel.h>, so that the program fits into the 9000 words limit as it is not necessary for me as well. Guys I have also delete some more part of the program to limit it to 9000 words the entire program is available on github link. Pl. guide me in which ever way possible.

Thankyou

DC 12V-36V 500W Brushless Motor Controller Hall Motor Balanced Car Driver Board -QS909 motor driver

/*

 *Self balancing unicycle *
  

   Web: https://github.com/joneivind
   
  *Connections *
   
  * SENSOR UNO/NANO   MEGA2560 (Same if not specified)
  
  
  //MPU6050 gyro/acc (I2C)
 
  * VCC      +5v        +5v
  * GND      GND        GND
  * SCL      A5         C21
  * SDA      A4         C20
  
  // Motor Driver BTS7960

  * VCC     +5v
  * GND     GND
  * RPWM    D9                  Forward pwm input
  * LPWM    D10                 Reverse pwm input
  * R_EN    D7                  Forward drive enable input, can be bridged with L_EN
  * L_EN    D8                  Reverse drive enable input, can be bridged with R_EN
  * R_IS                        Current alarm, not used
  * L_IS                        Current alarm, not used
  * B+                          Battery+
  * B-                          Battery-
  * M+                          Motor+
  * M-                          Motor-

  // Reset button //

  * SIGNAL  D4
  * GND     GND

  *** Credits *** 
  MPU6050/Kalman filter: https://github.com/TKJElectronics/KalmanFilter
  Medianfilter: http://www.elcojacobs.com/eleminating-noise-from-sensor-readings-on-arduino-with-digital-filtering/

*/

// Library //

#include <ArduinoJson.h>
      #include <Wire.h>
      #include <Kalman.h>
      #include <LiquidCrystal_I2C.h>
      #include <Adafruit_NeoPixel.h>
      #include <avr/power.h>
      #include <PWM.h>

// PID constants //

      float kp = 55.0; // P-value
      float td = 2.0; // D-value
      float bias = 0.0; // Bias value (Base output)
      float setpoint = 81.0; // Setpoint (Balance point)
      
      //#define TUNING // Uncomment if tuning panel is attached


// Output settings //

      float Umax = 255.0;  // Adjust max output 0-255
      float Umin = -255.0; // Adjust Min output 0-(-255)

      int max_roll = 15; // Max degrees from setpoint before motor will stop
      int min_roll = 10; // Min degrees from setpoint before motor will stop


      // Storage variables
      float p_term = 0.0; // Store propotional value
      float d_term = 0.0; // Store derivative value
      
      float error = 0.0; // Sum error
      float last_error = 0.0; // Store last error sum
      
      int output = 0; // PID output
      int total_output = 0; // PID output + throttle_expo
      int pid_output = 0; // PID out in main loop
      float angle = 0;

// Motor driver settings //
      
     // bool motor_direction_forward = false;  // Set motor direction forward/reverse
      int frequency = 4000; // Default motor frequency (in Hz)
      
      int RPWM = 9; // Forward pwm input
      int LPWM = 10; // Reverse pwm input
      int R_EN = 7; // Forward drive enable input
      int L_EN = 8; // Reverse drive enable input*/
      
// Motor control //
        
  /*  void motor(int pwm, float angle){ // pwm = Power, angle = Forward/backward

        if (motor_direction_forward == true){
          if (angle > setpoint){
            pwmWrite(LPWM, abs(pwm));
          }
          else if (angle < setpoint){ 
            pwmWrite(RPWM, abs(pwm));
          }
        }
        else{
          if (angle > setpoint){
            pwmWrite(RPWM, abs(pwm));
          }
          else if (angle < setpoint){ 
            pwmWrite(LPWM, abs(pwm));
          }
        }
      }*/

        // Motorcontroller output
        pinMode(RPWM, OUTPUT); // PWM output right channel
        pinMode(LPWM, OUTPUT); // PWM output left channel
        pinMode(R_EN, OUTPUT); // Enable right channel
        pinMode(L_EN, OUTPUT); // Enable left channel
        digitalWrite(RPWM, LOW); // Disable motor @ start
        digitalWrite(LPWM, LOW);
        digitalWrite(R_EN, LOW);
        digitalWrite(L_EN, LOW);
        
        
        // Add some initial gyro angle values
        for (int i=0; i<100; i++){
          get_angle();
        }

When your code is longer than the 9000 character limit of the forum, the best thing is to attach the sketch file(s). If you click the "Reply" button, you'll see an "Attachments and other settings" link, which will allow you to attach files to a reply.

A link to a GitHub repository is a reasonable idea. That would make it easy to see the changes you make to the code as the discussion proceeds. My concern with the code being hosted externally is that tends to lead to "bit rot" of forum threads as the external resources disappear. Someone coming across this thread while researching, after you deleted your GitHub repository a few years from now, will find the thread to be useless. That would not happen if all the files were hosted here on the forum. I know some forum members also don't like to visit external websites. So I guess I have mixed feelings about that idea.

@pert
Thanks a lot here is the entire program file in which I have to make the necessary changes. Pl. suggest me something on this.

try.ino (29.4 KB)