-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.py
More file actions
205 lines (155 loc) · 5.52 KB
/
example_usage.py
File metadata and controls
205 lines (155 loc) · 5.52 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env python3
"""
Example usage of the Tello Drone Agent
This script demonstrates how to use the TelloDroneAgent programmatically
for automated drone operations.
"""
import time
from tello_drone_agent import TelloDroneAgent
def basic_flight_demo():
"""Demonstrate basic flight operations."""
print("🚁 Tello Drone Agent - Basic Flight Demo")
print("=" * 50)
# Initialize the agent
agent = TelloDroneAgent()
try:
# Connect to drone
print("1. Connecting to drone...")
if not agent.connect():
print("❌ Failed to connect to drone. Exiting.")
return
# Check status
print("2. Checking drone status...")
status = agent.get_status()
print(f" Battery: {status['battery']}%")
print(f" Temperature: {status['temperature']}°C")
if status['battery'] < 20:
print("⚠️ Battery too low for flight demo")
return
# Start video stream
print("3. Starting video stream...")
agent.start_video_stream()
time.sleep(2) # Wait for stream to stabilize
# Take off
print("4. Taking off...")
if not agent.takeoff():
print("❌ Takeoff failed")
return
time.sleep(3) # Hover for a moment
# Take a photo
print("5. Taking photo...")
photo_file = agent.save_photo("demo_flight.jpg")
print(f" Photo saved: {photo_file}")
# Perform basic movements
print("6. Performing basic movements...")
# Move forward
print(" Moving forward 50cm...")
agent.move_forward(50)
time.sleep(2)
# Rotate 360 degrees
print(" Rotating 360 degrees...")
agent.rotate_clockwise(360)
time.sleep(3)
# Move back to start
print(" Moving back 50cm...")
agent.move_back(50)
time.sleep(2)
# Land
print("7. Landing...")
agent.land()
# Stop video
print("8. Stopping video stream...")
agent.stop_video_stream()
# Show flight log
print("9. Flight log:")
log = agent.get_flight_log()
for entry in log:
action_time = time.strftime("%H:%M:%S", time.localtime(entry['timestamp']))
print(f" [{action_time}] {entry['action']}")
print("\n✅ Demo completed successfully!")
except Exception as e:
print(f"❌ Demo failed: {e}")
finally:
# Always disconnect safely
agent.disconnect()
def photo_mission_demo():
"""Demonstrate automated photo mission."""
print("🚁 Tello Drone Agent - Photo Mission Demo")
print("=" * 50)
agent = TelloDroneAgent()
try:
# Connect and setup
if not agent.connect():
print("❌ Failed to connect")
return
agent.start_video_stream()
time.sleep(2)
if not agent.takeoff():
print("❌ Takeoff failed")
return
# Photo mission: take photos from different angles
positions = [
("center", 0, 0),
("left", -100, 0),
("right", 200, 0),
("back", -100, 100),
("center", 0, -100)
]
for i, (name, x_move, y_move) in enumerate(positions, 1):
print(f"Position {i}: {name}")
if x_move != 0:
if x_move > 0:
agent.move_right(abs(x_move))
else:
agent.move_left(abs(x_move))
if y_move != 0:
if y_move > 0:
agent.move_back(abs(y_move))
else:
agent.move_forward(abs(y_move))
time.sleep(1)
agent.save_photo(f"mission_photo_{i}_{name}.jpg")
print(f" 📸 Photo {i} captured")
# Return to center and land
agent.land()
agent.stop_video_stream()
print("📷 Photo mission completed!")
except Exception as e:
print(f"❌ Mission failed: {e}")
finally:
agent.disconnect()
def status_monitoring_demo():
"""Demonstrate continuous status monitoring."""
print("🚁 Tello Drone Agent - Status Monitoring Demo")
print("=" * 50)
agent = TelloDroneAgent()
try:
if not agent.connect():
return
print("Monitoring drone status for 30 seconds...")
start_time = time.time()
while time.time() - start_time < 30:
status = agent.get_status()
print(f"Battery: {status['battery']}% | "
f"Temp: {status['temperature']}°C | "
f"Height: {status['height']}cm")
time.sleep(5)
print("Monitoring completed")
except Exception as e:
print(f"❌ Monitoring failed: {e}")
finally:
agent.disconnect()
if __name__ == "__main__":
print("Choose a demo:")
print("1. Basic Flight Demo")
print("2. Photo Mission Demo")
print("3. Status Monitoring Demo")
choice = input("Enter choice (1-3): ").strip()
if choice == "1":
basic_flight_demo()
elif choice == "2":
photo_mission_demo()
elif choice == "3":
status_monitoring_demo()
else:
print("Invalid choice")