PDA

View Full Version : Detecting axis movement



Wolverine
6th December 2008, 12:22 PM
Hi,

I would like to press a cms button when the throttle axis is moved in any direction.
Thats for the collective brake in the Black Shark. It should automaticly pressed when the throttle is moved and released when movement stopped.

It should work like that:

if (js2.a3)
then cms.b1;
endif


I tried some if's and sqeuences but could not get it to work.



Greetings,

Manuel

Bob Church
6th December 2008, 02:07 PM
Hello Manuel,

You need to check it at two points in time and see if the value changed. The CLOCKTICK CMS variable is a good key for that, it ticks on the character clock. You should also look for a couple of counts of movement, otherwise if the value starts to "bobble", 51..52..51..52.. which will happen depending on how the axis is lined up with the edge of the point that defines the edge between 51 and 52 (in the example) it will keep the output from just jittering off and on when you're not actually moving it. The script would probably look something like this:


script

// Make an initial record of the current axis value
// when the script starts.
//
if( FIRSTSCAN ) then
a1 = js2.a3;
endIf

// Now wait until the clock ticks. When it does compare the
// current value with the last saved value. If it's moved set the
// bit and copy the new value from the axis. If it didn't move,
// then shut the bit down.
//
if( CLOCKTICK ) then

// This just calculates the positive difference between the
// current value of js2.a3 and the a1 holding register.
//
if([ js2.a3 > a1 ]) then
a2 = js2.a3 - a1;
else
a2 = a1 - js2.a3;
endIf

// Now check if the difference is greater than a couple
// of counts so it doesn't bobble. You can play with the "2"
// value to get it where it works for you.
//
if([ a2 > 2 ]) then

// It moved more than two counts so consider it "moving".
// Update the current position in a1 and set the flag.
//
a1 = js2.a3;
cms.b1 = TRUE;

else

// It didn't move, clear the flag.
//
cms.b1 = FALSE;

endIf

endIf

endScript

It seems to work here, but you never know. Timing and detecting movement can be tricky. Give it a try and see if it does what you want, if not maybe we can come up with another idea.

Best regards,

- Bob

The StickWorks
http://www.stickworks.com

Wolverine
6th December 2008, 03:35 PM
Works like a charm. Thank you Bob.
In never used Clocktick and Firstscan before. Didn't even thought of them.

Bob Church
6th December 2008, 03:45 PM
Hi Manuel,

They aren't really needed too often, but they're handy when they are. Anyway, I'm glad to hear it's working for you! Have fun with it!

- Bob

The StickWorks
http://www.stickworks.com