Exit status 1 redefination of a function

include<Servo.h>
#include "Wire.h"
#include <MPU6050_light.h>

//for mpu6050
MPU6050 mpu(Wire);
unsigned long timer = 0;

// creating classes for motors
Servo FRmotor ;
Servo FLmotor ;
Servo BRmotor ;
Servo BLmotor ;

// pins attached to the motors
int pin_FRmotor = 10 ;
int pin_FLmotor = 11 ;
int pin_BRmotor = 12 ;
int pin_BLmotor = 13 ; 

// PID parameters for altitude // can be changed
double KPa = 0 ; 
double KIa = 0 ;
double KDa = 0 ;

// PID parameters for oreantations // can be changed 
double KPo = 0 ;
double KIo = 0 ;
double KDo = 0 ;

// constants for pid controller
unsigned long currentTime, previousTime ;
double elapsedTime ;
double Error, previousError ;
double desiredValue, actualValue ;
double KP, KI, KD ;
double intError, rateError ;

// constants for ultrasonic sensor
double k  ;
float l = 0.01723 ;

// pins attached to ultrasonic sensor
int trig_pin = 9 ;
int echo_pin = 8 ;


void setup() {
//setup code for mpu6050//
  Serial.begin(38400) ;
  Wire.begin() ; 
  byte status = mpu.begin() ;
  Serial.print(F("MPU6050 status: ")) ;
  Serial.println(status) ;
  while(status!=0){ } 
  Serial.println(F("Calculating offsets, do not move MPU6050")) ;
  delay(1000) ;
  mpu.calcOffsets() ; 
  Serial.println("Done!\n") ;
//#######################
FRmotor.attach(pin_FRmotor) ;
FLmotor.attach(pin_FLmotor) ;
BRmotor.attach(pin_BRmotor) ;
BLmotor.attach(pin_BLmotor) ;

}// end of void setup

void loop() {

 FRmotor.writeMicroseconds(FRvalue() ) ;
 FLmotor.writeMicroseconds(FLvalue() ) ;
 BRmotor.writeMicroseconds(BRvalue() ) ;
 BLmotor.writeMicroseconds(BLvalue() ) ;
    
}// end of void loop 


//############ to determine actual_altitude from ultrasonic sensor ##############

double actualAltitude()
{
  
  pinMode(trig_pin, OUTPUT) ;
  digitalWrite(trig_pin, LOW) ;
  delayMicroseconds(2) ;
  digitalWrite(trig_pin, HIGH) ;
  delayMicroseconds(10) ;
  digitalWrite(trig_pin, LOW) ;
  pinMode(echo_pin, INPUT) ;  
  k =  pulseIn(echo_pin, HIGH) ;
  return l * k ; 

}

//############## to determine pitch, roll and yaw from mpu6050 ################

double actualPitch() 
{ 
 mpu.update() ;
 return mpu.getAngleX() ;
}

double actualRoll() 
{
 mpu.update() ;
 return mpu.getAngleY() ; 
}

double actualYaw() 
{
  mpu.update() ;
  return mpu.getAngleZ() ;
}

//######### to get desired values for altitide, pitch, roll and yaw ###########

double desiredAltitude()
{
  if (Serial.read() == 'T') {
    return 2 ;
  }

  else if (Serial.read() == 'b') {
    return -2 ;
  }
  
  else{
    return 0 ;
  }
}

double desiredPitch()
{
  if (Serial.read() == 'F') {
    return 2 ;
  }

  else if (Serial.read() == 'B') {
    return -2 ;
  }
  
  else{
    return 0 ;
  }
}

double desiredRoll()
{
  if (Serial.read() == 'L') {
    return 2 ;
  }

  else if (Serial.read() == 'R') {
    return -2 ;
  }
  
  else{
    return 0 ;
  }
}


double desiredYaw()
{
  if (Serial.read() == 'A') {
    return 2 ;
  }

  else if (Serial.read() == 'C') {
    return -2 ;
  }
  
  else{
    return 0 ;
  }
}

//################## function for PID controller ##########################

double pid(desiredValue, actualValue, KP, KI, KD)
{
  
 currentTime = mills() ;
 elapsedTime = (currentTime - previousTime) ;
 Error = (desired_value - actual_value) ;
 intError += Error * elapsedTime ;
 rateError = (Error - previousError)/elapsedTime ;
 previousError = Error ;
 previousTime = currentTime ;

 return KP*Error + KI*intError + KD*rateError ;
 
}

//################ functions for thrust, pitch, roll and yaw ###################

double Thrust() 
{
 return pid(desiredAltitude(), actualAltitude(), KPa, KIa, KDa) ;
 //return 1330 ;
}

double Pitch()
{
 return pid(desiredPitch(), actualPitch(), KPo, KIo, KDo) ; 
}

double Roll()
{
 return Pid(desiredRoll(), actualRoll(), KPo, KIo, KDo) ;
}

double Yaw()
{
 return pid(desiredYaw(), actualYaw(), KPo, KIo, KDo) ;
}

// ############# values of thrust for individual motors #############
int FRvalue()
{
  if ((Thrust() - Pitch() + Roll() - Yaw()) < 1000 )
  {
    return 1000 ;
  }

  if ((Thrust() - Pitch() + Roll() - Yaw()) > 2000 )
  {
    return 2000 ;
  }

  else {
    return Thrust() - Pitch() + Roll() - Yaw() ;
  }
}

int FLvalue() 
{
  if ((Thrust() - Pitch() - Roll() + Yaw()) < 1000 )
  {
    return 1000 ;
  }

  if ((Thrust() - Pitch() - Roll() + Yaw()) > 2000 )
  {
    return 2000 ;
  }

  else {
    return Thrust() - Pitch() - Roll() + Yaw() ;
  }
}

int BRvalue() 
{
  if ((Thrust() + Pitch() + Roll() - Yaw()) < 1000 )
  {
    return 1000 ;
  }

  if ((Thrust() + Pitch() + Roll() - Yaw()) > 2000 )
  {
    return 2000 ;
  }

  else {
    return Thrust() + Pitch() + Roll() - Yaw() ;
  }
}

int BLvalue() 
{
  if ((Thrust() + Pitch() - Roll() + Yaw() < 1000 ))
  {
    return 1000 ;
  }

  if ((Thrust() + Pitch() - Roll() + Yaw()) > 2000 )
  {
    return 2000 ;
  }

  else {
    return Thrust() + Pitch() - Roll() + Yaw() ;
  }
}

and the error is
Arduino: 1.8.16 (Linux), Board: "Arduino Uno"

quadcopter_2:180:12: error: redefinition of 'double pid'
double pid(desiredValue, actualValue, KP, KI, KD)
^~~~~~~~~~~~
/home/harsha/Arduino/quadcopter_2/quadcopter_2.ino:180:8: note: 'double pid' previously declared here
double pid(desiredValue, actualValue, KP, KI, KD)
^~~
/home/harsha/Arduino/quadcopter_2/quadcopter_2.ino: In function 'double Thrust()':
quadcopter_2:199:63: error: 'pid' cannot be used as a function
return pid(desiredAltitude(), actualAltitude(), KPa, KIa, KDa) ;
^
/home/harsha/Arduino/quadcopter_2/quadcopter_2.ino: In function 'double Pitch()':
quadcopter_2:205:57: error: 'pid' cannot be used as a function
return pid(desiredPitch(), actualPitch(), KPo, KIo, KDo) ;
^
/home/harsha/Arduino/quadcopter_2/quadcopter_2.ino: In function 'double Roll()':
quadcopter_2:210:9: error: 'Pid' was not declared in this scope
return Pid(desiredRoll(), actualRoll(), KPo, KIo, KDo) ;
^~~
/home/harsha/Arduino/quadcopter_2/quadcopter_2.ino:210:9: note: suggested alternative: 'pid'
return Pid(desiredRoll(), actualRoll(), KPo, KIo, KDo) ;
^~~
pid
/home/harsha/Arduino/quadcopter_2/quadcopter_2.ino: In function 'double Yaw()':
quadcopter_2:215:53: error: 'pid' cannot be used as a function
return pid(desiredYaw(), actualYaw(), KPo, KIo, KDo) ;
^
exit status 1
redefinition of 'double pid'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

WHAT SHOULD I DO

Your function definition is missing data types, and your serial handling is an accident waiting to happen

You can't use this one pid() function for different things because you only have one previousTime and one previousError. You could add those as arguments and pass them by reference. For example:

double pid(double desiredValue, double actualValue, double KP, double KI, double KD, double &previousError, unsigned long &previousTime)
{
}

double Roll()
{
  static double previousError = 0.0;
  static unsigned long previousTime = 0;
  return pid(desiredRoll(), actualRoll(), KPo, KIo, KDo, previousError, previousTime) ;
}

... and one intError as well. If OP leaves these state variables as global/shared, then the results will all interact.

Oops. I missed that one.

double pid(double desiredValue, double actualValue,
           double KP, double KI, double KD,
           double &previousError, double &intError,
           unsigned long &previousTime)
{
}

double Roll()
{
  static double previousError = 0.0;
  static double intError = 0.0;  // Integral term
  static unsigned long previousTime = 0;
  return pid(desiredRoll(), actualRoll(), KPo, KIo, KDo,
             previousError, intError, previousTime) ;
}

NOW MY CODE IS

#include<Servo.h>
#include "Wire.h"
#include <MPU6050_light.h>

//for mpu6050
MPU6050 mpu(Wire);
unsigned long timer = 0;

// creating classes for motors
Servo FRmotor ;
Servo FLmotor ;
Servo BRmotor ;
Servo BLmotor ;

// pins attached to the motors
int pin_FRmotor = 10 ;
int pin_FLmotor = 11 ;
int pin_BRmotor = 12 ;
int pin_BLmotor = 13 ; 

// PID parameters for altitude // can be changed
double KPa = 0 ; 
double KIa = 0 ;
double KDa = 0 ;

// PID parameters for oreantations // can be changed 
double KPo = 0 ;
double KIo = 0 ;
double KDo = 0 ;

// constants for pid controller
unsigned long currentTime, previousTime ;
double elapsedTime ;
double Error, previousError ;
double desiredValue, actualValue ;
double KP, KI, KD ;
double intError, rateError ;

// constants for ultrasonic sensor
double k  ;
float l = 0.01723 ;

// pins attached to ultrasonic sensor
int trig_pin = 9 ;
int echo_pin = 8 ;


void setup() {
//setup code for mpu6050//
 Serial.begin(38400) ;
 Wire.begin() ; 
 byte status = mpu.begin() ;
 Serial.print(F("MPU6050 status: ")) ;
 Serial.println(status) ;
 while(status!=0){ } 
 Serial.println(F("Calculating offsets, do not move MPU6050")) ;
 delay(1000) ;
 mpu.calcOffsets() ; 
 Serial.println("Done!\n") ;
//#######################
FRmotor.attach(pin_FRmotor) ;
FLmotor.attach(pin_FLmotor) ;
BRmotor.attach(pin_BRmotor) ;
BLmotor.attach(pin_BLmotor) ;

}// end of void setup

void loop() {

FRmotor.writeMicroseconds(FRvalue() ) ;
FLmotor.writeMicroseconds(FLvalue() ) ;
BRmotor.writeMicroseconds(BRvalue() ) ;
BLmotor.writeMicroseconds(BLvalue() ) ;
   
}// end of void loop 


//############ to determine actual_altitude from ultrasonic sensor ##############

double actualAltitude()
{
 
 pinMode(trig_pin, OUTPUT) ;
 digitalWrite(trig_pin, LOW) ;
 delayMicroseconds(2) ;
 digitalWrite(trig_pin, HIGH) ;
 delayMicroseconds(10) ;
 digitalWrite(trig_pin, LOW) ;
 pinMode(echo_pin, INPUT) ;  
 k =  pulseIn(echo_pin, HIGH) ;
 return l * k ; 

}

//############## to determine pitch, roll and yaw from mpu6050 ################

double actualPitch() 
{ 
mpu.update() ;
return mpu.getAngleX() ;
}

double actualRoll() 
{
mpu.update() ;
return mpu.getAngleY() ; 
}

double actualYaw() 
{
 mpu.update() ;
 return mpu.getAngleZ() ;
}

//######### to get desired values for altitide, pitch, roll and yaw ###########

double desiredAltitude()
{
 if (Serial.read() == 'T') {
   return 2 ;
 }

 else if (Serial.read() == 'b') {
   return -2 ;
 }
 
 else{
   return 0 ;
 }
}

double desiredPitch()
{
 if (Serial.read() == 'F') {
   return 2 ;
 }

 else if (Serial.read() == 'B') {
   return -2 ;
 }
 
 else{
   return 0 ;
 }
}

double desiredRoll()
{
 if (Serial.read() == 'L') {
   return 2 ;
 }

 else if (Serial.read() == 'R') {
   return -2 ;
 }
 
 else{
   return 0 ;
 }
}


double desiredYaw()
{
 if (Serial.read() == 'A') {
   return 2 ;
 }

 else if (Serial.read() == 'C') {
   return -2 ;
 }
 
 else{
   return 0 ;
 }
}

//################## function for PID controller ##########################

double pid(desiredValue, actualValue, KP, KI, KD, &previousError, &intError, &previousTime)
{
 
currentTime = mills() ;
elapsedTime = (currentTime - previousTime) ;
Error = (desired_value - actual_value) ;
intError += Error * elapsedTime ;
rateError = (Error - previousError)/elapsedTime ;
previousError = Error ;
previousTime = currentTime ;

return KP*Error + KI*intError + KD*rateError ;

}

//################ functions for thrust, pitch, roll and yaw ###################

double Thrust() 
{
 static double previousError = 0.0;
 static double intError = 0.0;  
 static unsigned long previousTime = 0 ;
 return pid(desiredAltitude(), actualAltitude(), KPo, KIo, KDo, previousError, intError, previousTime) ;
//return 1330 ;
}

double Pitch()
{
 static double previousError = 0.0 ;
 static double intError = 0.0 ;  
 static unsigned long previousTime = 0 ;
 return pid(desiredPitch(), actualPitch(), KPo, KIo, KDo, previousError, intError, previousTime) ;
}

double Roll()
{
 static double previousError = 0.0 ;
 static double intError = 0.0 ;  
 static unsigned long previousTime = 0 ;
 return pid(desiredRoll(), actualRoll(), KPo, KIo, KDo, previousError, intError, previousTime) ;
}

double Yaw()
{
 static double previousError = 0.0;
 static double intError = 0.0 ;  
 static unsigned long previousTime = 0 ;
 return pid(desiredYaw(), actualYaw(), KPo, KIo, KDo, previousError, intError, previousTime) ;
}


// ############# values of thrust for individual motors #############
int FRvalue()
{
 if ((Thrust() - Pitch() + Roll() - Yaw()) < 1000 )
 {
   return 1000 ;
 }

 if ((Thrust() - Pitch() + Roll() - Yaw()) > 2000 )
 {
   return 2000 ;
 }

 else {
   return Thrust() - Pitch() + Roll() - Yaw() ;
 }
}

int FLvalue() 
{
 if ((Thrust() - Pitch() - Roll() + Yaw()) < 1000 )
 {
   return 1000 ;
 }

 if ((Thrust() - Pitch() - Roll() + Yaw()) > 2000 )
 {
   return 2000 ;
 }

 else {
   return Thrust() - Pitch() - Roll() + Yaw() ;
 }
}

int BRvalue() 
{
 if ((Thrust() + Pitch() + Roll() - Yaw()) < 1000 )
 {
   return 1000 ;
 }

 if ((Thrust() + Pitch() + Roll() - Yaw()) > 2000 )
 {
   return 2000 ;
 }

 else {
   return Thrust() + Pitch() + Roll() - Yaw() ;
 }
}

int BLvalue() 
{
 if ((Thrust() + Pitch() - Roll() + Yaw() < 1000 ))
 {
   return 1000 ;
 }

 if ((Thrust() + Pitch() - Roll() + Yaw()) > 2000 )
 {
   return 2000 ;
 }

 else {
   return Thrust() + Pitch() - Roll() + Yaw() ;
 }
}`````

AND THE ERROR IS

Arduino: 1.8.16 (Linux), Board: "Arduino Uno"











quadcopter_2:180:91: error: cannot convert 'long unsigned int*' to 'double' in initialization
double pid(desiredValue, actualValue, KP, KI, KD, &previousError, &intError, &previousTime)
                                                                                          ^
quadcopter_2:180:12: error: redefinition of 'double pid'
double pid(desiredValue, actualValue, KP, KI, KD, &previousError, &intError, &previousTime)
           ^~~~~~~~~~~~
/tmp/arduino_modified_sketch_777172/quadcopter_2.ino:180:8: note: 'double pid' previously defined here
double pid(desiredValue, actualValue, KP, KI, KD, &previousError, &intError, &previousTime)
       ^~~
/tmp/arduino_modified_sketch_777172/quadcopter_2.ino: In function 'double Thrust()':
quadcopter_2:202:103: error: 'pid' cannot be used as a function
  return pid(desiredAltitude(), actualAltitude(), KPo, KIo, KDo, previousError, intError, previousTime) ;
                                                                                                      ^
/tmp/arduino_modified_sketch_777172/quadcopter_2.ino: In function 'double Pitch()':
quadcopter_2:211:97: error: 'pid' cannot be used as a function
  return pid(desiredPitch(), actualPitch(), KPo, KIo, KDo, previousError, intError, previousTime) ;
                                                                                                ^
/tmp/arduino_modified_sketch_777172/quadcopter_2.ino: In function 'double Roll()':
quadcopter_2:219:95: error: 'pid' cannot be used as a function
  return pid(desiredRoll(), actualRoll(), KPo, KIo, KDo, previousError, intError, previousTime) ;
                                                                                              ^
/tmp/arduino_modified_sketch_777172/quadcopter_2.ino: In function 'double Yaw()':
quadcopter_2:227:93: error: 'pid' cannot be used as a function
  return pid(desiredYaw(), actualYaw(), KPo, KIo, KDo, previousError, intError, previousTime) ;
                                                                                            ^
exit status 1
cannot convert 'long unsigned int*' to 'double' in initialization


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

what should I do now

NOW THIS MY CODE AND IT WAS COMPILED WITHOUT ERRORS

#include<Servo.h>
#include "Wire.h"
#include <MPU6050_light.h>

//for mpu6050
MPU6050 mpu(Wire);
unsigned long timer = 0;

// creating classes for motors
Servo FRmotor ;
Servo FLmotor ;
Servo BRmotor ;
Servo BLmotor ;

// pins attached to the motors
int pin_FRmotor = 10 ;
int pin_FLmotor = 11 ;
int pin_BRmotor = 12 ;
int pin_BLmotor = 13 ; 

// PID parameters for altitude // can be changed
double KPa = 0 ; 
double KIa = 0 ;
double KDa = 0 ;

// PID parameters for oreantations // can be changed 
double KPo = 0 ;
double KIo = 0 ;
double KDo = 0 ;

// constants for ultrasonic sensor
double k  ;
float l = 0.01723 ;

// pins attached to ultrasonic sensor
int trig_pin = 9 ;
int echo_pin = 8 ;


void setup() {
//setup code for mpu6050//
  Serial.begin(38400) ;
  Wire.begin() ; 
  byte status = mpu.begin() ;
  Serial.print(F("MPU6050 status: ")) ;
  Serial.println(status) ;
  while(status!=0){ } 
  Serial.println(F("Calculating offsets, do not move MPU6050")) ;
  delay(1000) ;
  mpu.calcOffsets() ; 
  Serial.println("Done!\n") ;
//#######################
FRmotor.attach(pin_FRmotor) ;
FLmotor.attach(pin_FLmotor) ;
BRmotor.attach(pin_BRmotor) ;
BLmotor.attach(pin_BLmotor) ;

}// end of void setup

void loop() {

 FRmotor.writeMicroseconds(FRvalue() ) ;
 FLmotor.writeMicroseconds(FLvalue() ) ;
 BRmotor.writeMicroseconds(BRvalue() ) ;
 BLmotor.writeMicroseconds(BLvalue() ) ;
    
}// end of void loop 


//############ to determine actual_altitude from ultrasonic sensor ##############

double actualAltitude()
{
  
  pinMode(trig_pin, OUTPUT) ;
  digitalWrite(trig_pin, LOW) ;
  delayMicroseconds(2) ;
  digitalWrite(trig_pin, HIGH) ;
  delayMicroseconds(10) ;
  digitalWrite(trig_pin, LOW) ;
  pinMode(echo_pin, INPUT) ;  
  k =  pulseIn(echo_pin, HIGH) ;
  return l * k ; 

}

//############## to determine pitch, roll and yaw from mpu6050 ################

double actualPitch() 
{ 
 mpu.update() ;
 return mpu.getAngleX() ;
}

double actualRoll() 
{
 mpu.update() ;
 return mpu.getAngleY() ; 
}

double actualYaw() 
{
  mpu.update() ;
  return mpu.getAngleZ() ;
}

//######### to get desired values for altitide, pitch, roll and yaw ###########

double desiredAltitude()
{
  if (Serial.read() == 'T') {
    return 2 ;
  }

  else if (Serial.read() == 'b') {
    return -2 ;
  }
  
  else{
    return 0 ;
  }
}

double desiredPitch()
{
  if (Serial.read() == 'F') {
    return 2 ;
  }

  else if (Serial.read() == 'B') {
    return -2 ;
  }
  
  else{
    return 0 ;
  }
}

double desiredRoll()
{
  if (Serial.read() == 'L') {
    return 2 ;
  }

  else if (Serial.read() == 'R') {
    return -2 ;
  }
  
  else{
    return 0 ;
  }
}


double desiredYaw()
{
  if (Serial.read() == 'A') {
    return 2 ;
  }

  else if (Serial.read() == 'C') {
    return -2 ;
  }
  
  else{
    return 0 ;
  }
}

//################## function for PID controller ##########################

double pid(double desiredValue, double actualValue, double KP, double KI, double KD, double &previousError, double &intError, unsigned long &previousTime)
{
  
 unsigned long currentTime = millis() ;
 double elapsedTime = (currentTime - previousTime) ;
 double Error = (desiredValue - actualValue) ;
 intError += Error * elapsedTime ;
 double rateError = (Error - previousError)/elapsedTime ;
 previousError = Error ;
 previousTime = currentTime ;
 return KP*Error + KI*intError + KD*rateError ;
 
}

//################ functions for thrust, pitch, roll and yaw ###################

double Thrust() 
{
  static double previousError = 0.0;
  static double intError = 0.0;  
  static unsigned long previousTime = 0 ;
  return pid(desiredAltitude(), actualAltitude(), KPo, KIo, KDo, previousError, intError, previousTime) ;
 //return 1330 ;
}

double Pitch()
{
  static double previousError = 0.0 ;
  static double intError = 0.0 ;  
  static unsigned long previousTime = 0 ;
  return pid(desiredPitch(), actualPitch(), KPo, KIo, KDo, previousError, intError, previousTime) ;
}

double Roll()
{
  static double previousError = 0.0 ;
  static double intError = 0.0 ;  
  static unsigned long previousTime = 0 ;
  return pid(desiredRoll(), actualRoll(), KPo, KIo, KDo, previousError, intError, previousTime) ;
}

double Yaw()
{
  static double previousError = 0.0;
  static double intError = 0.0 ;  
  static unsigned long previousTime = 0 ;
  return pid(desiredYaw(), actualYaw(), KPo, KIo, KDo, previousError, intError, previousTime) ;
}


// ############# values of thrust for individual motors #############
int FRvalue()
{
  if ((Thrust() - Pitch() + Roll() - Yaw()) < 1000 )
  {
    return 1000 ;
  }

  if ((Thrust() - Pitch() + Roll() - Yaw()) > 2000 )
  {
    return 2000 ;
  }

  else {
    return Thrust() - Pitch() + Roll() - Yaw() ;
  }
}

int FLvalue() 
{
  if ((Thrust() - Pitch() - Roll() + Yaw()) < 1000 )
  {
    return 1000 ;
  }

  if ((Thrust() - Pitch() - Roll() + Yaw()) > 2000 )
  {
    return 2000 ;
  }

  else {
    return Thrust() - Pitch() - Roll() + Yaw() ;
  }
}

int BRvalue() 
{
  if ((Thrust() + Pitch() + Roll() - Yaw()) < 1000 )
  {
    return 1000 ;
  }

  if ((Thrust() + Pitch() + Roll() - Yaw()) > 2000 )
  {
    return 2000 ;
  }

  else {
    return Thrust() + Pitch() + Roll() - Yaw() ;
  }
}

int BLvalue() 
{
  if ((Thrust() + Pitch() - Roll() + Yaw() < 1000 ))
  {
    return 1000 ;
  }

  if ((Thrust() + Pitch() - Roll() + Yaw()) > 2000 )
  {
    return 2000 ;
  }

  else {
    return Thrust() + Pitch() - Roll() + Yaw() ;
  }
}

thank you johnwasser

Now you need to fix the serial handling.

Note: All of these functions:

Can be reduced to:

int BRvalue() 
{
    return constrain(Thrust() + Pitch() + Roll() - Yaw(), 1000, 2000) ;
}

This kind of thing is not going to work at all:

double desiredAltitude()
{
  if (Serial.read() == 'T') {
    return 2 ;
  }

  else if (Serial.read() == 'b') {
    return -2 ;
  }
  else
  {
    return 0 ;
  }
}

Every time you call Serial.read() it is going to pull one byte from the input buffer, or return -1 if the buffer is empty. If the first character in the buffer is not 'T' it is completely ignored and the next byte is fetched from the buffer. If that second byte is not 'b' it, too, is completely ignored.

This is much closer to something that might work:

double desiredAltitude()
{
  if (Serial.peek() == 'T') {
    Serial.read();
    return 2 ;
  }

  else if (Serial.peek() == 'b') {
    Serial.read();
    return -2 ;
  }
  else
  {
    return 0 ;
  }
}

At least by using Serial.peek(), characters that don't match are left in the buffer to be checked against other possibilities. Unfortunately, if any character you are not looking for makes it into the Serial buffer, no further characters will be processed.

The proper way is to put all the input processing into loop() or a function called from loop(). Have a global variable instead of having a global function for each variable:

void processInput()
{
  if (Serial.available())
  {
    char command = Serial.read();
    switch (command)
    {
       case 'T':  desiredAltitude = 2; break;
       case 'b':  desiredAltitude = -2; break;
       case 'F':  desiredPitch = 2; break;
       case 'B':  desiredPitch = -2; break;
    }
}