PDA

View Full Version : Delays with axis lever ' position' control type?



Crow
10th March 2009, 05:17 PM
Hi,

I understand how to do simplistic cms scripts.

For instance how to make a controller's axis produce a button keypress, or a series of key presses as the controller continues to move the lever further along the axis. The WEP example at the top of the scripting examples forum here showed me the basic idea years ago!

However, what's a good way to put in a delay?

For example I wish to push back the left black lever on the TQ and have two button presses occur, but have the buttons stay down for three seconds each and then release.

Here's a script without the delays:

CMS.A1 = JS1.A1; // LET CMS CONTROL THE FIRST AXIS OF THE TQ
CMS.B1 = [CMS.A1<20]; // B1 PRESSED WHEN FIRST TQ STICK IS PUSHED BACK
CMS.B2 = [CMS.A1<20]; // B2 ALSO PRESSED

Of course in the cms dialogue boxes I can enter NULL a for cms B1 and NULL b for B2 to get both press and release of keyboard keys a and b, instead of having to then pull the stick back to release the keys.

Now my question is how do I script to make the same one TQ lever (JS1.A1) press cms buttons B1 and B2 and hold them each for say 3 seconds and then release both ?

Thanks!

Bob Church
10th March 2009, 09:08 PM
Hi Crow,

If you've got an input and you just want a fixed hold time on it when the button closes regardless of how long the button is closed for, use a PERIOD timer. That's exactly what it does. Something like:


script

// D1 goes true immediately when the comparison comes
// back TRUE, then stays on for about 3 seconds and shuts off,
// regardless of the input state. To get another pulse, you need
// to go above 20 so the comparison goes FALSE, and then come
// back below 20 to set it TRUE again.
//
timer( PERIOD, d1, 60 ) = [ cms.a1 < 20 ];

// Now copy the timer output to the button bits.
//
cms.b1 = d1;
cms.b2 = d1;

endScript

Is that what you're looking for?

Best regards,

- Bob

The StickWorks
http://www.stickworks.com

Crow
10th March 2009, 11:58 PM
Yep it's working fine, thanks!

By the way is the period 60 going to output a keypress for different lengths of time on different computers, depending on the speed of the c.p.u.?

Bob Church
11th March 2009, 03:48 AM
Hi Crow,

Probably. It's not really something the CM can control. The sim reads the sticks once per frame and it doesn't run on any real clock. It just depends on how long it takes to generate and render the next frame. The sim could pick new data up anywhere from immediately before the data is update (added time about 0) to immediately after the update (add time is about 1 frame time at your lowest frame rate) or anywhere inbetween, so the variation is one of whatever the current frame time is, and the CM has know way of knowing when the sim picked up the reading or what the relationship was to the frame boundary, even if Windows and the CM made caused absolutely no error to be introduced. They aren't of course, but the error is likely to be much smaller and more prone to be a short term jitter.

You have to make the characters long enough to cover that longest frame time plus a little to guarantee that the press or release reports won't get missed. If the framerate changes a lot (blue sky to a dozen aircraft in a close dogfight for example) then it can take more time than you might be expecting.

Anyway, about all you can do is try it and see. The CM piece of it is that Character Rate setting on the Program Settings tab, more is slower.

Hope for the best. :)

Best regards,

- Bob

The StickWorks
http://www.stickworks.com

Crow
13th March 2009, 04:16 PM
Hi, Bob.
In script below CMS.B18 outputs: m
and CMS.B19 outputs: M

JS4.A is 6th TQ handle.

Sometimes, not always, right after downloading map, M is continuously outputted on computer, which makes difficult to select another map to download for to stop it because M keeps getting written in selection box: MMMMMMMMMMM

1 Is there fast/easy way to kill any rogue map that is printing keyboard keys continuously all the time?

2 Is there way to alter script below so that nothing happens (no m or M is outputted) until the handle is first moved from wherever it was when map is first downloaded?

CMS.A9 = JS4.A6;
TIMER(PERIOD,D9,20) = [CMS.A9<20];
CMS.B18 = D9;
TIMER(PERIOD,D10,20) = [CMS.A9>175];
CMS.B19 = D10;

Thanks!

Bob Church
13th March 2009, 10:37 PM
Hi, Crow,

>> In script below CMS.B18 outputs: m and CMS.B19 outputs: M...

>>> Sometimes, not always, right after downloading map, M is continuously outputted on computer, which makes difficult to select another map to download for to stop it because M keeps getting written in selection box: MMMMMMMMMMM

1. Is there fast/easy way to kill any rogue map that is printing keyboard keys continuously all the time? <<

There are several actually, but first, it's not really a rogue map. The release key is just being missed by the script. It usually means the Character Rate setting on the Program Settings tab is set too low. The key goes by too quickly for the sim to see the release code and so it leaves the key "stuck". If the value is larger enough, the release won't be missed, but it may need to be so long at startup that the sim response gets sluggish.

If I run into that, I usually set it to a large value, 200 is the max I think. It won't be flyable, it's definitely too slow, but then you can work back down until it starts sticking again to find the best value.

If the key doesn't need to be held down, e.g. you just need one "M", you can program it as:

M NULL

The NULL will stop the repeat after one character. That's the easiest if it will work. The NULL makes it look like a string and strings don't repeat. The M is still subject to the Character Rate, though, so if that's still too short, use a KEYS macro:

KEYS +M CHARDLY CHARDLY CHARDLY CHARDLY -M

and the "M" will hold for about 5 times as long but still only get sent once.

You can click the Direct Mode button in the GUI and that will shut the map down and the "M" will stop. Then you can click Mapped Mode and it will start again. If it's not happening every time, then it's probably something to do with it needing longer keypresses during startup after download, stopping it and restarting it may do the trick. Once it's downloaded, though, that might improve, and you can switch the existing download off and on with Mapped Mode and Direct Mode.

The worst one is when it happens on the mouse. The mouse keeps moving, and you can't control it to shut the map off. If you unplug any controller and then plug it right back in, that will set it back to Direct Mode and the mouse will settle down so you have control again.

>> Is there way to alter script below so that nothing happens (no m or M is outputted) until the handle is first moved from wherever it was when map is first downloaded? <<

Not really. The problem is that the throttle itself may bobble by a count and so it's "moved". If you're in the detent with enough deadzone it won't, but if it's out of the detent it can still happen. You could set it wait for some other button press, that's stable and OFF at startup, but trying to get it on an axis isn't likely to work reliably.

I'd use the NULL or the KEYS solutions are if the single character is okay. KEYS macros don't repeat either, though, so it would require that you really only needed a single "M".

See if any of those work for you. If not, we can probably set up a macro that will send a "slow" "M", or maybe lock it out until another button is clicked to enable the function.

Let me know how it goes!

Best regards,

- Bob

The StickWorks
http://www.stickworks.com