View Full Version : mini joystick help
Mog
5th April 2008, 02:40 AM
I have the pro throttle and am trying to write a script. The problem is i have no idea what im doing or what most of the things in the help file means. I used the example in the dummies guide for the mini joystick. After 2 days i finally got it to work in Falcon. Anyway using the same script for a different game, I would like to have the mini joystick automatically repeat a keystroke and if possible do it faster the farther the stick is moved.
Here is what i have so far:
CMS.B1 = [JS2.A2 < 70]; // MINI-JOYSTICK UP = gun elevate
CMS.B2 = [JS2.A2 > 180]; // MINI-JOYSTICK DN = gun depress
CMS.B3 = [JS2.A1 < 70]; // MINI-JOYSTICK AFT = gun left
CMS.B4 = [JS2.A1 > 180]; // MINI-JOYSTICK FWD = gun right
If anyone understands what im trying to say and could help i would really appreciate it. I tried to use something from another post but i dont know what it means and it didnt really work out.
Thanks,
Mog
Bob Church
5th April 2008, 04:25 AM
Hi Mog,
>> I have the pro throttle and am trying to write a script. The problem is i have no idea what im doing or what most of the things in the help file means. I used the example in the dummies guide for the mini joystick. After 2 days i finally got it to work in Falcon. Anyway using the same script for a different game, I would like to have the mini joystick automatically repeat a keystroke and if possible do it faster the farther the stick is moved.
Here is what i have so far:
CMS.B1 = [JS2.A2 < 70]; // MINI-JOYSTICK UP = gun elevate
CMS.B2 = [JS2.A2 > 180]; // MINI-JOYSTICK DN = gun depress
CMS.B3 = [JS2.A1 < 70]; // MINI-JOYSTICK AFT = gun left
CMS.B4 = [JS2.A1 > 180]; // MINI-JOYSTICK FWD = gun right
If anyone understands what im trying to say and could help i would really appreciate it. I tried to use something from another post but i dont know what it means and it didnt really work out. <<
You can do it with that script if you just want to move it. If you check on the CMS Controls tab up in the GUI, chances are that Button 1 through Buttons 4 are programmed something like:
x NULL
If it makes a macro reference, then you'd need to check the macro it reference and probably redefine it.
It's the NULL that stops it from repeating. If you just remove that, the key will autorepeat at the system repeat rate.
Making it variable is possible with a little more scripting. Basically, you need to use that script to start a timer rather than send a button. Then you'd need to use the the ministick axes to control the off time between characters.
The problem with it is that it gets slow very quickly. To control the number of characters sent, you need to press and release the key, where with the normal repeating key, you just need to send the press key and let the system do the repeat. At the default Control Manager character time, that limits you to 10 characters per second max, you could adjust the rate down and get nearer to 20 characters per second but that might create other problems depending on your frame rate.
The big hit comes when you try to run more slowly than that. The best you can do would be 1 "ON" time with 2 "OFF" times in between, or a character rate of about 6 (default Character Rate setting), the second step would be 1 "ON" and 3 "OFF" times which would work out to about 2 or 3 CPS, and beyond that it's probably not going to be much better than then the single character you've got now.
Is there an analog way to control whatever it is you're trying to control the gun positions? If there was, you could control them using the axes you use now. Besides responding proportionately, you can play with the sensitivity, etc. and get much better control.
If that can't be done, or you want to use the variable characters, let me know and I'll show you how to set the script up.
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
Mog
5th April 2008, 06:12 AM
LOL ! OK i copied the script from suvvs' thread and changed it to sort of match the js2.b1 thing on mine. except it doesnt really work. now it only goes up and left i think and they are backwards to how it should work (right input is left result). Oh and the input seems to stop a little past halfway out from center. Here is what I have now:
CMS.B1 = [JS2.A2 < 70]; // MINI-JOYSTICK UP = RADAR CURSOR UP
CMS.B2 = [JS2.A2 > 180]; // MINI-JOYSTICK DN = RADAR CURSOR DOWN
CMS.B3 = [JS2.A1 < 70]; // MINI-JOYSTICK AFT = RADAR CURSOR LEFT
CMS.B4 = [JS2.A1 > 180]; // MINI-JOYSTICK FWD = RADAR CURSOR RIGHT
CMS.B2 = [JS2.A2 > 140];
A1 = (255-JS2.A2)/30;
TIMER( INTERVAL, D1, 1, A1) = CMS.B2;
CMS.B1 = D1;
CMS.B3 = [JS2.A1 < 116];
A2 = JS2.A1/30;
TIMER( INTERVAL, D2, 1, A2) = CMS.B3;
CMS.B4 = D2;
Im sorry but i really didnt understand much of your reply bob. What happens in the game is it is a manual crank for elevation and traverse. 1 keystroke equals a movement a certain distance,one way or the other, simulating manual cranking of a turret. I would like to be able to hold the mini stick instead of beating on the arrow keys of my keyboard, preferably with an proportional speeding up from center. Im apologize but i really dont understand any of this, but im studying the help manual so maybe something will sink in.
Thanks,
Mog
Bob Church
5th April 2008, 12:42 PM
Hi Mog,
>> LOL ! OK i copied the script from suvvs' thread and changed it to sort of match the js2.b1 thing on mine. except it doesnt really work. <<
:) Okay. Well, we'll sort it out. I'm going to assume that's essentially the whole script that you're using (though it doesn't have "script" and "endScript" on it so I'm not sure). I've added them but they would need to be removed if it's part of a larger script. If there is more, just cut that section of the code out and paste in the new section in it's place. Remove the "script" and "endScript" statements from this code, you should just have one "script" at the very beginning and one "endScript" at the very end. You might need to change some variable IDs too, if the unposted script is already using them. If that's the case and you need help, post the entire script here and I could show you where that snippet needs to go.
On to your script. It basically needed to be rewritten, below is what I came up with. It's really four blocks that are essentially the same. I commented the first one pretty heavily so you could follow what was happening, the following sections are more sparsely done. Anyway:
script
// The first section sends the UP character. The first
// line of script just does a mathematical comparison of the
// current value of the js2.a2 axis (Ministick Y Axis) against
// a fixed value of 116. The stick returns 0 to 255 with 128
// at center, so b1 will be ON whenever the ministick is above
// center by 12 counts or more. The "12" is dependent on the
// particular ministick, some may need more some may need less,
// it's just setting a deadzone so nothing happens when the
// ministick is released. When the stick is producing values above
// 128, 140 value used, basically 128 +/- 12. If you need to change
// that, then you should keep them symmetric around 128 like they
// are now. There are some other calculations that may neee
// some adjustment in that case too, they're discussed further
// down.
//
b1 = [ js2.a2 < 116 ];
// This calculation sets a1, an internal variable, to indicate how
// far from center Y is. It's divided by 30 because the result will
// be used to set the number of OFF character times between characters
// and letting it run to 128 would result in about 1 character every
// 6 seconds or so. This is sets to produced a maximum of 4 character
// times, which will give you a range of about 4 character per second
// to 10 characters per second.
//
// You can play with the "4" and "30" values to adjust the maximum
// number of OFF states. You need to choose the numbers so it will
// always produce a zero when the axis is near 0 or 255. The
// calculation will always give you 0 to 128 (before the
// division by 30, etc.) but if it's in the dead zone between 116 and
// 140, the b1..b4 bits will turn OFF and so the timer will
// all be shut offdown.
//
a1 = 4 - (( 128 - js2.a2 ) / 30 );
// Now the timer is created. It's an INTERVAL timer and pulses
// a bit ON and OFF continuously, like repeatedly pressing a button.
// The d1 bit is the bit that it controls. It will be ON for
// one character time (set by the "1" following the d1, 1 is all it
// should need), and OFF for as many character times as were saved
// in a1 in the previous step.
//
timer( INTERVAL, d1, 1, a1) = b1;
// This just copies d1 up to Button 1 on the CMS Controls tab. That
// button will pulse on whenever d1 pulses on. Then Button 1 on the
// CMS Controls tab needs to be set to the "UP" character.
//
cms.b1 = d1;
// The rest are really variations of exactly the same code to handle
// the other 3 directions. I've set it up to start with Up and then
// go clockwise around the directions to match the Windows convention,
// but what it really does is set by the character you program on the
// CMS button. The only real differences are that the calculations
// are different for for up or left and down or right because of the
// centered axis, and you can't reuse the bits so the various bit
// numbers will change. I've taken them in 1, 2, 3, 4 order to make
// it a little easier to relate. The problem you described with it
// not working at all in some quadrants happened because you took
// the whole axis at once and ended up only handling two directions,
// Up and Left I think. You have to treat it as a centered axis and
// then set up all four directions.
// This sends the RIGHT character. The calculation changes because
// the axis is giving a value above 128 (by 12 again, they should
// match if you change things) and so the distance calculation is
// more easily done by reversing the calculate, e.g. subtract center
// from the axis value rather than subtracting the axis value from
// the center value. It's just easier that way, it's always positive.
// Set b2 ON if the ministick is to the right past the deadzone
// limit. It's using js2.a1, the X axis this time.
//
b2 = [ js2.a1 > 140 ];
// Do the scaling calculation just as before but reverse the order
// of the (js2.a1 - 128) calculation since the axis is above 128
// this time.
//
a2 = 4 - (( js2.a1 - 128 ) / 30 );
// Now create the timer for the RIGHT direction, but uss a2, b2,
// and d2.
//
timer( INTERVAL, d2, 1, a2) = b2;
// Copy the d2 bit up to button 2 on the CMS Controls tab.
//
cms.b2 = d2;
// Next, handle the DOWN character. Same deal, but now the Y
// axis is above 128 so it uses the high-side calculation and
// a3, b3, d3, and cms.b3 this time.
//
b3 = [ js2.a2 > 140 ];
a3 = 4 - ( js2.a2 - 128 ) / 30; // << Edited here, the original post was using a1.
timer( INTERVAL, d3, 1, a3) = b3;
cms.b3 = d3;
// Finally, send the LEFT character. Again, the same procedure
// but using the X axis, low-side calculation, and a4, b4, d4
// and cms.b4.
//
b4 = [ js2.a1 < 116 ];
a4 = 4 - (( 128 - js1.a1 ) / 30 );
timer( INTERVAL, d4, 1, a4 ) = b4;
cms.b4 = d4;
endScript
You need to create the map with the stick on the first tab and the ProThrottle on the second tab so that the "js2" references are correct. The tabs to the far left always says "Program Settings" on, next to that you should have the tab for your stick, then the one for your throttle, then pedals. You also need to "Add" the "CMS Controls" to the map so you've got the buttons. Then just go in and add the Up, Right, Down, and Left characters to Button 1 through Button 4 on the CMS Controls tab respectively.
>> Im sorry but i really didnt understand much of your reply bob.
What happens in the game is it is a manual crank for elevation and traverse. 1 keystroke equals a movement a certain distance,one way or the other, simulating manual cranking of a turret. I would like to be able to hold the mini stick instead of beating on the arrow keys of my keyboard, preferably with an proportional speeding up from center. Im apologize but i really dont understand any of this, but im studying the help manual so maybe something will sink in. <<
The CMS curve is kind of steep at first, it gets easier after you've done a few. You don't need scripting for most of the common functions, and the GUI is mostly a matter of connecting the physical buttons on the left side of the screen to the joystick buttons Windows will see on the CM Devices over on the right side. And if you get stuck, we're always here to help. Just come on by and ask.
Anyway, the map compiles okay, but I can't actually run it at the moment. My system is currently set up for another program. It looks okay, but I may have done something dumb, you never know 'til it's running. Give it a try and if you run into problems, let me know and I'll sort them out.
Let me know how it goes!
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
Mog
6th April 2008, 04:13 AM
:salute: :cheers: Thanks a million, Bob ! It works great. I need to adjust it a little bit as its noticeably slower moving left for whatever reason. Thanks for explaning it like you did. That was more helpful then you will ever know. If I cant figure the rest of this out Ill let you know.
Thanks again,
mog
Bob Church
6th April 2008, 07:35 AM
Hi Mog,
You're quite welcome, Mog! I'm glad it worked for you! I usually run the things before I post, but I had to take the CM off the machine while I was working on another program, and you never know until you run it if you got it right.
I don't know why it would be slower on the left. If it's LEFT (whatever that is) is tagged to Button 4 on the CMS Controls panel, than anything wrong in the script would have to be in the last four lines:
b4 = [ js2.a1 < 116 ];
a4 = 4 - (( 128 - js1.a1 ) / 30 );
timer( INTERVAL, d4, 1, a4 ) = b4;
cms.b4 = d4;
If it's in the scripting, then "Slow" would indicate that a4 never gets to be at least 3, and the way it's set up it should get there easily. The calculation would end up being "a4 = 4 - (( 128 - 0 ) / 30 );" which produce zero for the off count. As I recall (it's been a long time since I've looked at it ) that's treated the same as a "one", and I think it would have shown up on the other three axes as well if it was creating a problem.
There is one kind of "quirk" in the ministick, too. You can see it if you watch it in the Test/Calibrate screen. It only produces 0 and 255 if it's exactly on the X or Y axis. If you move it around the edges of travel, it transcribes a circle. All the other devices will go all the way to the corners of the CMS Calibration display.
If you were to be moving it more towards the corner, at some point you'd hit an angle where the output wouldn't make the calculations for a4 not be able to get to 4. It wouldn't need to be much, really. Anything over "8" on the X axis would cause it. You might try decreasing the "30" value a little at a time and see if that helped. Check the calibration, too, and calibrate with the cursor exactly at the 12, 3, 6, and 9 o'clock position. The axis you're NOT calibrating need to be showing 128 (center). If it gets miscalibrated to where it won't get below eight, you'll lose that fastest step. Or it might work better to calibrate it up/left and down/right, purposely set those values so they produce the highest minimum value and the lowest maximum value. That should guarantee that it would hit the value, but it would increase the sensitivity "on-axis", you'd end up hitting the minimum and maximum values at about 70% of travel.
Anyway, assuming the code is right and all the characters are entered simularly, "a" or "a NULL", it should be the same. One other note. Don't say "A", say "a". "A" will be sent as "LSHF down, character delay, "a" down, character delay, "a" up, character delay, "LSHF up" and can take a long time. A lot of sim manuals will say "A" is the command, but they're actually asking for the "a" key. Unless the sim specifies the shiftiing thing specifically, alway try the lower case first.
If you need help with anything else, let me know.
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
Powered by vBulletin® Version 4.1.4 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.