-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.py
102 lines (88 loc) · 2.68 KB
/
3.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Dancing Dron - CrazyFly dancing for music beat
# Cnaan Aviv 2013-10-05
import time, sys
import usb
from threading import Thread
import logging
import cflib
from cflib.crazyflie import Crazyflie
from cfclient.utils.logconfigreader import LogConfig
from cfclient.utils.logconfigreader import LogVariable
logging.basicConfig(level=logging.INFO)
class _GetchUnix:
def __init__(self):
import tty, sys
def __call__(self):
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
class Main:
def __init__(self):
self.thrust_mult = 1
self.thrust_step = 500
self.thrust = 20000
self.maxthrust = 50000
self.pitch = 0
self.roll = 0
self.yaw = -127
self.stopping = False
Thread(target=self.gui).start()
self.crazyflie = Crazyflie()
cflib.crtp.init_drivers()
# You may need to update this value if your Crazyradio uses a different frequency.
self.crazyflie.open_link("radio://0/10/250K")
#self.crazyflie.open_link("radio://0/6/1M")
self.crazyflie.connectSetupFinished.add_callback(self.connectSetupFinished)
def connectSetupFinished(self, linkURI):
# Start a separate thread to do the motor test.
# Do not hijack the calling thread!
Thread(target=self.pulse_command).start()
def gui(self):
print "bingo"
while True:
#nb = _GetchUnix()
nb = sys.stdin.read(1)
if nb=='x':
self.stopping = True
sys.exit()
if nb=='r':
self.thrust = self.thrust + 2000
if nb=='f':
self.thrust = self.thrust - 2000
if nb=='e':
self.yaw = self.yaw + 0.2
if nb=='q':
self.yaw = self.yaw - 0.2
if nb=='d':
self.roll = self.roll + 0.2
if nb=='a':
self.roll = self.roll - 0.2
if nb=='w':
self.pitch = self.pitch - 0.2
if nb=='s':
self.pitch = self.pitch + 0.2
sys.stdout.write("thrust=")
print self.thrust
sys.stdout.write("yaw=")
print self.yaw
sys.stdout.write("pitch=")
print self.pitch
sys.stdout.write("roll=")
print self.roll
def pulse_command(self):
while self.stopping == False:
self.crazyflie.commander.send_setpoint(self.roll, self.pitch, self.yaw, self.thrust)
time.sleep(0.50)
#if (thrust >= maxthrust):
# thrust_mult = -1
#thrust = thrust + (thrust_step * thrust_mult)
self.crazyflie.commander.send_setpoint(0,0,0,0)
time.sleep(0.1)
self.crazyflie.close_link()
Main()