PDA

View Full Version : Virtual Throttle "While Sequence"



Scooter_Downunder
13th October 2008, 04:30 PM
I was wondering if someone could assist with a little project I started developing during the weekend, but a few months in rough planning. I am writing a script for my Pro throttle and Fighter Stick which does the following:

The concept involves a Pro-Throttle being moved up and down it's Z Axis, while (what I term as) a "virtual throttle" waits for engagement by the user pressing JS2.b3. The Virtual Throttle is then moved up and down with the throttle, while maintaining a set constant distance. Where upon release, the virtual throttle disengages and remains until it's engaged again

The "Z" axis is Js2.a3, labeled as True_Throttle and defined to cms.a1
while the "Virtual Throttle" is defined to cms.a3

I have set the Virtual throttle to a location of 128 for testing, and the throttle set for at 255 (At the bottom). If you now inch the throttle up until it reaches 240, and js2.b3 is pressed, this will initiate the WAIT sequence and execute the required calculation:

240 > 128
In this case: if ( [True_Throttle > Virtual_Throttle] ) then //

240 - 128
Throttle_DELTA = True_Throttle - Virtual_Throttle;

endif


The calculation derived = "112"

As js2.b2 is held down the next sequence & calculation is performed with the while sequence:

240 > 128
if ( [True_Throttle > Virtual_Throttle] ) then

240-112
Virtual_Throttle = True_Throttle - Throttle_DELTA;

endif





The Virtual_throttle variable will of course equal 128, and a constant distance of 112 units will be maintained "while" js2.b3 is pressed.

I guess my concept is analogous to a duel throttle set up, with the pilot pushing the right throttle forward, and the left throttle moves forward at the same time, and maintains a constant 112 units seperation in front.

The virtual throttle now reaches "0" and its limit is met, while the True throttle is at 112. As the The true throttle is advanced the Virtual throttle stays at zero until the True throttle rests along side it.

This is where things get a little weird:

With the 2 throttles at the equal position value of "0". Or just picture them both in a fully advanced state sitting alongside each other on throttle console:

If I maintain holding js2.b3, and start to retard the true throttle back. The virtual throttle will lag 112 units behind. Therefore, it will not move until 112 units have passed. This fits the equation as we'd expect. But what I don't get is when I disengage the js2.b3 at Zero , I would expect throttle Delta to be reset to Zero bringing the Virtual throttle and true throttle to equal values on the Z Axis. Hence, they should now move together as one. Except the Virtual throttle maintains the same constant value that's set by Throttle_DELTA ??

I have even tried clearing this variable with its own sequence which attempts to zero upon js2.b3 release. But it had no effect?

I have included the script as below with the variables needed to establish a working concept for anyone brave enough...LOL
I am also using CH Control Manager 4.20






%define FirstScan b255

%define Throttle_DELTA A1 // Calculated difference between
// Virtual and True throttle positions

%define True_Throttle cms.a1 // Display Z Axis
%define Virtual_Throttle cms.a3 // Virtual Throttle Z Axis

True_Throttle = js2.a3; // cms.a1 Display Z Axis


// These are setup for my test run:

If (not FirstScan) then

FirstScan = TRUE;
Virtual_Throttle = 128;
Throttle_DELTA = 0;

endif


sequence
wait (JS2.B3) ; // Wait until Button 2 clicks

Throttle_DELTA=0;

if ( [True_Throttle > Virtual_Throttle] ) then //
Throttle_DELTA = True_Throttle - Virtual_Throttle;
endif


if ( [True_Throttle < Virtual_Throttle] ) then //
Throttle_DELTA = Virtual_Throttle - True_Throttle;
endif


if ( [True_Throttle == Virtual_Throttle] ) then
Throttle_DELTA = 0;
endif
endsequence



sequence
while (js2.b3);

if ( [True_Throttle > Virtual_Throttle] ) then
Virtual_Throttle = True_Throttle - Throttle_DELTA;
endif


if ( [True_Throttle < Virtual_Throttle] ) then
Virtual_Throttle = True_Throttle + Throttle_DELTA;
endif


if ( [True_Throttle == Virtual_Throttle] ) then
Virtual_Throttle = True_Throttle;
Throttle_DELTA = 0;

endif
endsequence

Bob Church
15th October 2008, 03:28 AM
Hi Scooter,

If I understand you correctly, it should be easier than that. I'd try just setting up a toggle on js2.b3 that tells you whether it's engaged or disengaged. When it's engaged, set up the value. When it's disengaged, don't. Something like this:


script

// Set up an engaged/disengaged toggle
//
toggle( d1 ) = js2.b3;

// While it's engaged, calculate the virtual throttle
// value and transfer it to wherever it's going, I'm
// figure CMS.A1, but wherever it needs to end up.
// There's no need to wait for the calculation, it will
// happen in one pass anyway.
//
if( d1 ) then

// What you describe for a calculation method
// looks about right, I put in what I thought you
// wanted, but then it didn't look right, so I'm just
// going to let you work it out<g>.
//
cms.a1 = calculated value;

else

// It's not engaged, set the throttles equal (*ADDED*)
//
cms.a1 = js2.a3;

endIf

endScript

What's going to happen (I think. :) I didn't actually run it but it should show the idea in any case) is just that each click of js2.b3 is going to flip the state of the D1 "engaged" bit. If it's TRUE, the pseudo-throttle is engaged and so you do the calculation and send it where it needs to go for the virtual throttle (the assumed CMS.A1). When it's off, you won't be updating CMS.A1 (or wherever) and so it's just going to sit where it was when the toggle went FALSE.

I think that's enough to do what I think you're describing. If I've missed something let me know, but I've played with similar things before. One note. The limit on analog values actually sent to Windows, presumably your virtual throttle will be, are limited to 0..255 so it's going to be short on one end or the other by the offset, the virtual throttle is going to run off the end before the real throttle. I don't think you have to do anything about that, it's been awhile but it seems to me the CM limits it automatically, but you probably do need to be aware of it. If the virtual is below the actual and you pull the actual all the way back, they're going to both go to zero. The virtual will get limited and the real will eventually get to zero normally.

You might also try changing the "if( d1 ) then.." to "if( d1 AND CLOCKTICK ) then..". That causes it to only check when the character clock ticks which is less often then the script actually runs. Sometimes routines like that can eat a lot of time, CLOCKTICK limits that. If it turns out taking a noticeable hit on your FPS (unlikely), you might give it a shot.

Hope this helps! If it doesn't do what you want, let me know and we can take another look.

EDIT: To try and answer a couple of your other questions, FIRSTSCAN is supplied by the system now and is only true for one scan. I've never tried forcing it to another value and I'm not sure you can do that, but the first scan always resets the analog variables to 0. Having set it to zero, you still need to set the variable each time so it tracks the real Z axis. Otherwise it just sits where you left it. I've also modified the script to include an ELSE clause to do that. It should cause them to track. You can pick the real Z axis up directly in the GUI, it doesn't look to me like you're trying to do anything with it except use it in the calculation and using it directly avoids sending it through CMS.

The other change from what I think you're asking for is that you just need to click js2.b2, not hold it. Click it and it engages, click it and it disengages. If you need to hold it, lose the toggle and just base it on the switch state ( "if( js2.b2 ) then.." ) rather than using D1.

EDIT2: I tried to work out the math, but I don't think I had it right so I just passed the buck back to you.

Best regards,

- Bob

The StickWorks
http://www.stickworks.com

Scooter_Downunder
15th October 2008, 02:15 PM
Bob,

Thanks for taking your time to examine the code, and you raised an excellent point which I missed on the use of variables, especially " analogue."


"The virtual throttle is going to run off the end before the real throttle. I don't think you have to do anything about that, it's been awhile but it seems to me the CM limits it automatically, but you probably do need to be aware of it." 4.2 User Guide states:
"While analog variables can have a very wide range of values to allow some room for calculation. The values of the axes on real controllers, however, are always 0 through 255. The Control Manager calibration routines maintain this....................

It is up to the CMS script to see to it that the values have the proper range before being assigned to the CMS Controls. If a value less than zero is assigned to a CMS Controls axis, it will be treated as zero. If a value greater than 255 is assigned, then it will be treated as 255. Note that this only applies when the values are finally assigned to the CMS Controls so they can be used by the map. Values may frequently exceed this range during calculations, etc. and that will not create a problem for the CMS."


With the statement:
" %define Virtual_Throttle cms.a3 // Virtual Throttle Z Axis"
I just assumed that Virtual_Throttle as defined to cms.a3 could not automatically exceed a value of 255 or a value less than 0 :blush:. But this is not the case. I established a simple experiment to see if I could set the Virtual_Throttle variable to 125 (Middle of Z Axis) + 255 (A throttle phase out.....if you like). Total value of 380.
I then moved my Physical, or true throttle to top of the range and held JS2.B3 down, while moving the throttle towards me, back to 255. This dragged the Virtual Throttle back to 128, or middle range.

So in a simple summary: Just remember that the Anaglugue variables you use to calculate ranges can exceed Axes limits, but when applied to an exes only the top or bottom limits of an ases will be reached ie 0 to 255.

:idea:So therefore, I just simply impose the following limits when calculating the Virtual Throttle. Hence, if a value is calculated which exceeds <0 or >255, I simply impose an absolute.

if ([Virtual_Throttle <=0]) then
Virtual_Throttle = 0;


sequence
while (js2.b3);

if ( [True_Throttle > Virtual_Throttle] ) then

Virtual_Throttle = True_Throttle - Throttle_DELTA;

if ([Virtual_Throttle <=0]) then

Virtual_Throttle = 0;
endif
endif


if ( [True_Throttle < Virtual_Throttle]) then

Virtual_Throttle = True_Throttle + Throttle_DELTA;


if ([Virtual_Throttle >=255]) then

Virtual_Throttle = 255;
endif

endif


if ( [True_Throttle == Virtual_Throttle] ) then

Virtual_Throttle = True_Throttle;
Throttle_DELTA = 0;

endif

endsequence

Ans she works like a charm

Thanks you again for reading over and commenting on the code. I plan on posting and sharing my code when its finished, because it's certainly going to revolutionise my flying experience with duel engine, and possibly Quad Throttle planes while using just one throttle.

I would realy like to use it oneday with the new Eclipse flight yoke.:thumbsup:
Man that thing looks great.

:cheers:

PS I should have titled this post as..."The Outer Limits" :rofl:

Bob Church
15th October 2008, 07:50 PM
Hi Scooter,

>> Ans she works like a charm <<

Great! I'm glad it was some help!

One note on the limits. I you set a CMS Axis value, say cms.a1, to something outside the range, the value is clipped when it goes to Windows, but from the scripts view the value in cms.a1 doesn't really change. The value is read, clipped, and sent to Windows, but if your calculating and using cms.a1 to hold a value, the fact that it's sent to Windows doesn't propogate back into the script. IOW, if you set cms.a1 to 10000 and send that to Windows, Windows will get 255 clipped value but the script itself still sees cms.a1 as having the 10000 value.

Anyway, I'm glad to hear you got it sorted out. Have fun with it!

Best regards,

- Bob

The StickWorks
http://www.stickworks.com

akash
19th January 2009, 04:41 PM
The concept involves a Pro-Throttle being moved up and down it's Z Axis, while (what I term as) a "virtual throttle" waits for engagement by the user pressing JS2.b3. The Virtual Throttle is then moved up and down with the throttle, while maintaining a set constant distance. Where upon release, the virtual throttle disengages and remains until it's engaged again