-
Notifications
You must be signed in to change notification settings - Fork 8
/
Joystick_and_Video.py
90 lines (57 loc) · 1.6 KB
/
Joystick_and_Video.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
73
74
75
76
77
78
79
80
81
82
83
# Simple pygame test for the google coral
# Maps the gamepad for a Logitech controller
# Author: Danny Dasilva
# License: Public Domain
import pygame
from time import sleep
from app.TEST import Drone
drone = Drone()
pygame.init()
drone.video()
joystick_count = pygame.joystick.get_count()
if joystick_count == 0:
# No joysticks!
print("Error, I didn't find any joysticks.")
else:
# Use joystick #0 and initialize it
gamepad = pygame.joystick.Joystick(0)
gamepad.init()
print('init')
while True:
pygame.event.get()
if joystick_count != 0:
rightsticky = gamepad.get_axis(1)
leftsticky = gamepad.get_axis(4)
rightstickx = gamepad.get_axis(0)
leftstickx = gamepad.get_axis(3)
Start = gamepad.get_button(7)
Back = gamepad.get_button(6)
x, y = gamepad.get_hat(0)
X = gamepad.get_button(2)
Y = gamepad.get_button(3)
A = gamepad.get_button(0)
B = gamepad.get_button(1)
if Start == 1:
print('Start pressed')
drone.takeoff1()
if Back == 1:
drone.land()
print('Back pressed')
if abs(leftsticky) > .05:
drone.pitch(-leftsticky)
else:
drone.pitch(0)
if abs(rightsticky) > .05:
drone.throttle(-rightsticky)
else:
drone.throttle(0)
if abs(leftstickx) > .05:
print("call")
drone.roll(leftstickx)
else:
drone.roll(0)
if abs(rightstickx) > .05:
drone.yaw(rightstickx)
else:
drone.yaw(0)
sleep(.02)