python client keyboard control

Firmware/software/electronics/mechanics
Post Reply
crazyflying
Beginner
Posts: 20
Joined: Thu Oct 26, 2017 3:24 pm

python client keyboard control

Post by crazyflying »

(python client keyboard control)

hello i would like to control my drone via python...

so bassically take the first script from the pyhton lib using flow
https://github.com/bitcraze/crazyflie-l ... nceSync.py

so basscially i would like to use instead of having to open the cfclient and conenct with a ps2 controller i would like to control the crazy flie via terminal and pyhton with this script i tried to make..first time on python.so already learnt allot in just writting this even tho it doesnt function.

https://gist.github.com/anonymous/77429 ... a5fccfda06

so when i run the code i use python3 and it runs but does not work..my aim is for it to run like so..

start and move to hover point .4 from here on i can then controll thrust pitch and such with keyboard mapped keys?
can anyone help why this is not working?is it possible?
is there a python script that uses ps2 that i could change?

anyway thats all just started will continue..

p.s so far code runs and all left right work but if i add crazyflie code runs connects but as soon as i touche a key it closes the python3 window.

thankks
crazyflying
Beginner
Posts: 20
Joined: Thu Oct 26, 2017 3:24 pm

Re: python client keyboard control

Post by crazyflying »

infact just found this very similar...question i belive...as he is looking to do the same as me as in osx voice control a bash script into python to crazyflie?

viewtopic.php?f=6&t=2648


read it but seems i need to change firware and flash new firmware?

or can i do it just in python please please?
marcus
Bitcraze
Posts: 659
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: python client keyboard control

Post by marcus »

Hi!

The script you are trying to use requires the Flow deck for velocity control. Are you using the Flow deck?

If you just want to control the Crazyflie from a terminal using a joystick I would recommend using the headless client that is in the crazyflie-clients-python repository:

Code: Select all

$ bin/cfheadless --help
Disabling standard output for libraries!
usage: cfheadless [-h] [-u URI] [-i INPUT] [-d] [-c CONTROLLER]
                  [--controllers] [-x]

optional arguments:
  -h, --help            show this help message and exit
  -u URI, --uri URI     URI to use for connection to the Crazyradio dongle,
                        defaults to radio://0/10/250K
  -i INPUT, --input INPUT
                        Input mapping to use for the controller,defaults to
                        PS3_Mode_1
  -d, --debug           Enable debug output
  -c CONTROLLER, --controller CONTROLLER
                        Use controller with specified id, id defaults to 0
  --controllers         Only display available controllers and exit
  -x, --x-mode          Enable client-side X-mode

marcus
Bitcraze
Posts: 659
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: python client keyboard control

Post by marcus »

I was a bit quick and misunderstood the question, now I understand what you want to do :-)

One issue is that you have to call the command command at least 2 times per second which I'm not sure you will be able to do using your code. I think that the event loop will lock until you press a key. Or? If that's the case I would recommend using a separate thread that send the command at at least 2Hz and send events from the PyGame event loop into that thread.
crazyflying
Beginner
Posts: 20
Joined: Thu Oct 26, 2017 3:24 pm

Re: python client keyboard control

Post by crazyflying »

ok ok ...

how do i get a controller to work with headless?
do i just run python3 headless.py -c and plug in a usb controlerr or is it more complicated?
how would i set it to use my internal keyboard ?

as for python i am new an have no idea how to up the speed of sending commands to 2 hz any help would be good...if not im sure time will tell.

thanks
Post Reply