Skip to content

Commit 9bdcfca

Browse files
committed
restructre - import libardrone from outside the ardrone folder, move tests and demos into own folders
1 parent a6b9b55 commit 9bdcfca

16 files changed

+779
-690
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.pyc
22
*~
33
.cache
4+
*.egg-info
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
import pygame.surfarray
3333

3434
import pygame.transform
35-
import libardrone
35+
from libardrone import ardrone
3636

3737
def main():
3838
pygame.init()
3939
W, H = 320, 240
4040
screen = pygame.display.set_mode((W, H))
41-
drone = libardrone.ARDrone(True)
41+
drone = ardrone.ARDrone(True)
4242
drone.reset()
4343
clock = pygame.time.Clock()
4444
running = True

demo/demo_termios.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
'''
2+
For testing purpose only
3+
'''
4+
import termios
5+
import fcntl
6+
import os
7+
8+
def main():
9+
fd = sys.stdin.fileno()
10+
11+
oldterm = termios.tcgetattr(fd)
12+
newattr = termios.tcgetattr(fd)
13+
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
14+
termios.tcsetattr(fd, termios.TCSANOW, newattr)
15+
16+
oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
17+
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
18+
19+
drone = ARDrone(is_ar_drone_2=True)
20+
21+
import cv2
22+
try:
23+
startvideo = True
24+
video_waiting = False
25+
while 1:
26+
time.sleep(.0001)
27+
if startvideo:
28+
try:
29+
cv2.imshow("Drone camera", cv2.cvtColor(drone.get_image(), cv2.COLOR_BGR2RGB))
30+
cv2.waitKey(1)
31+
except:
32+
if not video_waiting:
33+
print("Video will display when ready")
34+
video_waiting = True
35+
pass
36+
37+
try:
38+
c = sys.stdin.read(1)
39+
c = c.lower()
40+
print("Got character", c)
41+
if c == 'a':
42+
drone.move_left()
43+
if c == 'd':
44+
drone.move_right()
45+
if c == 'w':
46+
drone.move_forward()
47+
if c == 's':
48+
drone.move_backward()
49+
if c == ' ':
50+
drone.land()
51+
if c == '\n':
52+
drone.takeoff()
53+
if c == 'q':
54+
drone.turn_left()
55+
if c == 'e':
56+
drone.turn_right()
57+
if c == '1':
58+
drone.move_up()
59+
if c == '2':
60+
drone.hover()
61+
if c == '3':
62+
drone.move_down()
63+
if c == 't':
64+
drone.reset()
65+
if c == 'x':
66+
drone.hover()
67+
if c == 'y':
68+
drone.trim()
69+
if c == 'i':
70+
startvideo = True
71+
try:
72+
navdata = drone.get_navdata()
73+
74+
print('Emergency landing =', navdata['drone_state']['emergency_mask'])
75+
print('User emergency landing = ', navdata['drone_state']['user_el'])
76+
print('Navdata type= ', navdata['drone_state']['navdata_demo_mask'])
77+
print('Altitude= ', navdata[0]['altitude'])
78+
print('video enable= ', navdata['drone_state']['video_mask'])
79+
print('vision enable= ', navdata['drone_state']['vision_mask'])
80+
print('command_mask= ', navdata['drone_state']['command_mask'])
81+
except:
82+
pass
83+
84+
if c == 'j':
85+
print("Asking for configuration...")
86+
drone.at(at_ctrl, 5)
87+
time.sleep(0.5)
88+
drone.at(at_ctrl, 4)
89+
except IOError:
90+
pass
91+
finally:
92+
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
93+
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
94+
drone.halt()
95+
96+
if __name__ == "__main__":
97+
main()

libardrone/__init__.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2011 Bastian Venthur
2+
# Copyright (c) 2013 Adrian Taylor
3+
# Copyright (c) 2017 Andreas Bresser
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
23+
24+
"""
25+
Python library for the AR.Drone.
26+
27+
This module was tested with Python 2.7.13 and AR.Drone vanilla firmware 1.5.1.
28+
"""
29+
30+
__author__ = "Bastian Venthur, Adrian Taylor, Andreas Bresser"
31+
32+
__all__ = ['ar2video', 'ardrone', 'at', 'arnetwork', 'arvideo', 'h264decoder', 'navdata', 'paveparser']

0 commit comments

Comments
 (0)