You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: PyFlyt/core/aviary.py
+60-42Lines changed: 60 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,15 @@
17
17
DroneIndex=int
18
18
19
19
20
+
classAviaryInitException(Exception):
21
+
def__init__(self, message: str) ->None:
22
+
self.message=message
23
+
super().__init__(self.message)
24
+
25
+
def__str__(self) ->str:
26
+
returnf"Aviary Error: {self.message}"
27
+
28
+
20
29
classAviary(bullet_client.BulletClient):
21
30
"""Aviary class, the core of how PyFlyt handles UAVs in the PyBullet simulation environment.
22
31
@@ -73,15 +82,18 @@ def __init__(
73
82
print("\033[A \033[A")
74
83
75
84
# check for starting position and orientation shapes
76
-
assert (
77
-
len(start_pos.shape) ==2
78
-
), f"start_pos must be shape (n, 3), currently {start_pos.shape}."
79
-
assert (
80
-
start_pos.shape[-1] ==3
81
-
), f"start_pos must be shape (n, 3), currently {start_pos.shape}."
82
-
assert (
83
-
start_orn.shape==start_pos.shape
84
-
), f"start_orn must be same shape as start_pos, currently {start_orn.shape}."
85
+
iflen(start_pos.shape) !=2:
86
+
raiseAviaryInitException(
87
+
f"start_pos must be shape (n, 3), currently {start_pos.shape}."
88
+
)
89
+
ifstart_pos.shape[-1] !=3:
90
+
raiseAviaryInitException(
91
+
f"start_pos must be shape (n, 3), currently {start_pos.shape}."
92
+
)
93
+
ifstart_orn.shape!=start_pos.shape:
94
+
raiseAviaryInitException(
95
+
f"start_orn must be same shape as start_pos, currently {start_orn.shape}."
96
+
)
85
97
86
98
# check the physics hz
87
99
ifphysics_hz!=240.0:
@@ -91,27 +103,33 @@ def __init__(
91
103
92
104
# check to ensure drone type has same number as drones if is list/tuple
93
105
ifisinstance(drone_type, (tuple, list)):
94
-
assert (
95
-
len(drone_type) ==start_pos.shape[0]
96
-
), f"If multiple `drone_types` are used, must have same number of `drone_types` ({len(drone_type)}) as number of drones ({start_pos.shape[0]})."
106
+
iflen(drone_type) !=start_pos.shape[0]:
107
+
raiseAviaryInitException(
108
+
f"If multiple `drone_types` are used, must have same number of `drone_types` ({len(drone_type)}) as number of drones ({start_pos.shape[0]})."
109
+
)
110
+
iflen(drone_type) !=start_pos.shape[0]:
111
+
raiseAviaryInitException(
112
+
f"If multiple `drone_types` are used, must have same number of `drone_types` ({len(drone_type)}) as number of drones ({start_pos.shape[0]})."
113
+
)
97
114
# check to ensure drone type has same number as drones if is list/tuple
98
115
ifisinstance(drone_options, (tuple, list)):
99
-
assert (
100
-
len(drone_options) ==start_pos.shape[0]
101
-
), f"If multiple `drone_options` ({len(drone_options)}) are used, must have same number of `drone_options` as number of drones ({start_pos.shape[0]})."
116
+
iflen(drone_options) !=start_pos.shape[0]:
117
+
raiseAviaryInitException(
118
+
f"If multiple `drone_options` ({len(drone_options)}) are used, must have same number of `drone_options` as number of drones ({start_pos.shape[0]})."
119
+
)
102
120
103
121
# constants
104
-
self.num_drones=start_pos.shape[0]
105
-
self.start_pos=start_pos
106
-
self.start_orn=start_orn
122
+
self.num_drones: int=start_pos.shape[0]
123
+
self.start_pos: np.ndarray=start_pos
124
+
self.start_orn: np.ndarray=start_orn
107
125
108
126
# do not change because pybullet doesn't like it
109
127
# default physics looprate is 240 Hz
110
-
self.physics_hz=physics_hz
111
-
self.physics_period=1.0/physics_hz
128
+
self.physics_hz: int=physics_hz
129
+
self.physics_period: float=1.0/physics_hz
112
130
113
131
# mapping of drone type string to the constructors
0 commit comments