Hello Tello Pilot!
Join our DJI Tello community & remove this banner.
Sign up

Tello keyboard control program not working - python

ConfusionSpren

New member
Joined
Oct 14, 2023
Messages
3
Reaction score
0
I am new to Python and fairly new to programming in general. I wrote this program to be able to control my tello with my keyboard. It works without the stabilization component, but it did not stop moving when I released the keys. To stop that I tried to have it auto-stabilize, but now it just moves in random directions.

EDIT: Attached the code because forum messed up the indentation.
 

Attachments

  • Key input tello.txt
    1.7 KB · Views: 13
Last edited:
I don't understand the purpose of the 'while' loop, and where does it end?

In any event, your code checks for each of the specified keypresses, and doesn't handle key releases at all. You need a keyboard listener that will continuously monitor keyboard events. Sometime ago, I used keyboard commands to control my drone. When the designated key was released, I sent a command to place the drone in a hover mode, i.e., tello.send_rc_control(0, 0, 0, 0).

In order to monitor for on_press and on_release keyboard events, I suggest you use the pynput library. See pynput

I'm attaching an example of using pynput to create a continuous keyboard listener. I modified this from the pynput documentation, in order to prevent key presses from being entered into my code (I'm not sure if the added code will work in your IDE. I use Thonny, and the added code moves the cursor into the Shell area.). Obviously, this code is not designed for Tello, but if you remove the print() statements and add some 'if' statements to handle specific key presses and releases you should be able to achieve what you want.

For a somewhat more detailed explanation of the pynput keyboard listener, see the section entitled 'Monitoring the keyboard' at Handling the keyboard — pynput 1.7.6 documentation.
 

Attachments

  • keyboard_listener.txt
    843 bytes · Views: 6
Last edited:
I don't understand the purpose of the 'while' loop, and where does it end?

In any event, your code checks for each of the specified keypresses, and doesn't handle key releases at all. You need a keyboard listener that will continuously monitor keyboard events. Sometime ago, I used keyboard commands to control my drone. When the designated key was released, I sent a command to place the drone in a hover mode, i.e., tello.send_rc_control(0, 0, 0, 0).

In order to monitor for on_press and on_release keyboard events, I suggest you use the pynput library. See pynput

I'm attaching an example of using pynput to create a continuous keyboard listener. I modified this from the pynput documentation, in order to prevent key presses from being entered into my code (I'm not sure if the added code will work in your IDE. I use Thonny, and the added code moves the cursor into the Shell area.). Obviously, this code is not designed for Tello, but if you remove the print() statements and add some 'if' statements to handle specific key presses and releases you should be able to achieve what you want.

For a somewhat more detailed explanation of the pynput keyboard listener, see the section entitled 'Monitoring the keyboard' at Handling the keyboard — pynput 1.7.6 documentation.
The loop is checking for if a key is pressed, if a key is pressed it send the corresponding rc control to the drone. It ends when the enter key is pressed.
 
The loop is checking for if a key is pressed, if a key is pressed it send the corresponding rc control to the drone. It ends when the enter key is pressed.
OK. The point here is that you need to capture key releases, not just key presses. When you send an rc command to the drone, it will continue to execute that command until you send another command. When the key is released, for example, your code could send a command for the drone to hover in place. Attached is another example that is more like your original code. It uses a "while" loop and the keyboard module. Again, you can easily adapt this code to send Tello rc commands.

I hope this helps.
 

Attachments

  • keyboard_capture.txt
    496 bytes · Views: 10
Last edited:

New Posts

Members online

No members online now.

Forum statistics

Threads
5,701
Messages
39,968
Members
17,067
Latest member
atapattu

New Posts