Skip to content

Amazing power of Teensy (and sketch programming)

Started by kurt-olsson, October 08, 2016, 12:11:52 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

kurt-olsson

Insted of all the plug and play installations and hooking up to softwares etc.
This is all the code i use for my autothrottle to work.

I have a delta diff that configures how sensitive the "null-zone" is for engagement of movement.

This is the only code for making the throttles work and mapping against the autothrottle set position.
The first else in the code is if the autothrottle is armed.

The Serial.Print is just for debugging.

else {

    //This is if the Autothrottle is armed and Spd or N1 is engaged.

    float differential_limit_for_throttle_to_move_on = 0.03;
    float diff = XPF_THROTTLE_LEFT_POSITION - THROTTLE_LEFT_POSITION;
 
    if (abs(diff) > differential_limit_for_throttle_to_move_on) {
        if (diff < 0) {
            Serial.print("Back off throttle");
            Serial.print("\n");
            SetThrottleMovementToDecrease();
        }
        else {
            Serial.print("Advance throttle");
            Serial.print("\n");
            SetThrottleMovementToIncrease();
        }
    }
    else {
      StopThrottles();
      Serial.print("Stop");
      Serial.print("\n");
    }
  }


This works flawlessly... i cant belive this task was so simple, though it would be more than a 20 minute job. =)

Oh, and also my functions, this is just HIGH,LOW values for the pins.

void SetThrottleMovementToIncrease() {
   digitalWrite(0,HIGH);
   digitalWrite(1,LOW);
   analogWrite(4,255);

   digitalWrite(2,LOW);
   digitalWrite(3,HIGH);
   analogWrite(5,255);
}

void SetThrottleMovementToDecrease() {
   digitalWrite(0,LOW);
   digitalWrite(1,HIGH);
   analogWrite(4,255);
 
   digitalWrite(2,HIGH);
   digitalWrite(3,LOW);
   analogWrite(5,255);
}

void StopThrottles() {
  analogWrite(4,0);
  analogWrite(5,0);
}

https://www.youtube.com/watch?v=Asn07F0Lpv8