Liftoff: Drone Racing - Taranis

Basic profile to use a Taranis RC remote as input for Liftoff: Drone Racing. - Remapping of sticks - Disables PS and XB button when active to prevent triggering with switches - Reset with SF (right-back switch) Make sure to move to slot 0 on the titan when navigating menus with a game controller! Controller setup TARANIS QX7 Axes order (* required) CH1 -> Thr *, CH2 -> Ail *, CH3 -> Ele *, CH4 -> Rud *, CH5 -> S1, CH6 -> S2, CH7 -> SA *, CH8 -> SB, CH9 -> SC, CH10 -> SD, CH11 -> SF *, CH12 -> SH
Version1.00
AuthorLuGusTom
Publish DateTue, 8 Dec 2020 - 08:59
Last UpdateTue, 8 Dec 2020 - 08:59
Downloads184
RATE


1

0

Release Notes: Initial version
Code: Select all
/* *
* GPC SCRIPT
*
*  GPC is a scripting language with C-like syntax.
*  To learn more access GPC Language Reference on Help menu.
* *********************************************************** */

 
    int leftX = 0;
    int leftY = 0;
    int rightX = 0;
    int rightY = 0;
    int consoleDeadband = 0;
    int desiredDeadband = 0;
    int deadbandScale = 100;
 
    int deflectionRight = 0;
    int deflectionLeft = 0;
 
    int deadbandCompensation = 0;
 
main {
 
    // TARANIS QX7 Axes order:
    // CH1 -> Thr
    // CH2 -> Ail
    // CH3 -> Ele
    // CH4 -> Rud
    // CH5 ->  S1
    // CH6 ->  S2
    // CH7-CH12 -> SA-SH
 
    // =====================
    //  Assign Input Values
    // =====================
 
    // TARANIS QX7
 
    // These values work both on xbox one and PS4
    leftX = get_val(PS4_L2);   // Detected as trigger
    leftY = get_val(PS4_LX);   // Detected as inverted axis
    rightX = get_val(PS4_LY);   // Detected as axis
    rightY = get_val(PS4_RX);   // Detected as inverted axis
 
 
    set_val(PS4_PS, 0);     // disable playstation button
    set_val(XB1_XBOX, 0);   // disable xbox button
 
 
    leftX = RemapBumperToFullRange(leftX);   
    leftY = RemapTaranisAxisInverted(leftY);
    rightX = RemapTaranisAxis(rightX);
    rightY = RemapTaranisAxisInverted(rightY);
 
 
    // == NOTE: ==
    // The consoleDeadband value should be set up so that:
    // sqrt(consoleDeadband^2 + consoleDeadband^2) == actual deadband
    // In this case, actual deadband is 20 (Xbox One)
    // -> sqrt(15*15 + 15*15) = 21 (Close enough)   
    consoleDeadband = 15;
    desiredDeadband = 1;    // desired deadband for rc remote
 
    deflectionRight = isqrt((rightX * rightX) + (rightY*rightY));     
    deflectionLeft = isqrt((leftX * leftX) + (leftY*leftY));
 
    // (mostly) remove deadband
    // Not possible to get rid of all deadband, since it's mapped as a smooth
    // gradient, and we don't have the precision to get rid of that
    rightX = RemoveDeadband(rightX, deflectionRight);
    rightY = RemoveDeadband(rightY, deflectionRight);
    leftX = RemoveDeadband(leftX, deflectionLeft);
    leftY = RemoveDeadband(leftY, deflectionLeft);
 
 
    // Reassign values to output
    set_val(PS4_LX, leftX);
    set_val(PS4_LY, leftY);
    set_val(PS4_RX, rightX);
    set_val(PS4_RY, rightY);
 
}
 
// Input detected as trigger
// Remap inputs to [-100 ; 100]
function RemapBumperToFullRange(val)
{   
    if(val >= 50)
    {       
        val = (val - 100) * 2;
    }
    else
    {               
        val = val * 2;
    }
 
    return val;
}
 
// Input detected as axis
// Remap inputs to [-100 ; 100]
function RemapTaranisAxis(val)
{
    if(val == -100)
    {       
        val = val + 100;
    }
    else if(val <= 0)
    {       
        val = val + 100;
    }
    else
    {       
        val = val - 100;
    }
 
    return val;
}
 
// Input detected as inverted axis
// Remap inputs to [-100 ; 100]
function RemapTaranisAxisInverted(val)
{
    val = inv(val);
 
    if(val == -100)
    {       
        val = val + 100;
    }
    else if(val < 0)
    {       
        val = val + 100;
    }
    else
    {       
        val = val - 100;
    }
 
    return val;
}
 
function RemoveDeadband(val, deflection)
{
    // Deadband linearly tapers off with stick deflection
    deadbandCompensation = consoleDeadband - (deflection/2);
    if (deadbandCompensation < 0) deadbandCompensation = 0;
 
    if (val > desiredDeadband)
    {               
        val = val + deadbandCompensation;
    }
    else if (val < (0-desiredDeadband))
    {
        val = val - deadbandCompensation;
    }
 
    return val;
}