SITL MAVProxy Joystick Support

3689451382?profile=original

3689451488?profile=original

I was working on getting the SITL simulation up and running this weekend, and was able to modify MAVProxy.py to support real-time control via a joystick or gamepad, here is the updated file:

mavproxy_joy.py

It requires installation of pygame (http://www.pygame.org) It will probably require some modification to map the axes on your particular controller to the proper APM channels, in these lines:

 

cmd_rc(["1", str(int(j.get_axis(2)*400 + 1500))])
cmd_rc(["2", str(int(j.get_axis(3)*400 + 1500))])
cmd_rc(["3", str(int(-j.get_axis(1)*800 + 1100))]) #throttle
cmd_rc(["4", str(int(j.get_axis(0)*400 + 1500))])


pygame prints any control input changes to the terminal, which can be annoying because it scrolls away some of the normal mavproxy messages.

I tested it flying the ArduCopter, and it works well, hopefully it will be useful for testing modifications to manual control modes.

--------------------

Update:

I created a mavproxy module file that can be loaded into the normal version of mavproxy.py:

joystick.py

Copy this file into the /modules folder, and from within mavproxy, load the module by entering:

module load joystick

Axis mapping is still custom to the Logitech Dual Action, so modifications may be required for other devices.  One issue is that it still writes the state of the joystick axes to the console - I'm still looking into whether there is a way to suppress this.

For future work, I want to add support for some of the gamepad buttons to change rc channels 5-8 to be used for changing mode, dropping waypoints, etc,

Andrew

 

E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • Hello dear Andrew, i am trying to connect "Thrustmaster T.Flight Hotas X" joysticks in mavproxy, and get such error

    MAVProxy.modules.mavproxy_joystick: Found joystick (Thrustmaster T.Flight Hotas PS3)
    MAVProxy.modules.mavproxy_joystick: Failed to find matching joystick.

    i created a .yml file already but it it didn't help.

    Can you help me to solve this problem please.

    Thank you !

  • This module is only for controlling the SITL simulation with a joystick, not the actual ArduCopter.

    Here is documentation on flying the actual ArduCopter with a joystick, via the Mission Planner:  http://code.google.com/p/arducopter/wiki/Joystick

  • Hello,

    with this module i can control the Arducopter using a  Joystick? I ask this because i don´t have joystick to try it and i have to buy one.

    Thanks!

  • Oh, and here's the link I referenced with the US military using xbox controllers to pilot drones:

    http://www.gamepolitics.com/2008/07/20/military-using-game-controll...

    GamePolitics News | GamePolitics
  • Hi! This is my first post. I've been lurking the forums off and on for a few years, but have not had the resources to even consider a build until now.


    I was wondering if anyone had tried to use an xbox 360 controller to control either a simulation or an actual drone. I think I remember seeing something about US drone pilots using those controllers, I can try to find the article and link it here.

    I think it would be a cool idea due to controller's great familiarity for a large number of people, the relatively low cost and high availability of the controller, and the proven reliability from countless long hours of gaming.

    I'm not sure if doing this would require you to interface with a computer or if there is a way to wire it straight into the board.

    Anyhow, hello.

  • Developer

    Thanks for the update Andrew! I've added it as a standard module in MAVProxy.

    The only small change I made was to check for mpstate.status.exit, otherwise the thread hangs around when you control-C mavproxy.

    Thanks for a great contribution!

    Cheers, Tridge

  • Sure, I'll try to set it up as a module, I'll need to learn a little more about how the modules work, but that should be doable.  Thanks for the feedback!

  • Developer

    another tip. When developing a module, its useful to do "set moddebug 1". That will allow you to see exceptions that happen in modules.

  • Developer

    Great work Andrew!

    If you want it to accepted into the mainline code, I'd prefer it was re-done as a mavproxy module. Then you would do "module load joystick" to get joystick support. You can put that in a mavinit.scr file if you like or use --cmd to run it every time.

    Where possible I'm trying to keep new features like this as modules. That will hopefully prevent the main code from getting too unwieldy. I'll probably also move some existing features into modules over time.

    If you look in the modules directory in MAVProxy you'll see there are currently 3 modules:

    • sensors - for monitor sensor consistency and displaying sensor summary
    • drop - for controlling bottle drops
    • test - for running a standard test flight I use for AHRS testing

    The drop module demonstrates how to control RC channels, which is what the joystick module would need to do.

    There is no documentation on the module API I'm afraid, but basically anything that can be done in MAVProxy can be done in a module. Sometimes its handy to export a core mavproxy function into mpstate.functions to make a module easier to write.

    Do you want to have a go at redoing the joystick support as a module? You'd then become the maintainer of that module in the future.

    Cheers, Tridge

This reply was deleted.