-
Notifications
You must be signed in to change notification settings - Fork 4
/
calibrate_hardsoft.py
72 lines (57 loc) · 2.16 KB
/
calibrate_hardsoft.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
#!/usr/bin/env python2.7
import time
from threading import Thread
import sys
import cflib.crtp
from cflib.crazyflie import Crazyflie
from cfclient.utils.logconfigreader import LogVariable, LogConfig
class Main:
def __init__(self):
self._stop = 0
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.connectSetupFinished.add_callback(self.connectSetupFinished)
def connectSetupFinished(self, linkURI):
lg = LogConfig("Magnetometer", 100)
lg.addVariable(LogVariable("mag.x", "int16_t"))
lg.addVariable(LogVariable("mag.y", "int16_t"))
lg.addVariable(LogVariable("mag.z", "int16_t"))
log = self.crazyflie.log.create_log_packet(lg)
if log is not None:
log.dataReceived.add_callback(self.magData)
log.start()
else:
print "Magnetometer not found in log TOC"
# Keep the commands alive so the firmware kill-switch doesn't kick in.
Thread(target=self.pulse_command).start()
Thread(target=self.input_loop).start()
def stop(self):
# Exit command received
# Set thrust to zero to make sure the motors turn off NOW
# make sure we actually set the thrust to zero before we kill the thread that sets it
time.sleep(0.5)
self._stop = 1;
# Exit the main loop
time.sleep(1)
self.crazyflie.close_link() # This errors out for some reason. Bad libusb?
sys.exit(0)
def input_loop(self):
command = raw_input("")
self.stop()
def pulse_command(self):
while 1:
self.crazyflie.commander.send_setpoint(0, 0, 0, 0)
time.sleep(0.1)
# Exit if the parent told us to
if self._stop==1:
return
def magData(self, data):
x, y, z = data['mag.x'], data['mag.y'], data['mag.z']
try:
print x, y, z
sys.stdout.flush()
except:
self.stop()
Main()