Cockpitbuilders.com

Arduino Projects => General Discussions => Topic started by: Ronix77 on February 27, 2018, 12:28:27 PM

Title: ArdSimX - problems with ProgOut routine
Post by: Ronix77 on February 27, 2018, 12:28:27 PM
Hi guys,
I'm facing to a big wall that i can't walk around. I'm trying to write the code for the 737 autothrottle. I've built a motorized throttle and i want to tell the motors to move forward and backward everytime the value of the pot mismatch the value of a specific dataref. Below my data.cfg and the arduino code. The progout routine doesn't run even if the value of the id change. Do you know how to resolve this problem?
Thank you

---- Analog pins: ----

1 - Throttle position – engine #1
2 - Throttle position – engine #2
3 - Speebrake HANDLE position

---- Programmable inputs: ----
1 - sim/cockpit2/controls/flap_ratio

---- Programmable outputs: ----

1 - sim/flightmodel2/gear/on_ground
2 - sim/flightmodel/engine/ENGN_thro_use
3 - sim/cockpit/autopilot/airspeed_mode

@ ================= CONFIG =================

*1-0U
[A]
T D6+

A0 sim/cockpit2/engine/actuators/throttle_ratio 0,1 1 200 0 100
A1 sim/cockpit2/engine/actuators/throttle_ratio 0,1 2 200 0 100
A2 sim/cockpit2/controls/speedbrake_ratio 0,1 1 200 0 100
C1 sim/cockpit2/controls/flap_ratio 0,1 1
D2- sim/cockpit2/engine/actuators/mixture_ratio 0 1
D2+ sim/cockpit2/engine/actuators/mixture_ratio 1 1
D3- sim/cockpit2/engine/actuators/mixture_ratio 0 2
D3+ sim/cockpit2/engine/actuators/mixture_ratio 1 2
D4- sim/cockpit2/controls/parking_brake_ratio 0 1
D4+ sim/cockpit2/controls/parking_brake_ratio 1 1
D5+ sim/autopilot/take_off_go_around
D6- sim/autopilot/autothrottle_off


  • 1D 0 sim/cockpit2/controls/flap_ratio 1


    #include
    #include
    #include
    const int analogInPinA = A0;
    const int analogInPinB = A1;
    const int analogInPinF = A3;

    int sensorValueF = 0;
    int sensorValueA = 0;
    int sensorValueB = 0;

    // Motore LEVA TH 1
    int dir1PinA = 24;
    int dir2PinA = 25;
    int speedPinA = 9;

    // Motore LEVA TH2
    int dir1PinB = 22;
    int dir2PinB = 23;
    int speedPinB = 10;

    // Motore RUOTE TRIM
    int dir1PinC = 26;
    int dir2PinC = 27;
    int speedPinC = 11;

    void setup() {
    BoardNumber 1; // -- Assign Board Number here (1...9)
    }

    void loop() {
    ArdSimScan; // Dont't delete!!!
    sensorValueF = analogRead(analogInPinF);
    sensorValueA = analogRead(analogInPinA);
    sensorValueB = analogRead(analogInPinB);

    if(sensorValueF==0){SimInput(1,0.0);}
    else if(sensorValueF>20 && sensorValueF<35){SimInput(1,0.125);}
    else if(sensorValueF>90 && sensorValueF<105){SimInput(1,0.250);}
    else if(sensorValueF>125 && sensorValueF<140){SimInput(1,0.375);}
    else if(sensorValueF>180 && sensorValueF<190){SimInput(1,0.500);}
    else if(sensorValueF>250 && sensorValueF<260){SimInput(1,0.625);}
    else if(sensorValueF>355 && sensorValueF<365){SimInput(1,0.750);}
    else if(sensorValueF>550 && sensorValueF<580){SimInput(1,0.875);}
    else if(sensorValueF>900){SimInput(1,1);}

    }

    void ProgOut(byte id, float val) {
    if(id==3 && val==10){
    if(id==2 && val>sensorValueA){
    analogWrite(speedPinA, 200);
    digitalWrite(dir1PinA, HIGH);
    digitalWrite(dir2PinA, LOW);

    }else if(id==2 && valsensorValueB){
    analogWrite(speedPinB, 200);
    digitalWrite(dir1PinB, HIGH);
    digitalWrite(dir2PinB, LOW);

    }else if(id==2 && val<sensorValueB){
    analogWrite(speedPinB, 200);
    digitalWrite(dir1PinB, LOW);
    digitalWrite(dir2PinB, HIGH);
    }
    }
    }