Solved! How To Use Dual Controls In X-Plane 11

* NOTE: I updated this post on 1/16/17 to clarify how you find the initial assignments of axes and buttons.

The one lingering barrier to my complete switch to X-Plane was the inability to use both sets of the Basement Sim’s controls. It seems that in X-Plane if roll/pitch/yaw are assigned to more than one controller, only one will work and X-Plane disregards the other. (This is not the case with FSX or P3D, which simply read whichever control provides the most recent or largest input.) Only one set of working controls is a real problem for me, as being able to fly with family, friends, etc. is a big part of what I enjoy about the Basement Sim.

There is an answer, though, and it turns out it is Lua. From the Lua website:

Lua is a powerful and fast programming language that is easy to learn and use and to embed into your application. Lua is designed to be a lightweight embeddable scripting language and is used for all sorts of applications from games to web applications and image processing.

 

Lots of simmers and cockpit builders use Lua to write little bits of computer code, called “scripts,” that allow them to execute unique commands (like having the buttons they installed in their panel turn on the cabin lights). Lua scripts are like little apps you can run to get things done that the sim software won’t do itself.

X-Plane is very easy to integrate with Lua thanks to the FlyWithLua plugin. I had posted on the X-Plane.org forums that I was hoping the final release version of X-Plane 11 would allow multiple sets of controls, and one of the very helpful folks in that community — Teddii — responded that a Lua script might be the answer. He said I should be able to write a script for one of the buttons on my yoke where if I flip the button to the left the left controls are live, and if I flip it to the right the right controls are live. He even volunteered possible code.

Getting the code to work meant finding out which axis numbers X-Plane was associating with each of the yokes. Fortunately every time you launch X-Plane FlyWithLua puts a little .TXT file called “initial_assignments.txt” in its plugin folder that shows initial joystick and button assignments. To find my axes and button assignment numbers I first went into X-Plane’s joystick configuration screen and assigned the axes of BOTH yokes to pitch and yaw. This gives you a warning that you have dual assignments in X-Plane, but that’s OK. I also assigned the button that I wanted to use to pass control of the airplane to a command I would recognize (in my case, calling ATC). Looking at the initial_assignments.txt file I could see the pitch, roll, and yaw axes for both yokes and the button numbers for the left / right switch on my Yoko yoke (which X-Plane reads as two buttons – one for each position – rather than as one, and I had assigned BOTH to call ATC in the joystick configuration screen). You will see commands like this in the initial_assignments.txt file:

set_axis_assignment( 0, "roll", "normal" )
set_axis_assignment( 1, "pitch", "normal" )
set_axis_assignment( 3, "yaw", "normal" )

… and …

set_button_assignment( (4*40) + 1, "sim/operation/contact_atc" )

You need to do a little math for the button assignment: (4*40)+1, for example, is 161. That’s the button number for the MyAirplaneYourAirplane code. You may also need to guess which set of axis assignments are the left and right controls, but that’s easy to change if you get it wrong.

I added these variables to Teddii’s initial code, put the “My Airplane Your Airplane.txt” script file in the FlyWithLua scripts folder, and gave it a go. Partial success: it worked in swapping to the right controls, but would not swap them back to the left. Looking at the joystick configuration window in X-Plane I could see that I again had conflicting yaw / pitch / roll controls, and deduced that while the swap from left to right worked, the script did not clear the assignments for the left yoke, resulting in the same problem I had started with (dual-assigned controls).

So I just modified the script a little bit, adding lines to assign the axes that I’m switching away from to “none.” SUCCESS! It worked, and now I’m able to easily pass control of the airplane to a passenger by flipping the yoke switch to the right, and take it back by flipping it back to the left.

The final code follows, and you are welcome to use it if you like. Thanks again for Teddii for his help as I would not have been able to do this without his initial and very helpful code. Also, there is a nice primer on getting started with FlyWithLua here.


 

My Airplane / Your Airplane FlyWithLua Script

-- axis numbers for left yoke
L_axisPitch = 75
L_axisRoll  = 76
L_axisPedal = 52

-- axis numbers for right yoke
R_axisPitch = 25
R_axisRoll  = 26
R_axisPedal = 2

function yoke_switch()
    if button (486) and not last_button(486)
    then
        -- activate right yoke
        set_axis_assignment(R_axisPitch, "pitch", "normal" ) --"normal" or "reverse"
        set_axis_assignment(R_axisRoll,  "roll", "normal" )
        set_axis_assignment(R_axisPedal, "yaw",  "normal" )
        -- DEactivate left yoke
        set_axis_assignment(L_axisPitch, "none", "normal" ) --"normal" or "reverse"
        set_axis_assignment(L_axisRoll,  "none", "normal" )
        set_axis_assignment(L_axisPedal, "none", "normal" )
    end
    if button (480) and not last_button(480)
    then
        -- activate left yoke
        set_axis_assignment(L_axisPitch, "pitch", "normal" ) --"normal" or "reverse"
       set_axis_assignment(L_axisRoll,  "roll", "normal" )
       set_axis_assignment(L_axisPedal, "yaw",  "normal" )
       -- DEactivate right yoke
       set_axis_assignment(R_axisPitch, "none", "normal" ) --"normal" or "reverse"
       set_axis_assignment(R_axisRoll,  "none", "normal" )
       set_axis_assignment(R_axisPedal, "none", "normal" )
    end
end

-- check for the switch button every frame ...
do_every_frame("yoke_switch()")

-- end

21 thoughts on “Solved! How To Use Dual Controls In X-Plane 11

    1. Hi, I have 2 Saitek yokes and 2 set of rudder pedals and a throttle quadrant. After much research and not being able to write code I had a simple idea. I ordered a USB hub from Amazon with 6 USB slots that can be turned off and on. Pulled yokes and pedals and throttle. So flying with someone and the other takes the controls ” my plane” and hit the USB controller switch turn my yoke and pedals off turn the others on. Works great.

  1. good day
    I try to sort out this dual controls on xplane

    got 2 yokes and 2 pedals – Saitek
    I installed lua in plugin folder and myplaneyourplane.txt into lua scripts subfolder.

    when I start xplane get an error written in green on top right of screen – and red message lua stopped
    this look like resoled if I restart lua

    how do you assign the flip / switch command to the yoke buttom ? to switch between the two ?
    tx
    ray

  2. good day
    ok installed lua and script

    running 2 Saitek Cessna yoke and 2 saitek pedals

    how do I assign the switch button – to switch between the two controls ?
    tx
    ray

    1. As I wrote in my post, you need to modify the script to have the correct axes numbers and button number for your configuration on X-Plane. I describe how to do this in the post.

  3. as we are in plugin theme
    i installed on the ipad the Simionic Simulator for Garmin G1000
    it is working fine in windows 7 and xp11 first release beta

    on the cockpit pc use windows 10 can not click on on the plugin ‘start button’ to start the server- it is basically unclickable – button is stubborn.

    did you come across this problem ?
    thanks
    ray

  4. Good day
    When starting xplane11 can not see in assignments any function yoke_switch and neither i can not see it in the initialassigments.txt. Because of that do not know the number of the button to type into the script
    How do you find out the button number?
    After you start xplane do you have to configure anything?
    Thanks
    Ray

    1. I went into X-Plane and assigned the button to a specific function (like calling up the ATC window). I then exited X-Plane and looked at the “initial_assignments.txt” file in the FlyWithLua plugin folder. Note the button number assigned to the command you assigned to that button, and that’s the button number for the code. Note that you need to do a little math to get the correct number.

      Here’s an example:

      set_button_assignment( (4*40) + 6, “FlyWithLua/autopilot/activate_autopilot” )

      That’s for having the autopilot on command set to the button. If you calculate (4*40)+6, you get 166, which is the button number to assign in the my airplane your airplane code. It doesn’t matter which command you assign to the button – you’re just doing it to identify which button code it is. Once I had the number I went back into the joystick config in X-Plane and deleted the assignment.

      1. know im using arduino boards to controls my custom cockpit!!! and they send data to xplane via ardsim plugin!! and i dont know how to make xplane 11 and your excellent script! to read my jokes :(

        but really good work!!

  5. Thank you very much for posting these tips..
    While I ‘still’ don’t have a dual yoke cockpit in the garage, I do have a TM Warthog for helicopters and a Saitek yoke for GA.
    Why LR don’t offer this kind of dual programming as standard is beyond me but I’m sure they have reasons.
    Thanks again for helping me sort out my controls.
    Toby

Leave a Reply

Your email address will not be published.