• 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.

Custom elevator trim using XML tools.

Messages
407
Country
ca-britishcolumbia
In another thread, Bjoern asked me if could post my code for a custom elevator trim system using XML tools. The default trim moves in increments that are too big for really accurate trim and moves too fast if the key or button is held down. This system works with the default trim commands made with the keyboard or joystick button. Some of the code relates to the animation of the "suitcase" trim handles on the DC8 and can be disregarded. That includes the timer -- it only relates to the handles.

Code:
<!--      Trim       -->
 
     'ELEV_TRIM_UP' (>C:XMLEVENTS:EventName,string)
     '40 (>L:DC8_trim_hdl, number)
     40 (>L:DC8_trim_hdl_rt, number)
     (P:ABSOLUTE TIME,seconds) (>L:trim_time,seconds)
     1 (>L:trim_up, bool)'
(>C:XMLEVENTS:EventString,string)
   
   'ELEV_TRIM_DN' (>C:XMLEVENTS:EventName,string)
     '0 (>L:DC8_trim_hdl, number)
     0 (>L:DC8_trim_hdl_rt, number)
     (P:ABSOLUTE TIME,seconds) (>L:trim_time,seconds)   
     1 (>L:trim_down, bool)'
  (>C:XMLEVENTS:EventString,string)

(P:ABSOLUTE TIME,seconds) (L:trim_time, seconds) - 0.1 &gt;
if{ 20 (>L:DC8_trim_hdl, number) }

(P:ABSOLUTE TIME,seconds) (L:trim_time, seconds) - 0.15 &gt;
if{ 20 (>L:DC8_trim_hdl_rt, number) }


(L:trim_up, bool) 1 ==
if{ (L:elevator_trim_temp, radians) 0.00045 + (>C:SIMVARS:Elevator Trim Position,radians)
     0 (>L:trim_up, bool)
(C:SIMVARS:Elevator Trim Position,radians) (>L:elevator_trim_temp, radians)    
   }

   (L:trim_down, bool) 1 ==
if{ (L:elevator_trim_temp, radians) 0.00045 - (>C:SIMVARS:Elevator Trim Position,radians)
     0 (>L:trim_down, bool)
(C:SIMVARS:Elevator Trim Position,radians) (>L:elevator_trim_temp, radians)    
   }
 
Ah, I see how you did it. Without the animation-specific bits, it boils down to this:

Code:
<!-- Trim -->
'ELEV_TRIM_UP' (>C:XMLEVENTS:EventName,string)
'1 (>L:trim_up, bool)'
(>C:XMLEVENTS:EventString,string)

'ELEV_TRIM_DN' (>C:XMLEVENTS:EventName,string)
'1 (>L:trim_down, bool)'
(>C:XMLEVENTS:EventString,string)

(L:trim_up, bool) 1 ==
if{ (L:elevator_trim_temp, radians) 0.00045 + (>C:SIMVARS:Elevator Trim Position,radians)
0 (>L:trim_up, bool)
(C:SIMVARS:Elevator Trim Position,radians) (>L:elevator_trim_temp, radians) }

(L:trim_down, bool) 1 ==
if{ (L:elevator_trim_temp, radians) 0.00045 - (>C:SIMVARS:Elevator Trim Position,radians)
0 (>L:trim_down, bool)
(C:SIMVARS:Elevator Trim Position,radians) (>L:elevator_trim_temp, radians) }


The event trap can be exchanged with an ordinary KeyMap object, which will make the actual script shorter. And to keep things sane, there can be a degree-based macro value that will determine the trim gain per keystroke.

Code:
<!-- Elevator Trim Gain -->
<Macro Name="TrimGain">
<MacroValue>
0.025
</MacroValue>
</Macro>
<!-- Key Trap and Script -->
<KeyMap>
<Trigger id="Trim Up">
<KeyEvent>ELEV_TRIM_UP</KeyEvent>
<Script>
(L:elevator_trim_temp, radians) @TrimGain 0.0174533 * + d (>C:SIMVARS:Elevator Trim Position,radians) (>L:elevator_trim_temp, radians)
</Script>
</Trigger>
<Trigger id="Trim Down">
<KeyEvent>ELEV_TRIM_DOWN</KeyEvent>
<Script>
(L:elevator_trim_temp, radians) @TrimGain 0.0174533 * - d (>C:SIMVARS:Elevator Trim Position,radians) (>L:elevator_trim_temp, radians)
</Script>
</Trigger>
</KeyMap>

(Note: The XML tags were written from heart and thus may not work without modification.)


All in all, this looks very useful. Thanks for posting it!
 
Last edited:
No problem. There are several snippets of your code combed from the forums in my aircraft, so it's the least I could do.
 
The event trap can be exchanged with an ordinary KeyMap object, which will make the actual script shorter.

That will work in VC views only. If trim would be also managed in other views, it´s necessary to capture those scripts using XMLEVENTS class, as Michael does.

Tom
 
That will work in VC views only. If trim would be also managed in other views, it´s necessary to capture those scripts using XMLEVENTS class, as Michael does.

Understood for external views , but keymaps should still work when the gauge is added to a 2D panel?
 
Yes, Keymaps work if added to 2D panels as well.

In External view, the 2D panel with Keymaps defined must be visible for those to work.
in VC view, Keymaps in a 2D panel won't be visible until the panel is first time displayed. After then they work no matter it is visible or hidden.

Tom
 
I guess this is what you get when you don't use 2D panels anymore (except for subpanel popups). Thanks, guys.
 
The default trim moves in increments that are too big for really accurate trim and moves too fast if the key or button is held down.
Surely the answer to that is "Change it". Why bother writing a custom gauge when the situation can be changed without any additional overhead.
First, each press increments the trim by 1/1024 of its range. If that gives too big a pitch change, then decrease the range in the aircraft.cfg [airplane_geometry] section.
Second, the trim effect per radian is adjustable in the air file, so each increment has a value that can be changed. Either Record 1101 Pitch Cm_dt pitch moment or the same thing in 1541.
Third, the rate of repeat is set by the position of the slide in Options settings controls Simulation Controls Buttons and Keys. None, slow, fast. You can also just blip it for small response.

Roy
 
Aircraft Airfile Manager only has an entry named "Cm trim" in table 1541 with a value of "-3" for the aircraft in question. I assume that I need to decrease the value (while leaving "trim_sensivity" and "trim_limit" untouched) in order to get a finer trim response?
 
Roy, as far as I can see, the air file entry 1101 Pitch Cm_dt pitch moment (which I was not familiar with) that you refer to only effects the effectiveness of the trim, not the rate of change in nominal degrees or radians. If you change the effectiveness of the trim with either that entry or in the cfg file you are also going to change the effective range of trim available in ways that you may not want. My aircraft uses the whole stabilizer for trim from 1/2' leading edge down to 10' leading edge up which can be very apparent in the visual model getting towards 10'. And the aircraft can be loaded so almost the whole 10' nose up trim is needed for rotation. So as a starting point it's easiest for me to have the range and nominal trim correspond to the real numbers and use that to animate the visual model. I then use the custom gauge calibrated to give me half a degree of trim per second (as per the real aircraft) when the button or key is held down (with repeat set to slow). Finally I use the effectiveness entry in the aircraft.cfg file to give the results I want which I determine by setting takeoff trim for a given MAC to what the manual says it should be and then adjusting the effectiveness until the aircraft will do the initial climb out with little or no displacement of the yoke.

Perhaps it could be done some other way, but this method works for me.
 
Last edited:
Michael,
Your method is perfectly valid and might be the best way to achieve what you want. However, there could be another way. My point was that your statement about default trim implied you were stuck with it and you are not. Trim effectiveness, range and rate of application can be changed. It is not essential to create a custom gauge.

Changing trim effectiveness can not affect the range of movement, just the pitch moment per angle. If you doubled cm dt, you would still have the same range but it would be twice as effective. You would have the same effect at half the trim deflection. Range value in the .cfg is actually half the total range 10degrees means plus and minus 10.

Small point, MAC does not vary, CG as percent MAC does.

What your trim setting does, and what every take-off setting does is to be in trim just above the lift-off speed for the initial climb. Where this occurs in terms of degrees/inches or whatever units, is a function of the pitch moment at zero AOA, which can be set in the air file and the pitch moment variation with AOA Record 473.

I'm sure you know this but what your animation does has nothing to do with how the aircraft flies. Your aircraft may just have an all-moving stab, but the sim uses the stab for trim and elevators for pitch variation.

I wanted you to be aware of what can be varied as far as trim is concerned and I believe you are now.

Roy

PS 10 inches stab leading edge up would give you nose down trim. Typically 10 inches nose up trim would be achieved by lowering the stab leading edge 10 inches. It would be gauged as nose up because that is what it does. Usually there is more nose up trim than nose down trim needed to fly the whole envelope in trim.
 
Last edited:
If I didn't understand that the model animation has nothing to do with the flight model, or that putting the leading edge of a stabilizer down gives nose up trim, I would have no business developing an airliner or any aircraft for that matter. But maybe I could have explained my reasoning more clearly.

I meant degrees by the apostrophe symbol, not inches; sorry if that wasn't clear.

You are right; I should have said the center of gravity as a % of MAC.

My point about the visual model is that if FSX reads your trim as going from 1/2 degree nose down to 10 degrees nose up, you don't have to scale anything to animate the visual model or the trim indicator in the VC. It's just easier. There can be a one to one relationship with what FSX understands the trim to be and the animation. When the whole stabilizer is roating through 10 1/2 degrees, the animation needs to be accurate for the model to look right.

Finally, and this was my main point, you cannot change the trim effectiveness, without changing the effective range. I never said it would change the nominal range.

Let's say that my trim is set up such that it works pretty well and when I set trim based on what it should be for a given weight and c.g. of %MAC, the aircraft responds as it should on rotation and climb out, however, you want to define that. But let's assume as well that the trim moves too fast when I hold the button down. The trim is too coarse to trim for level flight hands off and I can achieve maximum nose up trim in 10 seconds instead of 20 seconds. It's too powerful too quickly. So if I change the effectiveness of the trim (the change in pitch moment per degree or radian of trim), it will solve the too coarse problem, (although not the time to achieve full trim). But at the maximum amount of trim, the trim is now inadequate. I have changed the effective range. I change one and it affects the other. So now I have to change the trim limit in the aircraft.cfg file, which I guess would also improve time to achieve full trim (though probably not accurately). The changes needed would be very significant. The default trim is about 8x as fast as what I need. And then the animations have to be scaled. Maybe it could be done, and maybe would be more efficient in CPU use, but my way I can change each element with precision without having to change any others.
 
Last edited:
By the way, I don't see the default rate of trim change as being 1/1024 of the range. With the default system I get about between 0.1 and 0.15 of a degree per press (it isn't consistent). If we take 0.1 degrees over a 20 degree range we get 0.005 percent of the range per button press. 1/1024 is 0.00098 rounded off. Furthermore, if I change the range in the cfg to just 1 degree, I get exactly the same increments using default trim. The increment is fixed and has no relationship to the range.

My system also has the advantage of consistent increments.

Another point as to why I need custom trim increments: The DC-8 has two trim systems for the stabilizer, one hydraulic and one electric. The electric trim is very slow and operates 1/17 of a degree per second. It is used by the autopilot and can be used by the flight crew if the hydraulic system fails. Since I do not at present intend to model failures I am not sure if I will included the electric trim function, but I want to keep the option open.
 
One of the best things about posting here is that you often learn something new or find out that something you took as true is not quite true.
All the air file tools and documents state that the rate of change of trim per key press is 1/1024 of the range.
Reading out trim setting to two decimal places and setting my trim control to zero repeat, pressing the key 50 times and then dividing the trim change by 50 gives me 0.0572 degrees per key press.
It is consistent when you have zero repeat or use a keyboard selection to move it. And you are correct it moves the same amount irrespective of the range set in the aircraft.cfg
0.0572 degrees is 1/1000 of a radian. So 1000 key presses will give a full radian. It probably is 1024 but I have better things to do.
Cm_ dt has units of Cm per radian and so changing it has no effect on the amount of trim deflection, it just affects how much pitch moment is added or subtracted from the existing moment.

The reason I mentioned that the leading edge trim direction is opposite to what the trim setting is was this "My aircraft uses the whole stabilizer for trim from 1/2' leading edge down to 10' leading edge up which can be very apparent in the visual model getting towards 10'." I read that literally as 1/2° down to 10° up at the leading edge. Hint ALT248.

Another good reason for having code to set the trim is that by default it comes up at zero and that may not be the take-off setting.
Roy
 
I have repeat set to slow as no one is going to fly this having to make dozens of key presses to set takeoff trim. And I use a joystick button for trim as I imagine most people do. I didn't test it with repeat off or with a keyboard.

I see what you mean about leading edge down etc. I stated it the wrong way round. I blame my influenza.
 
Last edited:
Back
Top