Skip to content

Commit 1c8074b

Browse files
authored
Merge pull request #48 from jjshoots/upgrade_ruff
Upgrade ruff and typehints
2 parents e62f9b6 + 146122f commit 1c8074b

35 files changed

+373
-28
lines changed

PyFlyt/core/abstractions/base_controller.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def step(self, state: np.ndarray, setpoint: np.ndarray) -> np.ndarray:
1717
"""Step the controller.
1818
1919
Args:
20+
----
2021
state (np.ndarray): state
2122
setpoint (np.ndarray): setpoint
23+
2224
"""
2325
pass

PyFlyt/core/abstractions/base_drone.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class DroneClass(ABC):
1818
Each drone inheriting from this class must have several attributes and methods implemented before they can be considered usable.
1919
2020
Args:
21+
----
2122
p (bullet_client.BulletClient): PyBullet physics client ID.
2223
start_pos (np.ndarray): an `(3,)` array for the starting X, Y, Z position for the drone.
2324
start_orn (np.ndarray): an `(3,)` array for the starting X, Y, Z orientation for the drone.
@@ -64,6 +65,7 @@ class DroneClass(ABC):
6465
>>> self.use_camera = use_camera
6566
>>> if self.use_camera:
6667
>>> self.camera = Camera(...)
68+
6769
"""
6870

6971
def __init__(
@@ -80,6 +82,7 @@ def __init__(
8082
"""Defines the default configuration for UAVs, to be used in conjunction with the Aviary class.
8183
8284
Args:
85+
----
8386
p (bullet_client.BulletClient): PyBullet physics client ID.
8487
start_pos (np.ndarray): an `(3,)` array for the starting X, Y, Z position for the drone.
8588
start_orn (np.ndarray): an `(3,)` array for the starting X, Y, Z orientation for the drone.
@@ -88,6 +91,7 @@ def __init__(
8891
drone_model (str): name of the drone itself, must be the same name as the folder where the URDF and YAML files are located.
8992
model_dir (None | str = None): directory where the drone model folder is located, if none is provided, defaults to the directory of the default drones.
9093
np_random (None | np.random.RandomState = None): random number generator of the simulation.
94+
9195
"""
9296
if physics_hz % control_hz != 0:
9397
raise ValueError(
@@ -264,9 +268,11 @@ def register_controller(
264268
"""Default register_controller.
265269
266270
Args:
271+
----
267272
controller_id (int): ID to bind to this controller
268273
controller_constructor (type[ControlClass]): A class pointer to the controller implementation, must be subclass of `ControlClass`.
269274
base_mode (int): Whether this controller uses outputs of an underlying controller as setpoints.
275+
270276
"""
271277
if controller_id <= 0:
272278
raise ValueError(

PyFlyt/core/abstractions/base_wind_field.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ def __call__(self, time: float, position: np.ndarray) -> np.ndarray:
4747
"""When given the time float and a position as an (n, 3) array, must return a (n, 3) array representing the local wind velocity.
4848
4949
Args:
50+
----
5051
time (float): float representing the timestep of the simulation in seconds.
5152
position (np.ndarray): (n, 3) array representing a series of n positions to sample wind velocites.
53+
5254
"""
5355
pass
5456

PyFlyt/core/abstractions/boosters.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Boosters:
1616
Additionally, some boosters, typically of the solid fuel variety, cannot be extinguished and reignited, a property we call reignitability.
1717
1818
Args:
19+
----
1920
p (bullet_client.BulletClient): PyBullet physics client ID.
2021
physics_period (float): physics period of the simulation.
2122
np_random (np.random.RandomState): random number generator of the simulation.
@@ -31,6 +32,7 @@ class Boosters:
3132
thrust_unit (np.ndarray): an `(n, 3)` array representing the unit vector pointing in the direction of force for each booster, relative to the booster link's body frame.
3233
reignitable (np.ndarray | list[bool]): a list of booleans representing whether the booster can be extinguished and then reignited.
3334
noise_ratio (np.ndarray): a list of floats representing the percent amount of fluctuation present in each booster.
35+
3436
"""
3537

3638
def __init__(
@@ -54,6 +56,7 @@ def __init__(
5456
"""Used for simulating an array of boosters.
5557
5658
Args:
59+
----
5760
p (bullet_client.BulletClient): PyBullet physics client ID.
5861
physics_period (float): physics period of the simulation.
5962
np_random (np.random.RandomState): random number generator of the simulation.
@@ -69,6 +72,7 @@ def __init__(
6972
thrust_unit (np.ndarray): an `(n, 3)` array representing the unit vector pointing in the direction of force for each booster, relative to the booster link's body frame.
7073
reignitable (np.ndarray | list[bool]): a list of booleans representing whether the booster can be extinguished and then reignited.
7174
noise_ratio (np.ndarray): a list of floats representing the percent amount of fluctuation present in each booster.
75+
7276
"""
7377
self.p = p
7478
self.physics_period = physics_period
@@ -118,7 +122,9 @@ def reset(self, starting_fuel_ratio: float | np.ndarray = 1.0):
118122
"""Reset the boosters.
119123
120124
Args:
125+
----
121126
starting_fuel_ratio (float | np.ndarray): ratio amount of fuel that the booster is reset to.
127+
122128
"""
123129
# deal with everything in percents
124130
self.ratio_fuel_remaining = (
@@ -135,8 +141,10 @@ def get_states(self) -> np.ndarray:
135141
- (b0, b1, ..., bn) represent the remaining fuel ratio
136142
- (c0, c1, ..., cn) represent the current throttle state
137143
138-
Returns:
144+
Returns
145+
-------
139146
np.ndarray: A (3 * num_boosters, ) array
147+
140148
"""
141149
return np.concatenate(
142150
[
@@ -156,9 +164,11 @@ def physics_update(
156164
"""Converts booster settings into forces on the booster and inertia change on fuel tank.
157165
158166
Args:
167+
----
159168
ignition (np.ndarray): (num_boosters,) array of booleans for engine on or off.
160169
pwm (np.ndarray): (num_boosters,) array of floats between [0, 1] for min or max thrust.
161170
rotation (np.ndarray): (num_boosters, 3, 3) rotation matrices to rotate each booster's thrust axis around, this is readily obtained from the `gimbals` component.
171+
162172
"""
163173
assert np.all(ignition >= 0.0) and np.all(
164174
ignition <= 1.0
@@ -214,8 +224,10 @@ def _compute_thrust_mass_inertia(
214224
"""_compute_thrust_mass_inertia.
215225
216226
Args:
227+
----
217228
ignition (np.ndarray): (num_boosters,) array of booleans for engine on or off.
218229
pwm (np.ndarray): (num_boosters,) array of floats between [0, 1] for min or max thrust.
230+
219231
"""
220232
# if not reignitable, logical or ignition_state with ignition
221233
# otherwise, just follow ignition

PyFlyt/core/abstractions/boring_bodies.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ class BoringBodies:
1313
The `BoringBodies` component is used to represent a normal body moving through the air.
1414
1515
Args:
16+
----
1617
p (bullet_client.BulletClient): PyBullet physics client ID.
1718
physics_period (float): physics period of the simulation.
1819
np_random (np.random.RandomState): random number generator of the simulation.
1920
uav_id (int): ID of the drone.
2021
body_ids (np.ndarray | Sequence[int]): (n,) array of IDs for the links representing the bodies.
2122
drag_coefs (np.ndarray): (n, 3) array of drag coefficients for each body in the link-referenced XYZ directions.
2223
normal_areas (np.ndarray): (n, 3) array of frontal areas in the link-referenced XYZ directions.
24+
2325
"""
2426

2527
def __init__(
@@ -35,13 +37,15 @@ def __init__(
3537
"""Used for simulating a body moving through the air.
3638
3739
Args:
40+
----
3841
p (bullet_client.BulletClient): PyBullet physics client ID.
3942
physics_period (float): physics period of the simulation.
4043
np_random (np.random.RandomState): random number generator of the simulation.
4144
uav_id (int): ID of the drone.
4245
body_ids (np.ndarray | Sequence[int]): (n,) array of IDs for the links representing the bodies.
4346
drag_coefs (np.ndarray): (n, 3) array of drag coefficients for each body in the link-referenced XYZ directions.
4447
normal_areas (np.ndarray): (n, 3) array of frontal areas in the link-referenced XYZ directions.
48+
4549
"""
4650
self.p = p
4751
self.physics_period = physics_period
@@ -76,7 +80,9 @@ def state_update(self, rotation_matrix: np.ndarray):
7680
"""Updates the local surface velocity of the boring body.
7781
7882
Args:
83+
----
7984
rotation_matrix (np.ndarray): (3, 3) rotation_matrix of the main body
85+
8086
"""
8187
# get all the states for all the bodies
8288
link_states = self.p.getLinkStates(

PyFlyt/core/abstractions/camera.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Camera:
1919
On image capture, the camera returns an RGBA image, a depth map, and a segmentation map with pixel values representing the IDs of objects in the environment.
2020
2121
Args:
22+
----
2223
p (bullet_client.BulletClient): PyBullet physics client ID.
2324
uav_id (int): ID of the drone.
2425
camera_id (int): integer representing the ID of the link that the camera is attached to.
@@ -29,6 +30,7 @@ class Camera:
2930
camera_position_offset (np.ndarray = np.array([0.0, 0.0, 0.0])): an (3,) array representing an offset of where the camera is from the center of the link in `camera_id`.
3031
is_tracking_camera (bool = False): if the camera is a tracking camera, the focus point of the camera is adjusted to focus on the center body of the aircraft instead of at infinity.
3132
cinematic (bool = False): it's not a bug, it's a feature.
33+
3234
"""
3335

3436
def __init__(
@@ -47,6 +49,7 @@ def __init__(
4749
"""Used for implementing camera modules.
4850
4951
Args:
52+
----
5053
p (bullet_client.BulletClient): PyBullet physics client ID.
5154
uav_id (int): ID of the drone.
5255
camera_id (int): integer representing the ID of the link that the camera is attached to.
@@ -57,6 +60,7 @@ def __init__(
5760
camera_position_offset (np.ndarray = np.array([0.0, 0.0, 0.0])): an (3,) array representing an offset of where the camera is from the center of the link in `camera_id`.
5861
is_tracking_camera (bool = False): if the camera is a tracking camera, the focus point of the camera is adjusted to focus on the center body of the aircraft instead of at infinity.
5962
cinematic (bool = False): it's not a bug, it's a feature.
63+
6064
"""
6165
check_numpy()
6266
if is_tracking_camera and use_gimbal:
@@ -96,8 +100,10 @@ def __init__(
96100
def view_mat(self) -> np.ndarray:
97101
"""Generates the view matrix for the camera depending on the current orientation and implicit parameters.
98102
99-
Returns:
103+
Returns
104+
-------
100105
np.ndarray: view matrix.
106+
101107
"""
102108
# get the state of the camera on the robot
103109
camera_state = self.p.getLinkState(self.uav_id, self.camera_id)
@@ -155,8 +161,10 @@ def physics_update(self):
155161
def capture_image(self) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
156162
"""Captures the 3 relevant images from the camera.
157163
158-
Returns:
164+
Returns
165+
-------
159166
tuple[np.ndarray, np.ndarray, np.ndarray]: rgbaImg, depthImg, segImg
167+
160168
"""
161169
_, _, rgbaImg, depthImg, segImg = self.p.getCameraImage(
162170
height=self.camera_resolution[0],

PyFlyt/core/abstractions/gimbals.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ class Gimbals:
1616
Each gimbal can rotate about two arbitrary axis that may not be orthogonal to each other.
1717
1818
Args:
19+
----
1920
p (bullet_client.BulletClient): PyBullet physics client ID.
2021
physics_period (float): physics period of the simulation.
2122
np_random (np.random.RandomState): random number generator of the simulation.
2223
gimbal_unit_1 (np.ndarray): first unit vector that the gimbal rotates around.
2324
gimbal_unit_2 (np.ndarray): second unit vector that the gimbal rotates around.
2425
gimbal_tau (np.ndarray): gimbal actuation time constant.
2526
gimbal_range_degrees (np.ndarray): gimbal actuation range in degrees.
27+
2628
"""
2729

2830
def __init__(
@@ -38,13 +40,15 @@ def __init__(
3840
"""Used for simulating an array of gimbals.
3941
4042
Args:
43+
----
4144
p (bullet_client.BulletClient): PyBullet physics client ID.
4245
physics_period (float): physics period of the simulation.
4346
np_random (np.random.RandomState): random number generator of the simulation.
4447
gimbal_unit_1 (np.ndarray): first unit vector that the gimbal rotates around.
4548
gimbal_unit_2 (np.ndarray): second unit vector that the gimbal rotates around.
4649
gimbal_tau (np.ndarray): gimbal actuation time constant.
4750
gimbal_range_degrees (np.ndarray): gimbal actuation range in degrees.
51+
4852
"""
4953
self.p = p
5054
self.physics_period = physics_period
@@ -119,8 +123,10 @@ def reset(self):
119123
def get_states(self) -> np.ndarray:
120124
"""Gets the current state of the components.
121125
122-
Returns:
126+
Returns
127+
-------
123128
np.ndarray: a (2 * num_gimbals, ) array where every pair of values represents the current state of the gimbal
129+
124130
"""
125131
return np.concatenate(
126132
[
@@ -142,10 +148,13 @@ def compute_rotation(self, gimbal_command: np.ndarray) -> np.ndarray:
142148
"""Returns a rotation vector after the gimbal rotation.
143149
144150
Args:
151+
----
145152
gimbal_command (np.ndarray): (num_gimbals, 2) array of floats between [-1, 1].
146153
147154
Returns:
155+
-------
148156
rotation_vector (np.ndarray): (num_gimbals, 3, 3) rotation matrices for all gimbals.
157+
149158
"""
150159
assert np.all(gimbal_command >= -1.0) and np.all(
151160
gimbal_command <= 1.0
@@ -182,14 +191,17 @@ def _jitted_compute_rotation(
182191
"""Compute the rotation matrix given the gimbal action values.
183192
184193
Args:
194+
----
185195
gimbal_angles (np.ndarray): gimbal_angles
186196
w1 (np.ndarray): w1 from self
187197
w2 (np.ndarray): w2 from self
188198
w1_squared (np.ndarray): w1_squared from self
189199
w2_squared (np.ndarray): w2_squared from self
190200
191201
Returns:
202+
-------
192203
tuple[np.ndarray, np.ndarray]:
204+
193205
"""
194206
# precompute some things
195207
sin_angles = np.sin(gimbal_angles)

0 commit comments

Comments
 (0)