a

Dependencies:   mbed Brushless_DC_Lib_ MPU6050 AR-610_Lib_

main.cpp

Committer:
lordofthestorm12
Date:
2019-03-06
Revision:
0:38cb99a6dea6
Child:
2:1f0765d254d1

File content as of revision 0:38cb99a6dea6:

#include "mbed.h"
#include "AR610_LIB.h"
#include "Brushless_DC_LIB.h"
#include "MPU6050.h"

Serial pc(USBTX, USBRX);
BusOut LED(LED1, LED2, LED3, LED4);
MPU6050 Gyro(p9, p10);

int main() {
    
// I. Initprocedure...

    // I~SEC 
    
    bool SEC_MOTOR_FREE = false;
    
    // I~a Reciever Init 
    Receiver_obj Throttle(p15), Aile(p16),Elev(p17), Rudd(p18);
    
    // I~b Brushless Init (criticle procedure, [set for 4sec on 1kppm for Motorrealease...])
    
    LED = 0x06;
    Motor_obj Brshlss(p21, p22, p23, p24);
    Brshlss.setAllMotor(1000,1000,1000,1000);
    wait(2);
    
    LED = 0x00;

    // I~c Gyro Init and set Offset...
    
    float GyroData[3];
    float G_Offset[3];
    
      
    bool Test = Gyro.testConnection();
    if( Test == true ){
    LED = 0x0f;
    wait(2);
    
    SEC_MOTOR_FREE = true;
    
    Gyro.getGyro(GyroData);
    
    // GyroOffSet
    
    G_Offset[0] = GyroData[0];
    G_Offset[1] = GyroData[1];
    G_Offset[2] = GyroData[2];
    
    }else{
        SEC_MOTOR_FREE = false;
        Brshlss.setAllMotor(1000,1000,1000,1000);
        if(SEC_MOTOR_FREE == false){
            while(true){
            LED =0x0f;
            wait_ms(100);
            LED = 0x00;
            wait_ms(100); 
            }
        }
        
    }
    
    LED = 0x09;
    
    // Variaben
    int throttleVal;
    int corval = 20;
    
    
    while(true){
   
   Brshlss.setAllMotor(Throttle.CurVal(),Throttle.CurVal(),Throttle.CurVal(),Throttle.CurVal());
   pc.printf("%d", Throttle.CurVal());
   wait(1);
   
   /*
   
   LED = 0x01;
   Brshlss.setAllMotor(1300,0,0,0);
   wait(1);
   LED = 0x02;
   Brshlss.setAllMotor(0,1300,0,0);
   wait(1);
   LED = 0x04;
   Brshlss.setAllMotor(0,0,1300,0);
   wait(1);
   LED = 0x08;
   Brshlss.setAllMotor(0,0,0,1300);
   wait(1);
   
   
   
    Gyro.getGyro(GyroData);
    throttleVal = Throttle.CurVal();
    
    Brshlss.setAllMotor(throttleVal + (int)(GyroData[1] * corval),throttleVal + (int)(GyroData[1] * corval) , throttleVal, throttleVal);
     
    pc.printf(" MC: %d %d %d %d || GY: %f %d %d  \n" , Brshlss.getMotorVal(LeftFront), Brshlss.getMotorVal(RightFront), Brshlss.getMotorVal(LeftBack), Brshlss.getMotorVal(RightBack), GyroData[0], (int)(GyroData[0] * corval), 
    throttleVal );
    */
    
    }
    
}