Warning: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in ..../includes/class_bbcode.php on line 2958
Autothrottle test
Results 1 to 2 of 2

Thread: Autothrottle test

  1. #1
    25+ Posting Member
    Join Date
    Jun 2014
    Location
    france
    Posts
    44

    Autothrottle test

    Hi to all ,
    So I'm trying to finish a simple prototype autothrottle with servo.
    Using relay to cut off power to servo when autopilot is off . and then read servo potentiometer (I've modified the servo ) on a leo bodnar board (BU0836A) to control manualy throttle .
    My problem is when i ReArm the autopilot the servo remove to the last know position ( before AT was OFF) to go back to the new one .
    ( in fact i dont know how to read the actual position first ..)



    the code i use :

    Code:
    #include varSpeedServo.h
    
    boolean AT;// AutoThrust ON/OFF
    int Tleveli,Tleveli2;
    VarSpeedServo ThrustAServo;
    VarSpeedServo ThrustBServo;
    long prevMillis = 0;
    long prevMillis2 = 0;
    const int interval = 20;
    #define RELAY1  9
    #define RELAY2  18
    String Tlevel,Tlevelold,Tlevel2,Tlevelold2
    
    
    void setup() {
    digitalWrite(RELAY1,HIGH);//   This ONE CUT POWER GROUND FROM SERVO 
    digitalWrite(RELAY2,LOW);//    This one Change 5V from arduino to Leobodnar
      pinMode(RELAY1, OUTPUT); //  
      pinMode(RELAY2, OUTPUT); 
      
     ThrustAServo.attach(4); // The servo pin thrust level
     ThrustAServo.write(150);
     ThrustBServo.attach(5); // The servo pin thrust2 level
     ThrustBServo.write(40);// THE servo 2 is reversed
    
    Serial.begin(115200); 
    }
    
    
    void servo() {
     int Servowrite,Servowriteold,Servowrite2,Servowriteold2;
    Servowrite = Tleveli;
    Servowrite2 = Tleveli2;
    unsigned long currMillis = millis();
    unsigned long currMillis2 = millis();
    
    if  (Servowrite != Servowriteold  && currMillis - prevMillis >  interval) { // checks to see if its different to the "old" reading
           prevMillis = currMillis;
        Servowrite = map(Servowrite, 0, 90, 160,70);   // 
       
    if (AT == 1){// if autothrust is arm  
    
     ThrustAServo.slowmove(Servowrite,6);}  //sends 'value' to the servo and speed
         }
    if(Servowrite != Servowriteold){ Servowrite=Servowriteold;}
    
    //==========================================================================================================
    if  (Servowrite2 != Servowriteold2  && currMillis2 - prevMillis2  > interval) { // checks to see if its different to the "old" reading
           prevMillis2 = currMillis2;
          Servowrite2 = map(Servowrite2, 0, 90, 40,130);   // 
      
       if (AT == 1){ // if autothrust is arm    
       
     ThrustBServo.slowmove(Servowrite2,6);}  //sends 'value' to the servo and speed
         }
    if(Servowrite2 != Servowriteold2){  Servowrite2=Servowriteold2;}
    
    }
    
    void POUND() {
    CodeIn = getChar(); // Get the second identifier
    String cmda,cmdaold;
    switch(CodeIn) {// Now lets find what to do with it
    
    
    case 'e': // MCP AT/ARM
    
    cmda = "";
    cmda += getChar();
    AT=cmda.toInt() ;
    if (cmda.toInt() > 0){ digitalWrite(RELAY2,LOW);delay(1000);digitalWrite(RELAY1,LOW); 
    } else { digitalWrite(RELAY1,HIGH);delay(1000);digitalWrite(RELAY2,HIGH);} 
    cmda= cmdaold;
    break;
    }// end of question void
    
    void LESSTHAN(){ // The first identifier was "<"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    
    case 'V': //Found for reading the Thrust1 level    
       Tlevel = "";
       Tlevel += getChar();
       Tlevel += getChar();
       Tlevel += getChar();
       Tlevel += getChar();
       
       Tleveli = Tlevel.toInt();
       Tlevel = Tlevelold; // Writes the current reading to the "old" string.     
    
        break;
      case 'W': //Found for reading the Thrust1 leve2    
       Tlevel2 = "";
       Tlevel2 += getChar();
       Tlevel2 += getChar();
       Tlevel2 += getChar();
       Tlevel2 += getChar();
       
       Tleveli2 = Tlevel2.toInt();
       Tlevel2 = Tlevelold2; // Writes the current reading to the "old" string.
     break;
    }
    }
    
     }
    
    Attached Images Attached Images

  2. #2
    25+ Posting Member
    Join Date
    Jun 2014
    Location
    france
    Posts
    44

    Re: Autothrottle test

    I ve Found whats was wrong in my code ...
    Just write servo whatever AT(autothrust) is oN/Off ..only cut the ground power with relay when its off..
    Working great now ..Maybe the more easy way to do an simple motorized thrust