-
Notifications
You must be signed in to change notification settings - Fork 3
/
flymambo.py
74 lines (65 loc) · 2.46 KB
/
flymambo.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
from mambo_utils.Mambo import Mambo
'''
Thanks to https://github.com/amymcgovern/pyparrot for the original interface
on which this wrapper has been built
'''
class FlyMambo(object):
def __init__(self, mamboAddr):
print("Initializing Mambo...")
self.mamboAddr = mamboAddr
self.mambo = Mambo(mamboAddr, use_wifi=True)
print("Trying to connect...")
self.success = self.mambo.connect(num_retries=5)
if not self.success:
print("Failed to connect...")
exit(0)
else:
print("Connected to Mambo...")
print("sleeping")
self.mambo.smart_sleep(2)
self.mambo.ask_for_state_update()
self.mambo.smart_sleep(2)
self.set_mode("NORMAL")
print("Mambo ready to fly...")
def set_mode(self, mode="NORMAL"):
if mode == "NORMAL":
self.mambo.set_max_tilt(7.0)
self.mambo.set_max_vertical_speed(0.5)
print("Mambo in NORMAL mode...")
elif mode == "SPORT":
self.mambo.set_max_tilt(30.0)
self.mambo.set_max_vertical_speed(3.0)
print("Mambo in SPORT mode...")
def move_mambo(self, move="STOP", amount=50.0, degrees=0.0):
print(("Mambo moving %s by %.2f%%") % (move, amount))
if move == "STOP":
self.mambo.hover()
elif move == "FWD":
self.mambo.fly_direct(0.0, amount, 0.0, 0.0, 0.25)
elif move == "BCK":
self.mambo.fly_direct(0.0, -amount, 0.0, 0.0, 0.25)
elif move == "RGT":
self.mambo.fly_direct(amount, 0.0, 0.0, 0.0, 0.25)
elif move == "LFT":
self.mambo.fly_direct(-amount, 0.0, 0.0, 0.0, 0.25)
elif move == "UP":
self.mambo.fly_direct(0.0, 0.0, 0.0, amount, 0.25)
elif move == "DWN":
self.mambo.fly_direct(0.0, 0.0, 0.0, -amount, 0.25)
elif move == "RGT_TURN":
self.mambo.turn_degrees(degrees)
elif move == "LFT_TURN":
self.mambo.turn_degrees(-degrees)
self.mambo.smart_sleep(1)
def takeoff(self):
print("Mambo taking off...")
self.mambo.safe_takeoff(10)
def land(self):
print("Mambo landing...")
self.mambo.safe_land(10)
def emergency(self):
print("Mambo emergency landing...")
self.mambo.safe_emergency(2)
def get_battery(self):
print(self.mambo.sensors.battery)
return self.mambo.sensors.battery