FSX:SE Direct engine parameter manipulation through simConnect

#21
Hey folks,
I took all your input in and started working around this issue in the way most of you suggested: by overriding the throttle axis in the gauge. But now I'm wondering if there's a best-practice for the overrides of the controls. The obvious issue is the tug-of-war between the joystick control and the gauge and what I don't want is any spikes in the throttle due to it. So at what point and how should the throttle axis being read and set?

Right now I am using the gauge event system to read the current throttle setting on change and pass the value to an LVar that represents the lever in the sim. I do my manifold pressure calculations in my regular update cycle and in the same function pass the value back to the throttle axis. I was wondering if that's really the most efficient way to do it, or if there's some other solution for it (maybe using simConnect?).
 
#22
hope I not missed understood what your point. this what I do using SimConnect to manipulated Avar

make definition for Avar target
C++:
SimConnect_AddToDataDefinition(hs, DEF_AC_EXIT_3, "EXIT OPEN:1", "percent");
masking command to reach Sim
C++:
SimConnect_MapClientEventToSimEvent(hs, EV_AC_EXIT, "TOGGLE_AIRCRAFT_EXIT");
SimConnect_AddClientEventToNotificationGroup(hs, G_MASKS, EV_AC_EXIT, true);
SimConnect_SetNotificationGroupPriority(hs, G_MASKS, SIMCONNECT_GROUP_PRIORITY_HIGHEST_MASKABLE);
sending value to Avar
C++:
SimConnect_SetDataOnSimObject(hSc, DEF_AC_EXIT_1, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(double), &lv.exit_1);
manipulate value from this var: lv.exit_1

in your case you need to read throttle axis position then send value to your own engine code manipulation and lastly send to var ( in my case lv.exit_1 )
complete taking over is needed in this case

update:
add missing masking priority code
 
Last edited:
#23
Hi,
sorry for the late reply, I was away for the weekend building Lego Lockheed Vegas with my nephew.




My question is not so much in regards to simConnect, but rather about the overall structure of overriding the throttle axis. The issue is that I need to find out when the user is moving the throttle axis I then need to set the animation of my throttle to the correct value that corresponds with this using a custom L:var. Then I need to calculate the "real" throttle setting to achieve a certain manifold pressure as calculated by my code. Lastly I need to set the throttle axis to that value using either simconnect or events.

My current solution is the following:
1. The main update function is called by the main callback function of the gauge at the "PANEL_SERVICE_PRE_UPDATE" event.
2. In this function, I first read the current throttle axis by accessing the simvar "GENERAL ENG THROTTLE LEVER POSITION:1", pass it to "L:THROTTLE LEVER 1,number" for the lever animation of the 3d model.
3. I calculate the manifold pressure and an according throttle axis setting using a PID controller. This part is still in the works though.
4. I use the "KEY_THROTTLE1_SET" to set the throttle axis to the desired value.

So.... is that a good solution, or do you have a better way to do this? :wizard:
 

JB3DG

Resource contributor
#24
Actually, what Kalong was trying to explain to you is the exact method you should use.

You can intercept throttle key events and mask them from reaching the simulator using SimConnect, while taking their inputs and using them to drive your L var and internal engine simulations. You would then use SimConnect_SetDataOnSimObject to set the throttle sim var position directly to the desired value, rather than sending a key event.
 

JB3DG

Resource contributor
#25
hope I not missed understood what your point. this what I do using SimConnect to manipulated Avar

make definition for Avar target
C++:
SimConnect_AddToDataDefinition(hs, DEF_AC_EXIT_3, "EXIT OPEN:1", "percent");
masking command to reach Sim
C++:
SimConnect_MapClientEventToSimEvent(hs, EV_AC_EXIT, "TOGGLE_AIRCRAFT_EXIT");
SimConnect_AddClientEventToNotificationGroup(hs, G_MASKS, EV_AC_EXIT, true);
SimConnect_SetNotificationGroupPriority(hs, G_MASKS, SIMCONNECT_GROUP_PRIORITY_HIGHEST_MASKABLE);

sending value to Avar
C++:
SimConnect_SetDataOnSimObject(hSc, DEF_AC_EXIT_1, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(double), &lv.exit_1);
manipulate value from this var: lv.exit_1

in your case you need to read throttle axis position then send value to your own engine code manipulation and lastly send to var ( in my case lv.exit_1 )
complete taking over is needed in this case
@kalong you missed one step in the masking commands from the simulator. Added in the quote in red.
 
#28
Thanks for your explanations, I wasn't aware that you could actually prevent the inputs from being processed by the sim. I still have a question regarding the setting of the overrides. I'd like to keep the general structure of my module, which is that I've got one update function every tick that is taking care of all simulation calculations and I want to use it to calculate the new throttle position and send the new value through to simConnect. Hence there might be a gap between simConnect triggering the event and my module setting the new override. Is that an issue?
 
#29
as long as you not targeted in slow and smooth model animation, updating function every tick isn't an issue. Simconnect can work in everyframe, so it would not be a problem to work with xml that have 18hz tick
the Osprey is sample everything what you want which is that beyond of sim limitation, like
SimConnect work with XML as VTOL (Rob provided the xml code),
the door can be mask and unmask by SimConnect depend on it needed,
the lighting system is fully masking by SimConnect.

note:
not all avars can manipulated via SimConnect, it only avars that have "Y" at settable in SDK documentations.
 
#30
Excellent thanks!!


Edit:
forget that I asked. It doesn't even make any sense since the return type is different for each event. My current setup is that I combine all the throttle events under one notification group and set the max. priority to that group.

Another follow-up:
The AXIS_THROTTLE1_SET event only triggers if a joystick axis is used. I know I can set up additional structures to catch keyboard events as well to trap F1-F4 events. But is it possible to combine the trap into one routine that is called if any of the possible inputs is caught?


New question:
Can I claim authority over all input events in this manner? I.e. can I intercept any of the events listed in the SDK and override the variable in this manner?
 
Last edited:

taguilo

Resource contributor
#31
Indeed you need to capture ALL throttle related events.

I prefer to use an Event Handler for that, IMO more simple to implement than mapping through Simconnect.
Then, whithin each event definition in the handler function you do use Simconnect to directly write "GENERAL ENG THROTTLE LEVER POSITION:1" Avar.

Tom
 
Top