File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+
3
+ import asyncio
4
+ import sys
5
+
6
+ from mavsdk import System
7
+
8
+
9
+ async def run ():
10
+ drone = System ()
11
+ await drone .connect (system_address = "udp://:14540" )
12
+
13
+ asyncio .ensure_future (observe_shell (drone ))
14
+
15
+ print ("Waiting for drone to connect..." )
16
+ async for state in drone .core .connection_state ():
17
+ if state .is_connected :
18
+ print (f"Drone discovered!" )
19
+ break
20
+
21
+ asyncio .get_event_loop ().add_reader (sys .stdin , got_stdin_data , drone )
22
+ print ("nsh> " , end = '' , flush = True )
23
+
24
+ async def observe_shell (drone ):
25
+ async for output in drone .shell .receive ():
26
+ print (f"\n { output } " , end = '' , flush = True )
27
+
28
+ def got_stdin_data (drone ):
29
+ asyncio .ensure_future (send (drone , sys .stdin .readline ()))
30
+
31
+ async def send (drone , command ):
32
+ await drone .shell .send (command )
33
+
34
+
35
+ if __name__ == "__main__" :
36
+ asyncio .ensure_future (run ())
37
+
38
+ try :
39
+ asyncio .get_event_loop ().run_forever ()
40
+ except KeyboardInterrupt :
41
+ pass
You can’t perform that action at this time.
0 commit comments