Problem with ESC and arduino calibration .

I am using this following code which is available online. I am connecting arduino with ESC(Simonk 20-30A) and and that to BDLC motor A2212 and using li-po battery 7.4V 2200mah 25C.

My problem is when I initially start the experiment with my fully charged battery , I enter values like 180(full speed) , 160, 140 ,120 in serial monitor motor speed changes accordingly . But after running experiment for sometime as my battery discharges . The motor configuration changes !! to any of middle values . Like motor speed changes only between 150 to 160(achieves full throttle).and in this case if i try to enter any other value like 180 ,175, 120 , it doesn’t changes its speed.

how do i solve this problem . If I want motor to work at specific speed at specific input independent of
power input .

#include <Servo.h>

// This is our motor.
Servo myMotor;

// This is the final output
// written to the motor.
String incomingString;


// Set everything up
void setup()
{
  // Put the motor to Arduino pin #12
  myMotor.attach(5);

  // Required for I/O from Serial monitor
  Serial.begin(9600);
  // Print a startup message
  Serial.println("initializing");
 
}


void loop()
{
  // If there is incoming value
  if(Serial.available() > 0)
  {
    // read the value
    char ch = Serial.read();
  
    /*
    *  If ch isn't a newline
    *  (linefeed) character,
    *  we will add the character
    *  to the incomingString
    */
    if (ch != 10){
      // Print out the value received
      // so that we can see what is
      // happening
      Serial.print("I have received: ");
      Serial.print(ch, DEC);
      Serial.print('\n');
    
      // Add the character to
      // the incomingString
      incomingString += ch;
    }
    // received a newline (linefeed) character
    // this means we are done making a string
    else
    {
      // print the incoming string
      Serial.println("I am printing the entire string");
      Serial.println(incomingString);
    
      // Convert the string to an integer
      int val = incomingString.toInt();
    
      // print the integer
      Serial.println("Printing the value: ");
      Serial.println(val);
    
      /*
      *  We only want to write an integer between
      *  0 and 180 to the motor. 
      */
      if (val > -1 && val < 181)
     {
       // Print confirmation that the
       // value is between 0 and 180
       Serial.println("Value is between 0 and 180");
       // Write to Servo
       myMotor.write(val);
     }
     // The value is not between 0 and 180.
     // We do not want write this value to
     // the motor.
     else
     {
       Serial.println("Value is NOT between 0 and 180");
      
       // IT'S a TRAP!
       Serial.println("Error with the input");
     }
    
      // Reset the value of the incomingString
      incomingString = "";
    }
  }
}