|
6 | 6 | from dronesim.sensor.panda3d.camera import Panda3DCameraSensor
|
7 | 7 |
|
8 | 8 | import threading
|
9 |
| -import time |
10 |
| -from collections import namedtuple |
11 | 9 |
|
12 | 10 | import cv2
|
13 | 11 |
|
@@ -38,17 +36,30 @@ def initEnv(self, app):
|
38 | 36 | self.drone.sensors['down_camera_depth'].setHpr(0, -90, 0)
|
39 | 37 |
|
40 | 38 | 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 |
41 | 43 | self.drone.step({'action': DroneAction.TAKEOFF})
|
| 44 | + |
| 45 | + #Skip some frames till takeoff completes (TODO: wait for state change instead) |
42 | 46 | for _ in range(200):
|
43 | 47 | state = self.drone.step()
|
44 |
| - |
| 48 | + |
| 49 | + #Cycle for 2000 steps |
45 | 50 | for _ in range(2000):
|
46 | 51 | 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) |
50 | 52 | 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 | + |
51 | 60 | cv2.waitKey(10)
|
| 61 | + |
| 62 | + cv2.destroyAllWindows() |
52 | 63 |
|
53 | 64 | def __update_debug_state(self, state):
|
54 | 65 | observation, reward, done, info = state
|
|
0 commit comments