#4458670 - 01/25/19 09:27 PM
Re: Set an axis to a particular value
[Re: Joao Muas]
|
Joined: Jul 2016
Posts: 61
Drakoz
Junior Member
|
Junior Member
Joined: Jul 2016
Posts: 61
|
Yes, #2 (TM Axis == DX Axis) is the problem. Otherwise, I think you get the idea. My original method was to say if ( (TM Axis > (DX Axis - 100)) & (TM Axis < (DX Axis + 100)) .... (the axis are synced) A +/-100 point range around DX Axis worked most the time. But a 1% to 2% range (+/- 655 to +/- 1310 out of 65532) will probably work 99% of the time or better. Again, you get the idea, and you can adjust the range to fit your needs. That is the easiest way to do it for sure. You don't even need to use AXMAP. For myself, though, I was looking for a way to make it bullet proof. The method I used above needs to know if the previous TM Axis position was less than or greater than the DX Axis. So the idea of using AXMAP1() (the directional version of AXMAP) allows me figure out which way the TM Axis needs to move, and then only enable AXMAP1 to trigger when the TM Axis moves in the direction that moves it toward DX Axis. But I'm sure this is probably more complicated than it needs to be.
|
|
#4458964 - 01/27/19 09:36 PM
Re: Set an axis to a particular value
[Re: Joao Muas]
|
Joined: May 2001
Posts: 468
Joao Muas
Member
|
Member
Joined: May 2001
Posts: 468
Portugal
|
I did this, and it actually works but it needs further testing... It is not fully complete because I got stuck by not knowing how to set arguments for MapAxisInSync(...) when it's inside an EXEC... I want this to re-map several axis, so please check it out and tell me out to set the DX_axis argument for MapAxisInSync. (It's a bit messy, sorry about that)
include "target.tmh"
int flag; // to define where THR is in relation to DX (left or right)
int main()
{
//declare the event handler, return on error
if(Init(&EventHandle)) return 1;
// Initial axis definition
MapAxis(&T16000, THR, DX_SLIDER_AXIS, AXIS_REVERSED, MAP_ABSOLUTE);
// B13 to re-map to DX_THROTTLE_AXIS
MapKey(&T16000, B13, EXEC("MapAxisSync(DX_THROTTLE_AXIS);"));
// B14 to re-map to DX_SLIDER_AXIS - NOT TESTED
MapKey(&T16000, B14, EXEC("MapAxisSync(DX_SLIDER_AXIS);"));
}
int MapAxisSync(char DX_axis)
{
MapAxis(&T16000, THR, 0, 0, 0); // de-map current axis
if(T16000[THR] <= -Axis[DX_axis].pos) { // check if THR is to the left of DX (the "-" is because THR is reversed)
flag = 1; // sets flag left
KeyAxis(&T16000, THR, 0, AXMAP1(99, EXEC("MapAxisInSync(DX_THROTTLE_AXIS);"), 0)); // sets AXMAP1 on alert
}
else if(T16000[THR] >= -Axis[DX_axis].pos) { // check if THR is to the right of DX (the "-" is because THR is reversed)
flag = 2; // sets flag right
KeyAxis(&T16000, THR, 0, AXMAP1(99, 0, EXEC("MapAxisInSync(DX_THROTTLE_AXIS);"))); // sets AXMAP1 on alert
}
}
int MapAxisInSync(char DX_axis)
{
if (flag == 1) { // THR is to the left of DX, sweeping to the right
if(T16000[THR] >= -Axis[DX_axis].pos) { // THR as passed over DX let's capture it
MapAxis(&T16000, THR, DX_axis, AXIS_REVERSED, MAP_ABSOLUTE); // re-maps new axis
KeyAxis(&T16000, THR, 0, AXMAP1(1, 0, 0)); // sets AXMAP1 off
}
}
else if (flag == 2) { // THR is to the right of DX, sweeping to the left
if(T16000[THR] <= -Axis[DX_axis].pos) { // THR as passed over DX let's capture it
MapAxis(&T16000, THR, DX_axis, AXIS_REVERSED, MAP_ABSOLUTE); // re-maps new axis
KeyAxis(&T16000, THR, 0, AXMAP1(1, 0, 0)); // sets AXMAP1 off
}
}
}
int EventHandle(int type, alias o, int x)
{
DefaultMapping(&o, x);
}
|
|
#4459648 - 02/02/19 10:51 AM
Re: Set an axis to a particular value
[Re: Joao Muas]
|
Joined: May 2001
Posts: 468
Joao Muas
Member
|
Member
Joined: May 2001
Posts: 468
Portugal
|
OK. I finally made it, following the discussed concept: - making use of existing TARGET functions
- works without any concern for the previous axis
- no code in EventHandle() is required
Here is the code: //T16000M FCS script to re-map physical THR axis between 4 different virtual axis
include "target.tmh"
int virtual_axis; // virtual axis number
// 5 - DX_YROT_AXIS
// 6 - DX_ZROT_AXIS
// 7 - DX_THROTTLE_AXIS
// 8 - DX_SLIDER_AXIS
int main()
{
//excluding unused devices
Configure(&HCougar, MODE_EXCLUDED);
Configure(&Joystick, MODE_EXCLUDED);
Configure(&Throttle, MODE_EXCLUDED);
Configure(&T16000L, MODE_EXCLUDED);
Configure(&LMFD, MODE_EXCLUDED);
Configure(&RMFD, MODE_EXCLUDED);
Configure(&TFRPRudder, MODE_EXCLUDED);
Configure(&TWCSThrottle, MODE_EXCLUDED);
//declare the event handler, return on error
if(Init(&EventHandle)) return 1;
SetShiftButton(&T16000, B5); // B5 is ahift button
// Default axis definition
MapAxis(&T16000, THR, DX_SLIDER_AXIS, AXIS_REVERSED, MAP_ABSOLUTE);
// B13 axis control
MapKeyIO(&T16000, B13,
EXEC("if (virtual_axis != 5) {virtual_axis = 5; MapAxisSync(virtual_axis);}"), // for DX_YROT_AXIS
EXEC("if (virtual_axis != 7) {virtual_axis = 7; MapAxisSync(virtual_axis);}")); // for DX_THROTTLE_AXIS
// B14 axis control
MapKeyIO(&T16000, B14,
EXEC("if (virtual_axis != 6) {virtual_axis = 6; MapAxisSync(virtual_axis);}"), // for DX_ZROT_AXIS
EXEC("if (virtual_axis != 8) {virtual_axis = 8; MapAxisSync(virtual_axis);}")); // for DX_SLIDER_AXIS (default)
}
int MapAxisSync(int virtual_axis)
{
MapAxis(&T16000, THR, 0, 0, 0); // de-map current axis
if(T16000[THR] <= -Axis[virtual_axis].pos) { // check if THR is to the left of the virtual axis
KeyAxis(&T16000, THR, 0, AXMAP1(99, // Sets AXMAP1 on alert
EXEC("if(T16000[THR] >= -Axis[virtual_axis].pos) MapAxisInSync(virtual_axis);"), 0)); // sweeping right
}
else if(T16000[THR] >= -Axis[virtual_axis].pos) { // check if THR is to the right of the virtual axis
KeyAxis(&T16000, THR, 0, AXMAP1(99, 0, // Sets AXMAP1 on alert
EXEC("if(T16000[THR] <= -Axis[virtual_axis].pos) MapAxisInSync(virtual_axis);"))); // sweeping left
}
}
int MapAxisInSync(int virtual_axis) // when THR passes over the virtual axis, axis will be in sync
{
MapAxis(&T16000, THR, virtual_axis, AXIS_REVERSED, MAP_ABSOLUTE); // re-maps new axis
KeyAxis(&T16000, THR, 0, AXMAP1(1, 0, 0)); // sets AXMAP1 off
}
int EventHandle(int type, alias o, int x)
{
DefaultMapping(&o, x);
} So that is it. Axxis captured and remapped smoothly - no jumps. Thank you Drakoz for your precious help.
|
|
|
|
|
|
|
Exodus
by RedOneAlpha. 04/18/24 05:46 PM
|
|
|
|
|
|
|