A quadcopter control Software (Still in development). achieved single axis stability!!!!! released for others benefit. if you'd like to help co-develop this code, then please let me know

Dependencies:   MovingAverageFilter MyI2C PID RC mbed-rtos mbed

Currently on hold, due to the fact that i don't own a RX/TX system

Motors.h

Committer:
KarimAzzouz
Date:
2013-08-27
Revision:
1:e08a4f517989
Parent:
0:54b67cd15a5b

File content as of revision 1:e08a4f517989:

#define RefreshRate 2500 // in us :400Hz
    
   static uint16 Constrain(uint16 a , uint16 b, uint16 c){
   if(a<b) return b;
   else if(a>c)return c;
   else return a;
   }
 
  void CalibrateESC(void){
  
    FrontMotor.period_us(RefreshRate); // setting one will by default set all other pins to the same period 
    
    /*FrontMotor.pulsewidth_us(2000);
    RearMotor.pulsewidth_us(2000);
    LeftMotor.pulsewidth_us(2000);
    RightMotor.pulsewidth_us(2000);
    
    wait(2);  still in testing phase */ 
    
    FrontMotor.pulsewidth_us(1000);
    RearMotor.pulsewidth_us(1000);
    LeftMotor.pulsewidth_us(1000);
    RightMotor.pulsewidth_us(1000);
    
    wait(2);
  }
   
  void updateMotors(int16 PitchCommand,int16 RollCommand){
  
    if(Throttle>=1200){

    Mspeed[0] = Constrain((Throttle+PitchCommand),1200,2000);
    Mspeed[1] = Constrain((Throttle-PitchCommand),1200,2000);
    Mspeed[2] = Constrain((Throttle+RollCommand),1200,2000);
    Mspeed[3] = Constrain((Throttle-RollCommand),1200,2000);
    }
    
    else{
    Mspeed[0] = 1000;
    Mspeed[1] = 1000;
    Mspeed[2] = 1000;
    Mspeed[3] = 1000;
    }
    
    FrontMotor.pulsewidth_us(Mspeed[0]);
    RearMotor.pulsewidth_us(Mspeed[1]);
    LeftMotor.pulsewidth_us(Mspeed[2]);
    RightMotor.pulsewidth_us(Mspeed[3]);
}