PDA

View Full Version : Detecting Axis direction and sending single key



Suvv
25th March 2008, 11:22 PM
I have split an axis into 4 bands and as I enter each band I want to send a single keystroke. I have managed to do this for the axis going in one direction. (see code below ). However, what I really want is a different keystroke to be sent when the axis moves in the opposite direction. I need to know if the axis is going forward or backwards and send the one off keystroke as the axis traverses forwards from one band into the next and a different keystroke as it traverses in the opposite direction.

Anyone help?

Thanks,

Suvv.

//
// THROTTLE
//

cms.a2 = js3.a3;

if ( [cms.a2 > 200] ) then
cms.b3 = TRUE; // Send S NULL ( stop )
else
cms.b3 = FALSE;
endif;

if ( [cms.a2 < 200] AND [cms.a2 > 120] ) then
cms.b4 = TRUE; // Send W NULL ( 1st gear )
else
cms.b4 = FALSE;
endif;

if ( [cms.a2 < 120] AND [cms.a2 > 60] ) then
cms.b5 = TRUE; // Send W NULL ( 2nd gear )
else
cms.b5 = FALSE;
endif;

if ( [cms.a2 < 60] ) then
cms.b6 = TRUE; // Send W NULL ( 3rd gear )
else
cms.b6 = FALSE;
endif;

Bob Church
26th March 2008, 01:38 AM
Hi Suvv,

Sure! You're probably working harder than you need to, though. Select the axis, uncheck the "DX Mode" box. The screen will change to one that sends character. It will be set to "Up/Down". Click the button that says "Position" and program the "Position Keys" box with an odd number of character. The one in the center should be:

NULL

Put the same number of characters either side of the NULL, e.g.

1 2 3 NULL 4 5 6

will send "1 2 3" as you go left and "4 5 6". They'll be equallly spaced, if you need them unequally spaced, double up the characters. For example:

1 2 3 3 3 NULL 4 4 4 5 6

will send the same character sequence, but the 2 and the 5 will be about 60% to the limit of travel. The tripled characters won't repeat, you'll only get one. You can adjust the number of repeated character to adjust the width of the band.

If that won't work for you, let me know, we can certainly script it up, but the GUI procedure it quicker.

Best regards,

- Bob

The StickWorks
http://www.stickworks.com

Bob Church
26th March 2008, 02:36 AM
Hi Suvv,

I think that maybe I misinterpreted what you were trying to do. Is it that you want on character to be sent going from Zone A to Zone B, but then a different one sent going from Zone B to Zone A? If that's the case, you do need to script. This should do the trick:


script

cms.a2 = js3.a3;

cms.b3 = [ cms.a2 > 200 ];
cms.b4 = [ cms.a2 > 120 ];
cms.b5 = [ cms.a2 > 60 ];
cms.b6 = [ cms.a2 > 0 ];

endScript

You might have to play around with the ordering of things and maybe reverse the axes or play around with the characters a bit, but it does the job. The outputs just stack up as the axis moves away from 0. First b6 turns on, then b5, then b4, then b3. As you come back down, they shut off in the reverse order.

If you program the Press character to send:

a NULL

and the Release character just to send:

b

then the other characters in a similar fashion for the other zones, you'll get one character at each transition, but since going one way the button is pressed (but NULL'd so it doesn't repeat) and going the other way it sends the release (which never repeats anyway) the direction controls which transition gets sent.

Best regards,

- Bob

The StickWorks
http://www.stickworks.com

Suvv
26th March 2008, 08:09 AM
Bob,

You're a gent, thank you very much.

This solution ....

cms.a2 = js3.a3;

cms.b3 = [ cms.a2 > 200 ];
cms.b4 = [ cms.a2 > 120 ];
cms.b5 = [ cms.a2 > 60 ];
cms.b6 = [ cms.a2 > 0 ];


... is perfect.

Suvv.

Bob Church
26th March 2008, 11:06 AM
Hi Suvv,

You're welcome! I'm glad it worked out for you!

Have fun!

Best Regards

- Bob

The StickWorks
http://www.stickworks.com