PDA

View Full Version : Need some scripting help (okay alot!)


Manfromx
30-03-2004, 04:35 PM
Hey everyone, great resource here. I'm a big fan of the CH product line so far and I generally put together some decent profiles for myself.

I've never been good at scripting though, I don't really have a base knowledge to work off of there. So I was wondering if you guys could help out.

IL-2 has lots of Axis settings, things like prop pitch, mixture, flaps, trim etc etc.

Now when I was making my profile I hit upon the idea of making a button switch the Axis on my throttle to a different axis in CMS and voila! I can use all the axis in the game and just hit the approriate button, set whatever it is I need, let go of the button and I have my throttle back.

Unfortunately, if I'm at 100% throttle, hit the button for say prop pitch axis, then move the throttle to set the pitch to say 60% then let go of the button, then my throttle also goes to 60% as soon as I do:(.

Is there anyway to make my previous setting "stick" for a few seconds. So I hit the button, change my prop pitch, then release the button and have it ignore the input for say 1 - 2 seconds until I bring the throttle back to where I want it?

Thanks in advance guys, this is a bit much for me!

Bob Church
31-03-2004, 12:10 AM
I've looked at that myself a few times, just exploring possibilities. I'd work with internal variables to control the sim, the external variables (the real axis value) would just get transferred to the internal value at some appropriate time, e.g. you click a button and js1.a1 gets copied to cms.a1. Then cms.a1 is fed to the sim. Another button could transfer it to a different CMS axis which would control some other item.

It would be relatively simple to record the value from the axis when you clicked the button to set it, then watch for the raw data to change by maybe 5 counts or so before you let the actual value change. Use that to trigger a restart of the data from the axis itself to whatever the target was.

A little more elaborate idea was to not have the internal axis start moving until the external and internal axes were equal. For example, you have the primary internal axis at 80%. You hold the button and move your secondary internal axis to 20% and release the button. Now the external axis, the throttle handle or whatever is at 20% but the internal value is at 80%. Leave it at 80% internally until the external axis crosses 80% again, then start picking it up. You'd have to move the external axis forward, but as soon as it got sync'd with the internal value they'd lock up again.

A third method might just involve working with "differences". Say your internal axis is at 50% and your external axis is at 20%. You move the external axis to 30%, that would be +10%, your internal axis would go up 10% to 60%. This has an obvious disadvantage in that the handle for the external axis isn't necessarily anywhere near what the internal axis is telling the game, but it can be resync'd by moving it through it's full range. It'll bump up against the 0% and 100% external points and they'll have to realign.

- Bob

The StickWorks
http://www.stickworks.com

JNOV
01-04-2004, 09:31 PM
I've thought about this, too, particularly in line with Bob's second suggestion. The problem, in practice, is that when you switch back to a previously-controlled axis, you may not recall what it was set at. Thus, the only way to guarantee that you sync up is to sweep the throttle through its entire physical range. Something that would help is a peripheral that would display whatever internal data you wanted and that you could program to display the internal values of the various axes the throttle is controlling, as well as the value of the physical throttle. With such a system, at least you would know which direction and how much to move the throttle to sync the internal and physical throttles. Moreover, you could actually see the sync-up as the two values converge. I am working on this sort of a feedback system using an USB LCD display, but it is still very much a work in progress.

Another option (this looks like Bob's #3) when switching axes is to just "pretend" that the physical throttle is in the right place, so that deviations from where it was at the time of switching change the internal axis just as one would expect. For example, if the physical and internal throttles were at 80% when you switched over to the prop pitch axis, but the phyical throttle was at 30% when you switch back, moving the physical throttle to 35% would cause the internal representation to go to 85%, moving the physical throttle to 15% would cause the internal representation to go to 65%, etc.

This approach works fine until you "run out of physical throttle." To deal with this eventuality, you program small bands at each end of the physical throttle's throw (e.g., 0-5%, 95-100%) to be "relative" until synching is achieved. Thus, in the 35%/85% example posited above, if you want to take the internal throttle to 0%, you're going to run out of physical throttle first. But, what would happen is that when you enter the 0-5% "relative" zone, the internal throttle would continue to decrease until synching occurs or until the physical throttle is moved out of the zone. Once synching occurs, the "relative" zones are disbanded, and the internal throttle simply tracks the external one. You might augment this system with an "insta-sync" button that, when pressed, would snap the internal representation in-line with the physical throttle.

I've never tried this, but it seems like it might be useful in certain circumstances.

- JNOV

Bob Church
02-04-2004, 12:16 AM
I've looked at a couple of those variations myself. For the situation you mention where you "run out of handle", the relative thing, one thought I had was that the handle moved nothing unless some button was down. Maybe the four buttons on the front of the ProThrottle control 4 engines in FlightSim or whatever, and you hold down the button(s) for the axes you want to move. The advantage (if it is one) is that you can use the handle like a ratchet. If you run out of handle movement before you get to where you're going you can always release the button, slide the handle back up to the other end, and drag it some more.

In the case where you're willing to sweep the handle through it's range, the relative solution works automatically, actually. Say your handle is at 35% and your current throttle is at 85 percent. If you push the handle to 100%, things are sync'd again. Moving the handle from 35% to 50% is going to push the throttle to 100%, moving the handle from 50% to 100% isn't going to do anything, but when you get there your throttle and handle are in sync at 100%. If the handle is ahead of the throttle (switch the percentages) then a full back forces them to sync at 0%.

The display thing would be neat, so will the numerical thing you were working on for doing the tones, etc. You might have it generate a beep when you hit the sync position and the throttle locked to the handle again. You could move it slowly forward or backward until you heard the tone, the throttle would reconnect automatically at that point.

There was one more possibility I played with, probably the most complex, and that would be to have the internal value automatically start increment or decrementing towards the external value. If your handle was behind your internal setting, the aircraft would start to throttle back slowly, your natural inclination is to push the throttle forward to hold the speed, and eventually you would hit the sync point. Then you'd just lock them together and clear the Increment/Decrement coding. It would give you a pretty quick indication of which way the handle needed to go at least. Coupled with the beep, it might work really well.

Anyway, some more food for thought. :)

- Bob

The StickWorks
http://www.stickworks.com

Manfromx
02-04-2004, 04:19 PM
LOL. Okay you guys know your stuff :).

Although I think alot of those ideas are a little too elaborate or overly complicated for what I need.

Since it's just a WWII plane I don't need super fine precision. Say if I didn't want to overrev the engine when I wanted to change proppitch I could just throttle back before I went to change it.

So is there no way to make a 1 - 2 second delay after letting go of the button to switch bring it back to the default axis?

It's really just so, say I mapped it to elevator trim and the trim setting was near 0 throttle. If I'm in the Me262 I could become a fireball real easy once I let go of my axis swapping button. But being within say 10% of my original position before I swapped axis wouldn't be a problem. So 2 second delay gives me time to move it close to where I remember.

Of course another idea I had was just to build a small joystick with x/y/z all being dials on a little contol pad or something. Never done anything like that but seems like it'd be a more user friendly option.

Anyway, some good ideas here, that incremental one is neat. Thanks again.

p.s. Just rereading your first reply there Bob and it sounds like that could work. What would the code look like for that and could you give me an example how it works? Like in practice. Big thanks :)

Revvin
02-04-2004, 04:40 PM
Originally posted by Manfromx@Apr 2 2004, 03:19 PM
LOL. Okay you guys know your stuff :).

I bloody hope so Bob writes the Control Manager software :D Thanks once again Bob for your continued support here :salute:

Bob Church
03-04-2004, 03:18 AM
My pleasure, Revvin!

WRT the original post, sorry. I think JNOV and I got to looking at the problem in general and not just answering the question. It's kind of an interesting subject, especially in things like Flight Simulator where you can have a dozen analog axes to control without even half trying. I'll try to focus....

You've got two outputs, one that's going to the throttle normally another that's going to the prop pitch. The idea is to use the throttle as a throttle unless you press a button. Then you want to switch it over to pitch while you hold the button down, but not switch back to throttle until a couple of seconds after release. At least that's how I understand it.

Okay, first you need to CMS axes, one to control the throttle and one to control the prop. You also need the button, I'll assume it's Button 2 on the joystick, and you need the throttle axis. You don't say whether you're running combined into a single device or not, I'm going to assume not. That means we've got:

CMS.A1 - Internal Throttle Axis
CMS.A2 - Internal Prop Axis
JS1.B2 - Throttle/Prop Select button
JS2.A3 - ProThrottle Throttle Axis

You can move things around as you see fit of course.

The script itself should be pretty simple, something like:

script

timer( OFFDELAY, d1, 50 ) = js1.b2;

if( js1.b2 and d1 ) then
cms.a2 = js2.a3;
else
if( not d1 ) then
cms.a1 = js2.a3;
endif
endif
endScript

Then up in the GUI you need to assign JS1.B2 to DX Device NONE and DX Control NONE, likewise JS2.A3. You also need to assign CMS.A1 to be the throttle axis for the sim and CMS.A2 to be the Prop axis.

What will happen is this. Initially, the timer is timed out, js1.b2 isn't pressed. D1 will be false and so it's just going to copy JS2.A3 (the throttle handle) into CMS.A1 where you'll pass it to the sim throttle in the GUI.

When you press JS1.B2, the D5 timer bit will immediately turn TRUE and so the "NOT D5" conditional will be FALSE. That will disconnect the throttle from the CMS.A1 axis and CMS.A1 will just hold whatever the last value it had in it. That will continue going to the sim.

At that same time, JS1.B2 is TRUE and D1 is TRUE, so the first conditional is TRUE and the throttle will start going to the CMS.A2 axis where it will get passed to the Prop axis.

Eventually, you get the adjustment made and you release JS1.B2. The first conditional is now FALSE since JS1.B2 is FALSE, but the timer bit D1 will stay TRUE for awhile because it's an OFFDELAY. That means that the "NOT D1" conditional is FALSE and so the throttle won't reconnect with CMS.A1 until the timer runs out. All you need to do is to adjust the value in the timer statement to give you enough time to readjust.

Give that a try and see if it does the trick. The possible problem I see is that there's no delay in the engagment of the Prop axis, so it's going to want to jump to wherever the throttle was when you pressed the button. We can add another timer to delay that a little if it's a problem.

Hope this helps!

- Bob

The StickWorks
http://www.stickworks.com

Manfromx
03-04-2004, 04:32 PM
Okay I think I understand how that script works. You're right it is pretty simple now that I look at it.

That's the thing with me and this scripting. I see it, and I go oh yeah I get it no biggie. But dreaming the logic up just doesn't happen. Usually it's me staring into a help file for a good 30 min trying a few things that don't work and then shooting down planes for stress relief :lol: .

Anyway that script works well. But yup we need to stop that prop pitch from shooting up the second I hit the button. So it's bigger than I thought.

So I fumbled around a bit and figured we needed an ondelay. Unfortunately I didn't see the timer function or ondelay mentioned in the help file :( .

So I did this

timer( ONDELAY, d1, 50) = js1.b8; <---- me
timer( OFFDELAY, d1, 50 ) = js1.b8;

if( js1.b8 and d1 ) then
cms.a3 = js1.a3;
else
if( not d1 ) then
cms.a2 = js1.a3;


Now I understand most the stuff here. But what is the "d1" variable in there?
I tried making it d2 for ondelay and then it worked for on, but not for off because I figure it = not d1.

Thanks again. I am learning alot here just from the few scripts I have. I'm sure glad I bought CH by the way. Didn't think you guys would be so involved!

Bob Church
04-04-2004, 07:13 AM
>> Okay I think I understand how that script works. You're right it is pretty simple now that I look at it.

That's the thing with me and this scripting. I see it, and I go oh yeah I get it no biggie. But dreaming the logic up just doesn't happen. Usually it's me staring into a help file for a good 30 min trying a few things that don't work and then shooting down planes for stress relief. <<

I know. I can't explain how you do that, really. It's easy to learn about a lot of functions and how they work, getting to the point where you can see a solution as some combination of the things is the troublesome part. I don't have any particular method, I just sort of look at it and play back possibilities, eventually something fits. I wish I knew some method and could say "...do this and this and this and you'll have your script..." but I've never really found one either.

>> Anyway that script works well. But yup we need to stop that prop pitch from shooting up the second I hit the button. So it's bigger than I thought. <<

Yeah, I was afraid it would be. It's kind of what JNOV and I were trying to automate. That transition is a problem, it really needs to be symmetric and it would be nice if the readjustment came more or less naturally. Even here, unless you happen to hit it exactly, there's going to be some little jump in throttle or pitch when the timers run out.

>> So I fumbled around a bit and figured we needed an ondelay. Unfortunately I didn't see the timer function or ondelay mentioned in the help file. <<

It's back in the section on CMS Scripting:

CMS Programming Guide -> Scripting Reference -> Logical Devices

>> So I did this.... <<

You really almost had it. The syntax is right and the timer does what you think. I think you'd have gotten it if it hadn't been for the confusion over the "d1" stuff. You've got the throttle handle tagged to JS1, too, which would be the stick and not the PT I think.

>> Now I understand most the stuff here. But what is the "d1" variable in there? <<

The "Dx" IDs are the Device bits, they represent the outputs of the logical devices like the timers, etc. There are 256 (D1..D256) and you need to use a different one for each device. It's what the rest of the script references to tell what the device is doing.

Once you make the changes for those and the throttle axis, it's pretty much just what you did:

script

// First we do the OFFDELAY to disconnect the throttle when
// the button is clicked. It turns on immediately so we invert
// it in the conditional so that it will disable throttle when
// it turns on.
//
timer( OFFDELAY, d1, 50 ) = js1.b8;
If( not d1 ) then
cms.a1 = js2.a3;
endIf

// Now we do an ONDELAY to connect the prop. It waits awhile
// after the button closes to switch on, but then switches off
// immediately when the button is released. Combined with the
// OFFDELAY switching above, we end up with neither axis being
// transferred for a short time after the button is pressed or
// released.
//
timer( ONDELAY, d2, 50 ) = js1.b8;
if( d2 ) then
cms.a2 = js2.a3;
endIf

endScript

Anyway, it's just a matter of adding D2 and and then using it to key the prop side rather than what was in your original. I didn't bother with the ELSE clauses, the above works as well when there's no value that needs to be set when neither of the other two are set, and it's a little easier to read.

>> Thanks again. I am learning alot here just from the few scripts I have. I'm sure glad I bought CH by the way. Didn't think you guys would be so involved! <<

You're certainly welcome! I'm glad it's been some help! If it still won't quite do it, come on back and maybe we can come up with something that will!

- Bob

The StickWorks
http://www.stickworks.com