Skip to content

Commit ec3fd39

Browse files
committed
Type hintings added, fast step PID delta time fix
Bumped to v0.6.0 Lighting, shadow caster fix InputState typed dict added PStats conenction Load scene modifications Button input codee changes Scene texture change to use CC0 texture Added CREDITS.md IDroneControllable abstract methods Added some examples DroneState and DroneAction module split Other minor bug fixes
1 parent 448d1f1 commit ec3fd39

36 files changed

+490
-181
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Or alternatively, execute the package using the Python interpreter:
3333
$ python -m dronesim
3434
```
3535

36-
Refer to the `examples/` folder for running the simulator with custom controllers
36+
Refer to the `examples/` folder for running the simulator with custom controllers. You will need to clone this repo in order to access the examples.
3737

3838
## Controls
3939

@@ -48,6 +48,7 @@ Key|Action
4848
Esc|Unlock/Lock and Show/Hide mouse
4949
F1|Toggle visibility of HUD
5050
F3|Toggle visibility of debug view
51+
Shift+F3|Connect to Panda3D's PStats tool for profiling
5152
F5|Change camera mode from one of [Free, First Person or Third Person]
5253
F6|Toggle your control between camera and UAV
5354
F11|Toggle fullscreen

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ Pretty long at the moment. It is in no particular order
2626
- [x] Show crosshair
2727
- [ ] Crosshair blend mode (invert) with what's on screen below it
2828
- [ ] Allow sensor access to physics engine
29-
- [ ] Bump mapping on scene to make depth more realistic
29+
- [x] Bump mapping on scene to make depth more realistic

demo-old/scenes/simple_loop.bam

-24.3 MB
Binary file not shown.

dronesim/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
#Import major classes
77
from dronesim.simulator import DroneSimulator
8-
from dronesim.types import DroneState
9-
from dronesim.interface import IDroneControllable, DefaultDroneControl
8+
from dronesim.interface import IDroneControllable, DroneAction, DroneState
9+
from dronesim.interface.default import DefaultDroneControl
1010
from dronesim.actor import UAVDroneModel
11+
from dronesim.simapp import SimulatorApplication
1112

1213
def make_uav() -> typing.Tuple[DroneSimulator, IDroneControllable, UAVDroneModel]:
1314
'''Simple method to create a UAV model with a simulator attached'''

dronesim/__main__.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11

2-
#Simulated drone
3-
from dronesim import make_uav
2+
#Simulated drone and application
3+
from dronesim import SimulatorApplication, make_uav
44

55
#Sensors
66
from dronesim.sensor.panda3d.camera import Panda3DCameraSensor
77

8-
#App window
9-
from dronesim.simapp import SimulatorApplication
10-
118
import argparse
129

1310
def main():
@@ -19,23 +16,23 @@ def main():
1916
sim, controller, drone = make_uav()
2017

2118
#Application window with the drone entity added
22-
droneWindow = SimulatorApplication(drone)
19+
simulator_window = SimulatorApplication(drone)
2320

2421
# ** Configure the simulator by adding sensors **
2522

2623
#Add a camera sensor facing down
2724
#NOTE: having texture of a power of 2 helps in memory optimization
28-
downCam = Panda3DCameraSensor("downCameraRGB", size=(512,512))
29-
sim.add_sensor(down_camera_rgb = downCam)
25+
down_cam = Panda3DCameraSensor("downCameraRGB", size=(512,512))
26+
sim.add_sensor(down_camera_rgb = down_cam)
3027
#Insert camera into main app window and attach to the scene
31-
downCam.attach_to_env(droneWindow.render, droneWindow.graphicsEngine, droneWindow.win)
28+
down_cam.attach_to_env(simulator_window.render, simulator_window.graphicsEngine, simulator_window.win)
3229
#Move and rotate camera with the UAV object
33-
downCam.reparentTo(drone)
30+
down_cam.reparentTo(drone)
3431
#Face down
35-
downCam.setHpr(0, -90, 0)
32+
down_cam.setHpr(0, -90, 0)
3633

3734
#Start the app
38-
droneWindow.run()
35+
simulator_window.run()
3936

4037
if __name__ == "__main__":
4138
main()

dronesim/actor/uav.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self,
7272
'modelRoot': shell_model,
7373
**propeller_parts
7474
}, anims={'modelRoot': {}}) #To use the multipart w/o LOD loader (this is the way to do it)
75-
75+
7676
for bone in propellers.keys():
7777
#Make node accessible
7878
self.exposeJoint(None, 'modelRoot', bone)
-260 KB
Binary file not shown.

dronesim/cameracontrol.py

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from direct.showbase.ShowBase import ShowBase
99
from direct.actor.Actor import Actor
10-
from .types import Vec4Tuple
10+
from .types import InputState, StepRC
1111
import typing
1212

1313
class CameraControlBase:
@@ -99,6 +99,8 @@ def _mouseModeUnlocked(self):
9999
class FreeCam(CameraControlBase):
100100
'''
101101
Implement Free camera (spectator view) movement
102+
103+
It controls like Blender fly mode or Counter Strike spectator mode
102104
'''
103105
def __init__(self, flySpeed : float = 15.0, *args, **kwargs):
104106
super().__init__(*args, **kwargs)
@@ -120,14 +122,64 @@ def update_scroll(self, dir : float):
120122
def update(self,
121123
dt : float,
122124
lookSensitivity : float = 2000.0,
123-
mvVec : Vec4Tuple = None,
125+
input_state : InputState = None,
124126
**kwargs):
125127

126128
hprVec = self._app.camera.getHpr()
127129
xyzVec = self._app.camera.getPos()
130+
mvVec : StepRC = None
131+
132+
if input_state is not None:
133+
mvVec = input_state['movement_vec']
134+
135+
if mvVec is None:
136+
mvVec = StepRC(0,0,0,0)
137+
138+
if self.mouseLocked:
139+
mx, my = self._grabMouseLockRelative()
140+
#Mouse relative pitch and yaw
141+
hprVec[0] -= mx * lookSensitivity * dt
142+
hprVec[1] -= my * lookSensitivity * dt
143+
144+
hprVec[0] -= mvVec.velr * lookSensitivity * 3e-2 * dt
145+
hprVec[1] += mvVec.velz * lookSensitivity * 3e-2 * dt
146+
147+
hprVec = tuple(self.restrict_Hpr(hprVec))
148+
self._app.camera.setHpr(hprVec)
149+
150+
#Get updated camera matrix
151+
camRotVecFB = self._app.camera.getMat().getRow3(1)
152+
camRotVecLR = self._app.camera.getMat().getRow3(0)
153+
camRotVecFB.normalize()
154+
camRotVecLR.normalize()
155+
156+
#New camera position based on user control and camera facing direction.
157+
#This allows movement in any direction
158+
flyVec = camRotVecLR * mvVec.velx * self._flySpeed * dt + camRotVecFB * mvVec.vely * self._flySpeed * dt
159+
self._app.camera.setPos(xyzVec + flyVec)
160+
161+
162+
class FlyCam(CameraControlBase):
163+
'''
164+
Implement Free camera movement
165+
166+
It controls like Minecraft creative flying mode
167+
'''
168+
def update(self,
169+
dt : float,
170+
lookSensitivity : float = 2000.0,
171+
input_state : InputState = None,
172+
**kwargs):
173+
174+
hprVec = self._app.camera.getHpr()
175+
xyzVec = self._app.camera.getPos()
176+
mvVec : StepRC = None
177+
178+
if input_state is not None:
179+
mvVec = input_state['movement_vec']
128180

129181
if mvVec is None:
130-
mvVec = (0,)*4
182+
mvVec = StepRC(0,0,0,0)
131183

132184
if self.mouseLocked:
133185
mx, my = self._grabMouseLockRelative()

dronesim/interface/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

22
from .control import IDroneControllable
3-
from .default import DefaultDroneControl
3+
from .action import DroneAction
4+
from .state import DroneState

dronesim/interface/action.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
from enum import Enum, auto
3+
4+
class DroneAction(Enum):
5+
'''
6+
Action or operation the UAV has to perform (takeoff, land, flip, etc.).
7+
8+
You can extend this class if your (custom) engine has a different set, but
9+
make sure to use the correct enum class for that!
10+
'''
11+
TAKEOFF = auto()
12+
LAND = auto()
13+
STOP_IN_PLACE = auto()
14+
MOTOROFF = auto()

0 commit comments

Comments
 (0)