Controlling with joystick/gamepad using python-client

Firmware/software/electronics/mechanics
Post Reply
tungnx94
Beginner
Posts: 11
Joined: Wed Dec 27, 2017 11:49 am

Controlling with joystick/gamepad using python-client

Post by tungnx94 »

Hello,

I want to write a small programm using python that allows over the crazyflie using a game controller and simultaneously send back data to computer (as the client does, but with python library for more adaptiability). I figured out how to read data from the crazyflie, but not yet how to extract input signal from the game device, convert it to and send to the drone as control signal.

Would be glad for any tips, suggestions or instructions.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Controlling with joystick/gamepad using python-client

Post by arnaud »

The easiest might be to look at pygame, pygame has APIs to handle joysticks.

In the Crazyflie client we have a custom implementation for Linux and we use pysdl2 for Windows and Mac.
tungnx94
Beginner
Posts: 11
Joined: Wed Dec 27, 2017 11:49 am

Re: Controlling with joystick/gamepad using python-client

Post by tungnx94 »

Hi arnaud,
it I want to study the client code to "copy" the way it handles joystick input, which files should I look into ?
Really appreciate the help.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Controlling with joystick/gamepad using python-client

Post by arnaud »

The input subsystem of the client is there: https://github.com/bitcraze/crazyflie-c ... tils/input, the low level drivers for SDL and Linux are in a subfolder: https://github.com/bitcraze/crazyflie-c ... putreaders

This code became a bit too complex to our taste (it handles all assisted mode as well as the joystick mapping), but has been designed to be independant from the graphical client (it is used in the headless client as well) so you should even be able to use the JoystickReader object directly in your project and have all mapping and assisted mode functionality. You can look in the headless client for an 'simple' example of how it is used and in the gui client for all the functionalities.
tungnx94
Beginner
Posts: 11
Joined: Wed Dec 27, 2017 11:49 am

Re: Controlling with joystick/gamepad using python-client

Post by tungnx94 »

I'm studying the joystick input subroutine. The code is easy enough to understand. There is one thing I haven't got though: what is the role of the pysdl2.py file ?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Controlling with joystick/gamepad using python-client

Post by arnaud »

linuxjsdev.py is used for Linux, pysdl2.py is used for Mac, Windows and anything not Linux. Both files implements the same low level function to access and ready joystick. We have had problems on linux with sdl so this is why there is a pure-python joystick driver for Linux.
Post Reply