-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
72 lines (52 loc) · 1.51 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import pygame
from time import sleep
from djitellopy import Tello
import tkinter as tk
# Joystick Initilization Code
pygame.init()
pygame.joystick.init()
joystick = pygame.joystick.Joystick(0)
joystick.init()
# Tello Initilization Code
tello = Tello()
tello.connect()
# GUI Code (Not Working)
root = tk.Tk()
root.title("Tello Virpil Control")
x_label = tk.Label(root, text="X Axis:")
x_label.pack()
y_label = tk.Label(root, text="Y Axis:")
y_label.pack()
# Send RC Control to Tello, no response needed
def map_joystick_to_tello(x, y):
speed = int(-x * 100)
turn = int(y * 100)
if abs(speed) < 10:
speed = 0
if abs(turn) < 10:
turn = 0
tello.send_rc_control(0, speed, 0, turn)
try:
while True:
pygame.event.pump()
# Flip cause virpil joystick is funky
x_axis = joystick.get_axis(0)
y_axis = joystick.get_axis(1)
x_label.config(text=f"X Axis: {x_axis:.2f}")
y_label.config(text=f"Y Axis: {y_axis:.2f}")
map_joystick_to_tello(x_axis, y_axis)
# Individual Button Mapping
if (joystick.get_button(3) == 1):
tello.land()
if (joystick.get_button(9) == 1 ):
tello.takeoff()
if (joystick.get_button(17) == 1):
tello.move_up(30)
if (joystick.get_button(18) == 1):
tello.move_down(30)
sleep(0.05)
except KeyboardInterrupt:
tello.send_rc_control(0, 0, 0, 0)
tello.land()
tello.end()
root.destroy()