Skip to content

Commit 28c8b8c

Browse files
committed
Updated example
1 parent 3c2c7ae commit 28c8b8c

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

examples/follow.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from dronesim.sensor.panda3d.camera import Panda3DCameraSensor
77

88
import threading
9-
import time
10-
from collections import namedtuple
119

1210
import cv2
1311

@@ -38,17 +36,30 @@ def initEnv(self, app):
3836
self.drone.sensors['down_camera_depth'].setHpr(0, -90, 0)
3937

4038
def run(self):
39+
#Set to True to show an OpenCV window of the RGB camera
40+
show_camera = False
41+
42+
#Tell simulator to takeoff
4143
self.drone.step({'action': DroneAction.TAKEOFF})
44+
45+
#Skip some frames till takeoff completes (TODO: wait for state change instead)
4246
for _ in range(200):
4347
state = self.drone.step()
44-
48+
49+
#Cycle for 2000 steps
4550
for _ in range(2000):
4651
state = self.drone.step(StepRC(0,0.6,0,0))
47-
ret, img = self.drone.sensors['down_camera_rgb'].renderAndGetFrameBuffer()
48-
if ret:
49-
cv2.imshow("Camera frame", img)
5052
self.__update_debug_state(state)
53+
54+
if show_camera:
55+
ret, img = self.drone.sensors['down_camera_rgb'].renderAndGetFrameBuffer()
56+
#Show image only if we got one
57+
if ret:
58+
cv2.imshow("Camera frame", img)
59+
5160
cv2.waitKey(10)
61+
62+
cv2.destroyAllWindows()
5263

5364
def __update_debug_state(self, state):
5465
observation, reward, done, info = state

0 commit comments

Comments
 (0)