• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

MSFS20 Rough Running Engine - Best methods for setting

Messages
26
Country
unitedkingdom
Hi All

I am trying to implement spark fouling in the a custom behaviour xml.

I have a time that checks what the mixture ratio is and then counts up to between 30 & 60.

Once there I want to implement/simulate the rough running of the engine but i'm having trouble making it realistic. At the moment I am reducing the engine manifold pressure, has anyone else got any ideas how we can implement a rough running engine?

Instead of manifold pressure I think I really want to show changes to rpm and power?

XML:
<Macro Name="MaxPsiDrop"> 6 </Macro>
<Macro Name="PsiScaler"> (L:ELAPSED_TIME) 0.01 * 0.29 - </Macro>

<!-- ### TRIGGER ### -->
<Update Frequency="1">
(L:ELAPSED_TIME) 30 &gt;
if{
1 (&gt;L:Fouling, bool)
} els{
0 (&gt;L:Fouling, bool)
</Update>


<!-- ### FOULING EFFECT, SCALED BY THE TIMING MECHANISM not shown ### -->
<Update Frequency="3">
(L:Fouling, bool) 1 ==
(A:GENERAL ENG RPM:1, rpm) 600 &gt; and
if{
@PsiScaler @MaxPsiDrop &gt;
    if{ (A:RECIP ENG MANIFOLD PRESSURE:1, psi) @MaxPsiDrop - (&gt;A:RECIP ENG MANIFOLD PRESSURE:1, psi) }
    els{ (A:RECIP ENG MANIFOLD PRESSURE:1, psi) @PsiScaler - (&gt;A:RECIP ENG MANIFOLD PRESSURE:1, psi) }
}
</Update>
 
Code:
if{ (A:RECIP ENG MANIFOLD PRESSURE:1, psi) @MaxPsiDrop - (&gt;A:RECIP ENG MANIFOLD PRESSURE:1, psi) }

Does that even work? FSX and P3D you couldn't write to A: vars directly. You'd need to use SimConnect and even then something like the manifold pressure would not be writeable as the sim is constantly updating that value. You make your rough running change and then the sim will change that value itself.

In the past I've set the mixture ratio. That involved setting up SimConnect to intercept any user commands to adjust mixture and then read those, make any modifications I need and then set the mixture ratio myself. Not the easiest thing to do.

I like Dragonflightdesign's idea of cutting the magnetos though. But I'd probably make a custom fuel system and put an extra fuel valve in front of the engine that the user doesn't have access to and switch that open/closed randomly.

EDIT: Using a custom fuel system or cutting magnetos isn't going to work well. The fuel system has about 4-5 seconds of extra running after the fuel valve is closed. And in both cases (fuel cutoff or magnetos) you are going to trigger the engine shutdown sounds which might sound unpleasant and unrealistic. I'd probably stick with quickly reducing the mixture levels. This will give a rough cutout effect without actually cutting the engine.

Fun fact, MSFS doesn't have a random number generater in XML. Here's some dead simple code for a psuedo random number generator. You can seed it using time for more randomness.

Code:
(L:Random1,number) 1 + 747811 / 1000000000 * 1 % abs (&gt;L:Random1,number)
 
Last edited:
If you want a failure that is likely to happen in flight, try carb icing. You can be flying along in nice clear weather at 2000 or so feet and very slowly the engine loses power. It might not totally kill the engine but there is not enough power to maintain level flight. If you suddenly think "carb Ice" and pull out the heater control, the engine will cut out. The nice thing is that while it actually keeps going you do have some control and can refine your glide into the best looking field.
Been there, done that.
Roy
 
If you suddenly think "carb Ice" and pull out the heater control, the engine will cut out. The nice thing is that while it actually keeps going you do have some control and can refine your glide into the best looking field.
Been there, done that.
Roy
:rotfl:I nearly did once, but I was downwind in the circuit and the engine decided to play nice after a couple of heart-stopping seconds.
 
@Anthony31

Thank you; I'll try the mixture ratio thing. I wish there was a way to simulate these things more easily.

As for the random number - I've been using this which works well.

Code:
<!-- random number times 30 equals a number between 0 and 30. Then adding 30 makes it between 30 and 60. -->
  <Macro Name="RandomTimer">
    rand 30 * 30 +
  </Macro>
 
If you want a failure that is likely to happen in flight, try carb icing. You can be flying along in nice clear weather at 2000 or so feet and very slowly the engine loses power. It might not totally kill the engine but there is not enough power to maintain level flight. If you suddenly think "carb Ice" and pull out the heater control, the engine will cut out. The nice thing is that while it actually keeps going you do have some control and can refine your glide into the best looking field.
Been there, done that.
Roy
It's on the list, :-) I eventually want to model as many of these as possible with our G36 Improvement Mod.
 
@Anthony31

Thank you; I'll try the mixture ratio thing. I wish there was a way to simulate these things more easily.

As for the random number - I've been using this which works well.

Code:
<!-- random number times 30 equals a number between 0 and 30. Then adding 30 makes it between 30 and 60. -->
  <Macro Name="RandomTimer">
    rand 30 * 30 +
  </Macro>
Maybe I was looking in the wrong place for the rand operator. Or maybe Asobo has added it to the SDK documentation and it was there all along.

I see it now under Special Operators on https://docs.flightsimulator.com/html/index.htm#t=Additional_Information/Reverse_Polish_Notation.htm

One of the dangers with messing with the mixture ratio is you need to keep track of any user inputs. If the user adjusts the mixture while you are fiddling with it you need to be able to return to the user selected mixture position. Then there is the issue of a user who selects auto mixture as a pilot assistance, you won't be able to adjust the mixture. Then there is the question of altitude. A mixture setting at sea level is going to have a different effect at a higher altitude.
 
Last edited:
Hello,
I would suggest the following:
intercept user input for throttles and upload them to your own L:Var ,
I posted an example on how I was able to do this:


Suggested psuedo code to implement rough running:

Code:
if(runningRough==false) {  (L:MyThrottleLvar,number) 16384 * (>K:THROTTLE_SET) }  // normal mode , your L:var drives the Simvar throttle value.

else{ (L:MyThrottleLvar,number)  (L:RandomOffset,number) + 16384 * (>K:THROTTLE_SET)  } // if rough mode , add random number to the Simvar throttle value, the value of this random number should be updated as a function of time, in an update loop for example every 30 frames.

if your throttle animation is linked to (L:MyThrottleLvar,number) then the outcome of the above would be:
User sets his throttle input, if engine should run rough; engine manifold pressure fluctuates without effecting the user's throttle position. and would operate normally otherwise.
 
Last edited:
Reading throttle inputs is rather tricky. I've done this via simconnect in FSX and P3D and I had to implement a joystick calibration routine as various joysticks will output various values. Some joysticks will use half the throttle range for reverse throttles for example.

As I understand it the raw values you get from reading throttle events is before any joystick calibration in the sim (at least it is for FSX and P3D). So a user may give it full throttle but their stick is only sending 15500 instead of 16384. That's why you need to write a calibration routine so the user can calibrate their throttle to work in your system.

I mean, you can do it. It's how I simulated a two stage supercharger in my T28 aircraft but it isn't the easiest thing to do.
 
Reading throttle inputs is rather tricky. I've done this via simconnect in FSX and P3D and I had to implement a joystick calibration routine as various joysticks will output various values. Some joysticks will use half the throttle range for reverse throttles for example.

As I understand it the raw values you get from reading throttle events is before any joystick calibration in the sim (at least it is for FSX and P3D). So a user may give it full throttle but their stick is only sending 15500 instead of 16384. That's why you need to write a calibration routine so the user can calibrate their throttle to work in your system.

I mean, you can do it. It's how I simulated a two stage supercharger in my T28 aircraft but it isn't the easiest thing to do.
Hello Anthony, Thank you for your feedback , big fan!
My understanding is that the <inputEvents> approach is receiving the in-sim variable of throttle position that is fed for all aircraft , so calibration should be baked in already, or atleast if user has an issue with the stick sending only 15500 this will be apparent with all aircraft and not only the one using the <inputEvents> method.
The value received is already calibrated by the simulation engine.

Will experiment with this further and let you know if my assumptions are correct or not.
 
Hello,
I would suggest the following:
intercept user input for throttles and upload them to your own L:Var ,
I posted an example on how I was able to do this:


Suggested psuedo code to implement rough running:

Code:
if(runningRough==false) {  (L:MyThrottleLvar,number) 16384 * (>K:THROTTLE_SET) }  // normal mode , your L:var drives the Simvar throttle value.

else{ (L:MyThrottleLvar,number)  (L:RandomOffset,number) + 16384 * (>K:THROTTLE_SET)  } // if rough mode , add random number to the Simvar throttle value, the value of this random number should be updated as a function of time, in an update loop for example every 30 frames.

if your throttle animation is linked to (L:MyThrottleLvar,number) then the outcome of the above would be:
User sets his throttle input, if engine should run rough; engine manifold pressure fluctuates without effecting the user's throttle position. and would operate normally otherwise.
Hey @Marwan Gharib

Thanks so much, I'm just trying to get my hear around your code and what is happening in https://www.fsdeveloper.com/forum/threads/hijack-input-events-using-b-vars.454266/ but the theory behind it all sounds good.

I've started trying to implement your psuedo code into RPN for the XML file but I seem to have made it intercept and change the throttle back to 0% whenever I move it. Can you see any issue with my code?



XML:
<!-- Mixture Ratio -->
  <Macro Name="MixtureRatio">
    (A:RECIP MIXTURE RATIO:1, ratio)
  </Macro>

  <Macro Name="MaxDrop">
    6
  </Macro>

  <!-- random number times 30 equals a number between 0 and 30. Then adding 30 makes it between 30 and 60. -->
  <Macro Name="RandomTimer">
    rand 30 * 30 +
  </Macro>

<Template Name="Spark_Fouling">

  <!-- Create a timing mechanism we can use to create the fouling, we want it to get worse over time if the user doesn't do anything -->
  <Update Frequency="1">
    (A:ENG COMBUSTION:1, bool) 1 ==
    @MixtureRatio 0.07 &gt; and
    if{
      (L:G36XIP_ELAPSED_TIME) 1 + (&gt;L:G36XIP_ELAPSED_TIME)
    } els{
      0 (&gt;L:G36XIP_ELAPSED_TIME)
    }
  </Update>

  <!-- Create the trigger based on the elapsed time which checks if the fouling might happen -->
  <Update Frequency="1">
    (L:G36XIP_ELAPSED_TIME) @RandomTimer &gt;
        if{
            1 (&gt;L:G36XIP_FOUL, bool)
        } els{
            0 (&gt;L:G36XIP_FOUL, bool)
    }
  </Update>


  <Update Frequency="12">
    (L:G36XIP_FOUL, bool) 1 ==
    IF{
      (L:MyThrottleLvar,number) @MaxDrop + 16384 * (&gt;K:THROTTLE_SET)
    } els{
      (L:MyThrottleLvar,number) 16384 * (&gt;K:THROTTLE_SET)
    }
  </Update>

</Template>
 
Hey @Marwan Gharib

Thanks so much, I'm just trying to get my hear around your code and what is happening in https://www.fsdeveloper.com/forum/threads/hijack-input-events-using-b-vars.454266/ but the theory behind it all sounds good.

I've started trying to implement your psuedo code into RPN for the XML file but I seem to have made it intercept and change the throttle back to 0% whenever I move it. Can you see any issue with my code?



XML:
<!-- Mixture Ratio -->
  <Macro Name="MixtureRatio">
    (A:RECIP MIXTURE RATIO:1, ratio)
  </Macro>

  <Macro Name="MaxDrop">
    6
  </Macro>

  <!-- random number times 30 equals a number between 0 and 30. Then adding 30 makes it between 30 and 60. -->
  <Macro Name="RandomTimer">
    rand 30 * 30 +
  </Macro>

<Template Name="Spark_Fouling">

  <!-- Create a timing mechanism we can use to create the fouling, we want it to get worse over time if the user doesn't do anything -->
  <Update Frequency="1">
    (A:ENG COMBUSTION:1, bool) 1 ==
    @MixtureRatio 0.07 &gt; and
    if{
      (L:G36XIP_ELAPSED_TIME) 1 + (&gt;L:G36XIP_ELAPSED_TIME)
    } els{
      0 (&gt;L:G36XIP_ELAPSED_TIME)
    }
  </Update>

  <!-- Create the trigger based on the elapsed time which checks if the fouling might happen -->
  <Update Frequency="1">
    (L:G36XIP_ELAPSED_TIME) @RandomTimer &gt;
        if{
            1 (&gt;L:G36XIP_FOUL, bool)
        } els{
            0 (&gt;L:G36XIP_FOUL, bool)
    }
  </Update>


  <Update Frequency="12">
    (L:G36XIP_FOUL, bool) 1 ==
    IF{
      (L:MyThrottleLvar,number) @MaxDrop + 16384 * (&gt;K:THROTTLE_SET)
    } els{
      (L:MyThrottleLvar,number) 16384 * (&gt;K:THROTTLE_SET)
    }
  </Update>

</Template>
Hello ,
Were you able to successfully implement the B:var method, ie. is (L:MyThrottleLvar,number) modulating with throttle input?
the code in the other thread will modulate the throttle variable between 0~1 . so in terms of percentage the code would be :

(L:MyThrottleLvar,number) 100 * @MaxDrop - 163.84* (&gt;K:THROTTLE_SET) , which should input 94% throttle at full forward position.
 
Hi

I think so, sorry I'm not that great with the XML stuff.

I have this in the Bonanza_g36_interior.xml file

XML:
<!-- intercepting throttle input #####################################-->
        <Component ID="throttleController">
      <UseTemplate Name="CUSTOM_THROTTLE_CONTROLLER">
        <THROTTLE_ID>1</THROTTLE_ID>
        </UseTemplate>
    </Component>

    <Template Name="CUSTOM_THROTTLE_CONTROLLER">
      <Parameters Type="Default">
        <INPUT_EVENT_ID_SOURCE>ENGINE1</INPUT_EVENT_ID_SOURCE>
      </Parameters>
      <UseTemplate Name="ASOBO_Interaction_Base_Template">
        <USE_INPUT_EVENT_ID>ENGINE1</USE_INPUT_EVENT_ID>
      </UseTemplate>
    </Template>

    <InputEvent ID="ENGINE1">
      <Presets>
        <Extend Target="ASOBO_GIE_Anim_Handling">
          <Parameters Type="Default">
            <INPUT_EVENT_ID_SOURCE>ENGINE1</INPUT_EVENT_ID_SOURCE>
          </Parameters>
            </Extend>
        <INPUT_EVENT_ID_SOURCE>ENGINE1</INPUT_EVENT_ID_SOURCE>
          <Preset ID="ENGINE1_Throttle_#THROTTLE_ID#">
            <INCREMENT>0.1</INCREMENT>
            <UPPER_LIMIT>16384</UPPER_LIMIT>
            <LOWER_LIMIT>(A:THROTTLE LOWER LIMIT, position 16k)</LOWER_LIMIT>
              <INIT_CODE>(A:GENERAL ENG THROTTLE LEVER POSITION:#THROTTLE_ID#, position 16k) 16384 / s0 (&gt;O:ENGINE_Throttle_#THROTTLE_ID#_Position)</INIT_CODE>

            <Tooltip>
              <Icon>MOVE_AXIS_Y</Icon>
              <Interaction>PRIMARY_DOWN+Y_AXIS</Interaction>
              <InteractionLockable>Y_AXIS</InteractionLockable>
              <TTDescription RPN="True">@TT_Package.ENGINE_PUSH_TOGA_ACTION</TTDescription>
              <TTValue RPN="True">(A:GENERAL ENG THROTTLE LEVER POSITION:1, percent) '%.1f%%' @sprintf</TTValue>
            </Tooltip>
            <Value>
              <Units>percent</Units>
              <Code>(O:ENGINE_Throttle_#THROTTLE_ID#_Position)</Code>
              <Init>(A:GENERAL ENG THROTTLE LEVER POSITION:#THROTTLE_ID#, position 16k) 16384 / (&gt;O:ENGINE_Throttle_#THROTTLE_ID#_Position)</Init>
                <WatchVars>
                  <Simvar ID="GENERAL ENG THROTTLE LEVER POSITION:#THROTTLE_ID#"/>
                </WatchVars>
            </Value>
            <Inc>
              <Code>(L:THROTTLE#THROTTLE_ID#_SET,number) p0 + (&gt;B:ENGINE1_Throttle_#THROTTLE_ID#_SET)</Code>
                <Parameters>
                  <Param Type="Float" RPN="True">p0</Param>
              </Parameters>
              <Bindings>
                  <Binding EventID="THROTTLE_INCR"><!-- event manipulating all throttles (declared for each throttle preset) -->
                    <Param>0.1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE_INCR_SMALL"><!-- event manipulating all throttles (declared for each throttle preset) -->
                    <Param>0.05</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_INCR">
                    <Param>0.1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_INCR_SMALL">
                    <Param>0.05</Param>
                  </Binding>
              </Bindings>
            </Inc>
            <Dec>
              <Code>(L:THROTTLE#THROTTLE_ID#_SET,number) p0 - (&gt;B:ENGINE1_Throttle_#THROTTLE_ID#_SET)</Code>
              <Parameters>
                <Param Type="Float" RPN="True">p0</Param>
              </Parameters>
              <Bindings>
                <Binding EventID="THROTTLE_DECR"><!-- event manipulating all throttles (declared for each throttle preset) -->
                    <Param>0.1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE_DECR_SMALL"><!-- event manipulating all throttles (declared for each throttle preset) -->
                    <Param>0.05</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_DECR">
                        <Param>0.1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_DECR_SMALL">
                    <Param>0.05</Param>
                  </Binding>
                </Bindings>
            </Dec>
            <Set>
              <Code>p0 0 max 1 min s0 (&gt;L:THROTTLE#THROTTLE_ID#_SET,number) l0 (&gt;O:ENGINE_Throttle_#THROTTLE_ID#_Position)</Code>
              <Parameters>
                <Param Type="Float" RPN="True">p0</Param>
              </Parameters>
              <Bindings>
                <!-- Aliases -->
                  <Binding Alias="ENGINE1_All_Throttle_Full_Forward"><!-- event manipulating all throttles (declared for each throttle preset) -->
                      <Param>1</Param>
                  </Binding>
                  <Binding Alias="ENGINE1_All_Throttle_Full_Backward"><!-- event manipulating all throttles (declared for each throttle preset) -->
                      <Param>0</Param>
                  </Binding>
                  <Binding Alias="ENGINE1_All_Throttle_Idle"><!-- event manipulating all throttles (declared for each throttle preset) -->
                      <Param>0</Param>
                  </Binding>
                  <Binding Alias="ENGINE1_Throttle_#THROTTLE_ID#_Full_Forward">
                      <Param>1</Param>
                  </Binding>
                  <Binding Alias="ENGINE1_Throttle_#THROTTLE_ID#_Full_Backward">
                      <Param>#LOWER_POSITION_PCT_OVER_100#</Param>
                  </Binding>
                  <Binding Alias="ENGINE1_Throttle_#THROTTLE_ID#_Idle">
                      <Param>0</Param>
                  </Binding>
                  <!-- EventIDs -->
                  <Binding EventID="THROTTLE_FULL">
                      <Param>1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE_CUT">
                      <Param>0</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_FULL">
                      <Param>1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_CUT">
                      <Param>0</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_SET">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_AXIS_SET_EX1">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
                  <Binding EventID="AXIS_THROTTLE#THROTTLE_ID#_SET">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
                  <Binding EventID="THROTTLE_SET">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
                  <Binding EventID="THROTTLE_AXIS_SET_EX1">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
                  <Binding EventID="AXIS_THROTTLE_SET">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
              </Bindings>
          </Set>
          </Preset>
      </Presets>
    </InputEvent>

And this in my CustomEngineModelling.xml

XML:
  <!-- Mixture Ratio -->
  <Macro Name="MixtureRatio">
    (A:RECIP MIXTURE RATIO:1, ratio)
  </Macro>

  <Macro Name="MaxDrop">
    6
  </Macro>

  <!-- random number times 30 equals a number between 0 and 30. Then adding 30 makes it between 30 and 60. -->
  <Macro Name="RandomTimer">
    rand 30 * 30 +
  </Macro>

<Template Name="Spark_Fouling">

  <!-- Create a timing mechanism we can use to create the fouling, we want it to get worse over time if the user doesn't do anything -->
  <Update Frequency="1">
    (A:ENG COMBUSTION:1, bool) 1 ==
    @MixtureRatio 0.07 &gt; and
    if{
      (L:G36XIP_ELAPSED_TIME) 1 + (&gt;L:G36XIP_ELAPSED_TIME)
    } els{
      0 (&gt;L:G36XIP_ELAPSED_TIME)
    }
  </Update>

  <!-- Create the trigger based on the elapsed time which checks if the fouling might happen -->
  <Update Frequency="1">
    (L:G36XIP_ELAPSED_TIME) @RandomTimer &gt;
        if{
            1 (&gt;L:G36XIP_FOUL, bool)
        } els{
            0 (&gt;L:G36XIP_FOUL, bool)
    }
  </Update>


  <Update Frequency="12">
    (L:G36XIP_FOUL, bool) 1 ==
    IF{
      (L:MyThrottleLvar,number) 100 * @MaxDrop - 163.84* (&gt;K:THROTTLE_SET)
    } els{
      (L:MyThrottleLvar,number) 16384 * (&gt;K:THROTTLE_SET)
    }
  </Update>

</Template>

When I move the throttle it jumps to 0%
 
Hi

I think so, sorry I'm not that great with the XML stuff.

I have this in the Bonanza_g36_interior.xml file

XML:
<!-- intercepting throttle input #####################################-->
        <Component ID="throttleController">
      <UseTemplate Name="CUSTOM_THROTTLE_CONTROLLER">
        <THROTTLE_ID>1</THROTTLE_ID>
        </UseTemplate>
    </Component>

    <Template Name="CUSTOM_THROTTLE_CONTROLLER">
      <Parameters Type="Default">
        <INPUT_EVENT_ID_SOURCE>ENGINE1</INPUT_EVENT_ID_SOURCE>
      </Parameters>
      <UseTemplate Name="ASOBO_Interaction_Base_Template">
        <USE_INPUT_EVENT_ID>ENGINE1</USE_INPUT_EVENT_ID>
      </UseTemplate>
    </Template>

    <InputEvent ID="ENGINE1">
      <Presets>
        <Extend Target="ASOBO_GIE_Anim_Handling">
          <Parameters Type="Default">
            <INPUT_EVENT_ID_SOURCE>ENGINE1</INPUT_EVENT_ID_SOURCE>
          </Parameters>
            </Extend>
        <INPUT_EVENT_ID_SOURCE>ENGINE1</INPUT_EVENT_ID_SOURCE>
          <Preset ID="ENGINE1_Throttle_#THROTTLE_ID#">
            <INCREMENT>0.1</INCREMENT>
            <UPPER_LIMIT>16384</UPPER_LIMIT>
            <LOWER_LIMIT>(A:THROTTLE LOWER LIMIT, position 16k)</LOWER_LIMIT>
              <INIT_CODE>(A:GENERAL ENG THROTTLE LEVER POSITION:#THROTTLE_ID#, position 16k) 16384 / s0 (&gt;O:ENGINE_Throttle_#THROTTLE_ID#_Position)</INIT_CODE>

            <Tooltip>
              <Icon>MOVE_AXIS_Y</Icon>
              <Interaction>PRIMARY_DOWN+Y_AXIS</Interaction>
              <InteractionLockable>Y_AXIS</InteractionLockable>
              <TTDescription RPN="True">@TT_Package.ENGINE_PUSH_TOGA_ACTION</TTDescription>
              <TTValue RPN="True">(A:GENERAL ENG THROTTLE LEVER POSITION:1, percent) '%.1f%%' @sprintf</TTValue>
            </Tooltip>
            <Value>
              <Units>percent</Units>
              <Code>(O:ENGINE_Throttle_#THROTTLE_ID#_Position)</Code>
              <Init>(A:GENERAL ENG THROTTLE LEVER POSITION:#THROTTLE_ID#, position 16k) 16384 / (&gt;O:ENGINE_Throttle_#THROTTLE_ID#_Position)</Init>
                <WatchVars>
                  <Simvar ID="GENERAL ENG THROTTLE LEVER POSITION:#THROTTLE_ID#"/>
                </WatchVars>
            </Value>
            <Inc>
              <Code>(L:THROTTLE#THROTTLE_ID#_SET,number) p0 + (&gt;B:ENGINE1_Throttle_#THROTTLE_ID#_SET)</Code>
                <Parameters>
                  <Param Type="Float" RPN="True">p0</Param>
              </Parameters>
              <Bindings>
                  <Binding EventID="THROTTLE_INCR"><!-- event manipulating all throttles (declared for each throttle preset) -->
                    <Param>0.1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE_INCR_SMALL"><!-- event manipulating all throttles (declared for each throttle preset) -->
                    <Param>0.05</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_INCR">
                    <Param>0.1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_INCR_SMALL">
                    <Param>0.05</Param>
                  </Binding>
              </Bindings>
            </Inc>
            <Dec>
              <Code>(L:THROTTLE#THROTTLE_ID#_SET,number) p0 - (&gt;B:ENGINE1_Throttle_#THROTTLE_ID#_SET)</Code>
              <Parameters>
                <Param Type="Float" RPN="True">p0</Param>
              </Parameters>
              <Bindings>
                <Binding EventID="THROTTLE_DECR"><!-- event manipulating all throttles (declared for each throttle preset) -->
                    <Param>0.1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE_DECR_SMALL"><!-- event manipulating all throttles (declared for each throttle preset) -->
                    <Param>0.05</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_DECR">
                        <Param>0.1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_DECR_SMALL">
                    <Param>0.05</Param>
                  </Binding>
                </Bindings>
            </Dec>
            <Set>
              <Code>p0 0 max 1 min s0 (&gt;L:THROTTLE#THROTTLE_ID#_SET,number) l0 (&gt;O:ENGINE_Throttle_#THROTTLE_ID#_Position)</Code>
              <Parameters>
                <Param Type="Float" RPN="True">p0</Param>
              </Parameters>
              <Bindings>
                <!-- Aliases -->
                  <Binding Alias="ENGINE1_All_Throttle_Full_Forward"><!-- event manipulating all throttles (declared for each throttle preset) -->
                      <Param>1</Param>
                  </Binding>
                  <Binding Alias="ENGINE1_All_Throttle_Full_Backward"><!-- event manipulating all throttles (declared for each throttle preset) -->
                      <Param>0</Param>
                  </Binding>
                  <Binding Alias="ENGINE1_All_Throttle_Idle"><!-- event manipulating all throttles (declared for each throttle preset) -->
                      <Param>0</Param>
                  </Binding>
                  <Binding Alias="ENGINE1_Throttle_#THROTTLE_ID#_Full_Forward">
                      <Param>1</Param>
                  </Binding>
                  <Binding Alias="ENGINE1_Throttle_#THROTTLE_ID#_Full_Backward">
                      <Param>#LOWER_POSITION_PCT_OVER_100#</Param>
                  </Binding>
                  <Binding Alias="ENGINE1_Throttle_#THROTTLE_ID#_Idle">
                      <Param>0</Param>
                  </Binding>
                  <!-- EventIDs -->
                  <Binding EventID="THROTTLE_FULL">
                      <Param>1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE_CUT">
                      <Param>0</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_FULL">
                      <Param>1</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_CUT">
                      <Param>0</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_SET">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
                  <Binding EventID="THROTTLE#THROTTLE_ID#_AXIS_SET_EX1">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
                  <Binding EventID="AXIS_THROTTLE#THROTTLE_ID#_SET">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
                  <Binding EventID="THROTTLE_SET">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
                  <Binding EventID="THROTTLE_AXIS_SET_EX1">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
                  <Binding EventID="AXIS_THROTTLE_SET">
                      <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                  </Binding>
              </Bindings>
          </Set>
          </Preset>
      </Presets>
    </InputEvent>

And this in my CustomEngineModelling.xml

XML:
  <!-- Mixture Ratio -->
  <Macro Name="MixtureRatio">
    (A:RECIP MIXTURE RATIO:1, ratio)
  </Macro>

  <Macro Name="MaxDrop">
    6
  </Macro>

  <!-- random number times 30 equals a number between 0 and 30. Then adding 30 makes it between 30 and 60. -->
  <Macro Name="RandomTimer">
    rand 30 * 30 +
  </Macro>

<Template Name="Spark_Fouling">

  <!-- Create a timing mechanism we can use to create the fouling, we want it to get worse over time if the user doesn't do anything -->
  <Update Frequency="1">
    (A:ENG COMBUSTION:1, bool) 1 ==
    @MixtureRatio 0.07 &gt; and
    if{
      (L:G36XIP_ELAPSED_TIME) 1 + (&gt;L:G36XIP_ELAPSED_TIME)
    } els{
      0 (&gt;L:G36XIP_ELAPSED_TIME)
    }
  </Update>

  <!-- Create the trigger based on the elapsed time which checks if the fouling might happen -->
  <Update Frequency="1">
    (L:G36XIP_ELAPSED_TIME) @RandomTimer &gt;
        if{
            1 (&gt;L:G36XIP_FOUL, bool)
        } els{
            0 (&gt;L:G36XIP_FOUL, bool)
    }
  </Update>


[CODE]<Update Frequency="12">
    (L:G36XIP_FOUL, bool) 1 ==
    IF{
      (L:THROTTLE1_SET,number) 100 * @MaxDrop - 163.84* (&gt;K:THROTTLE_SET)
    } els{
      (L:THROTTLE1_SET,number) 16384 * (&gt;K:THROTTLE_SET)
    }
  </Update>

</Template>[/CODE]

When I move the throttle it jumps to 0%

can you try and change the (L:MyThrottleLvar,number) to (L:THROTTLE1_SET,number) , the latter is the one the actually holds the throttle values, Apologies for not being clear

code to be:
XML:
<Update Frequency="12">

    (L:G36XIP_FOUL, bool) 1 ==

    IF{

      (L:THROTTLE1_SET,number) 100 * @MaxDrop - 163.84* (&gt;K:THROTTLE_SET)

    } els{

      (L:THROTTLE1_SET,number) 16384 * (&gt;K:THROTTLE_SET)

    }

  </Update>
 
Thanks for all your help!

I did spot my mistake after posting and reading through the code again, have just tried the above and the throttle still drops to 0% when moving the throttle sadly.

It's strange because the time code shouldn't be even letting the (L:THROTTLE1_SET,number) 100 * @MaxDrop - 163.84* (&gt;K:THROTTLE_SET) line run at all
 
Last edited:
can you track the value of (L:THROTTLE1_SET,number) on it's own in the modelbehabiours L:vars tab? does it change with throttle input (joystick or button) or remains at 0? just to eliminate whether the intercept code is the culprit or not.

EDIT: oh and the intercept code will take over the throttle controls competely , so no (&gt;K:THROTTLE_SET) is triggered until you trigger it yourself in the code..
 
Looking at both the Simvar Watcher and SpadNext I can see the L:THROTTLE1_SET changes between 0 and 1 so I think your intercept code is ok?
 
got it, since you are using templates , can you try setting up the update loops like this (mind the IDs if you have multiple update components):
Code:
    <Component ID="UpdateLoop1">
        <UseTemplate Name="ASOBO_GT_Update">
            <FREQUENCY>12</FREQUENCY>
            <UPDATE_CODE>
                    (*Update code goes here*)
            </UPDATE_CODE>
        </UseTemplate>
    </Component>
 
I would set up the file like this , I didn't get the chance to test this but this is generally how I do templates, updates and how I call them (by creating a component the uses the template)

XML:
  <!-- Mixture Ratio -->
  <Macro Name="MixtureRatio">
    (A:RECIP MIXTURE RATIO:1, ratio)
  </Macro>

  <Macro Name="MaxDrop">
    6
  </Macro>

  <!-- random number times 30 equals a number between 0 and 30. Then adding 30 makes it between 30 and 60. -->
  <Macro Name="RandomTimer">
    rand 30 * 30 +
  </Macro>


<Component ID="Call_Spark_Fouling">
    <UseTemplate Name="Spark_Fouling">
    </UseTemplate>
</Component>

<Template Name="Spark_Fouling">
  <Component ID="UpdateLoop1">
        <UseTemplate Name="ASOBO_GT_Update">
            <FREQUENCY>1</FREQUENCY>
            <UPDATE_CODE>
                    (A:ENG COMBUSTION:1, bool) 1 ==
                    @MixtureRatio 0.07 &gt; and
                    if{
                    (L:G36XIP_ELAPSED_TIME) 1 + (&gt;L:G36XIP_ELAPSED_TIME)
                    } els{
                    0 (&gt;L:G36XIP_ELAPSED_TIME)
                    }
            </UPDATE_CODE>
        </UseTemplate>
    </Component>
    
  <Component ID="UpdateLoop2">
        <UseTemplate Name="ASOBO_GT_Update">
            <FREQUENCY>1</FREQUENCY>
            <UPDATE_CODE>
                (L:G36XIP_ELAPSED_TIME) @RandomTimer &gt;
                if{
                1 (&gt;L:G36XIP_FOUL, bool)
                } els{
                0 (&gt;L:G36XIP_FOUL, bool)
                }
            </UPDATE_CODE>
        </UseTemplate>
    </Component>   
  <Component ID="UpdateLoop3">
        <UseTemplate Name="ASOBO_GT_Update">
            <FREQUENCY>12</FREQUENCY>
            <UPDATE_CODE>
            (L:G36XIP_FOUL, bool) 1 ==
            if{
            (L:THROTTLE1_SET,number) 100 * @MaxDrop - 163.84* (&gt;K:THROTTLE_SET)
            } els{
            (L:THROTTLE1_SET,number) 16384 * (&gt;K:THROTTLE_SET)
            }
            </UPDATE_CODE>
        </UseTemplate>
    </Component>   

</Template>
 
Back
Top