Skip to content

Commit b00cf04

Browse files
committed
extend demo to switch camera and add documentation
1 parent 9609131 commit b00cf04

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ At present this is in the format of a numpy array with dimensions (width, height
3030
The drone's property `navdata` contains always the latest navdata.
3131
You can for example get the current battery charge from that:
3232

33-
```
33+
```python
3434
>>> bat = drone.navdata.get(0, dict()).get('battery', 0)
3535
>>> print('Battery: %i%%' % bat)
3636
```
@@ -43,12 +43,17 @@ and lets you remote-control the drone with the keyboard (you need pygame for it
4343

4444
RETURN - takeoff
4545
SPACE - land
46-
BACKSPACE - reset (from emergency)
47-
a/d - left/right
48-
w/s - forward/back
46+
BACKSPACE - reset (from emergency - DO NOT USE IN FLIGHT)
47+
w - forward
48+
a - left
49+
s - back
50+
d - right
51+
LEFT/q - turn left
52+
RIGHT/e - turn right
4953
1,2,...,0 - speed
5054
UP/DOWN - altitude
51-
LEFT/RIGHT - turn left/right
55+
r - switch to front facing camera
56+
f - switch to downward facing camera
5257

5358
Here is a [video] of the library in action:
5459

demo/demo_pygame.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ def main():
5454
running = False
5555
# takeoff / land
5656
elif event.key == pygame.K_RETURN:
57-
print("return")
5857
drone.takeoff()
5958
elif event.key == pygame.K_SPACE:
60-
print("space")
6159
drone.land()
6260
# emergency
6361
elif event.key == pygame.K_BACKSPACE:
@@ -78,9 +76,9 @@ def main():
7876
elif event.key == pygame.K_DOWN:
7977
drone.move_down()
8078
# turn left / turn right
81-
elif event.key == pygame.K_LEFT:
79+
elif event.key in [pygame.K_LEFT, pygame.K_q]:
8280
drone.turn_left()
83-
elif event.key == pygame.K_RIGHT:
81+
elif event.key in [pygame.K_RIGHT, pygame.K_e]:
8482
drone.turn_right()
8583
# speed
8684
elif event.key == pygame.K_1:
@@ -103,11 +101,13 @@ def main():
103101
drone.speed = 0.9
104102
elif event.key == pygame.K_0:
105103
drone.speed = 1.0
106-
104+
elif event.key == pygame.K_r:
105+
drone.set_camera_view(True)
106+
elif event.key == pygame.K_f:
107+
drone.set_camera_view(False)
107108
try:
108-
# print pygame.image
109109
pixelarray = drone.get_image()
110-
if pixelarray != None:
110+
if (not pixelarray is None) and pixelarray.any():
111111
surface = pygame.surfarray.make_surface(pixelarray)
112112
rotsurface = pygame.transform.rotate(surface, 270)
113113
screen.blit(rotsurface, (0, 0))
@@ -117,6 +117,8 @@ def main():
117117
f = pygame.font.Font(None, 20)
118118
hud = f.render('Battery: %i%%' % bat, True, hud_color)
119119
screen.blit(hud, (10, 10))
120+
except KeyboardInterrupt:
121+
break
120122
except:
121123
pass
122124

0 commit comments

Comments
 (0)