Skip to content

Commit

Permalink
Merge pull request #53 from jjshoots/multidogfight
Browse files Browse the repository at this point in the history
Multidogfight
  • Loading branch information
jjshoots authored Sep 23, 2024
2 parents f487e4e + cf20762 commit 431b56e
Show file tree
Hide file tree
Showing 111 changed files with 2,496 additions and 1,585 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ jobs:
pip install .[dev]
- name: Release Test
run: |
xvfb-run -s "-screen 0 1024x768x24" pytest tests/*.py -vvv
xvfb-run -s "-screen 0 1024x768x24" pytest --cov tests/*.py -vvv
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,3 @@ dmypy.json

# Cython debug symbols
cython_debug/

62 changes: 52 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,60 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: "^docs/"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-symlinks
- id: destroyed-symlinks
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-ast
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: detect-private-key
- id: debug-statements
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args: ['--skip=^docs/']
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args:
- '--per-file-ignores=*/__init__.py:F401'
- --max-complexity=30
- --max-line-length=456
- --show-source
- --statistics
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args:
- "--profile=black"
- repo: https://github.com/python/black
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
args:
- --ignore-words-list=null
exclude: docs/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- --source
- --explain
- --convention=google
additional_dependencies: ["tomli"]
- repo: local
hooks:
- id: pyright
Expand All @@ -21,6 +63,6 @@ repos:
language: node
pass_filenames: false
types: [python]
additional_dependencies: ["pyright"]
additional_dependencies: ["pyright@1.1.347"]
args:
- --project=pyproject.toml
1 change: 0 additions & 1 deletion PyFlyt/core/abstractions/base_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def step(self, state: np.ndarray, setpoint: np.ndarray) -> np.ndarray:
"""Step the controller.
Args:
----
state (np.ndarray): state
setpoint (np.ndarray): setpoint
Expand Down
3 changes: 0 additions & 3 deletions PyFlyt/core/abstractions/base_drone.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class DroneClass(ABC):
Each drone inheriting from this class must have several attributes and methods implemented before they can be considered usable.
Args:
----
p (bullet_client.BulletClient): PyBullet physics client ID.
start_pos (np.ndarray): an `(3,)` array for the starting X, Y, Z position for the drone.
start_orn (np.ndarray): an `(3,)` array for the starting X, Y, Z orientation for the drone.
Expand Down Expand Up @@ -83,7 +82,6 @@ def __init__(
"""Defines the default configuration for UAVs, to be used in conjunction with the Aviary class.
Args:
----
p (bullet_client.BulletClient): PyBullet physics client ID.
start_pos (np.ndarray): an `(3,)` array for the starting X, Y, Z position for the drone.
start_orn (np.ndarray): an `(3,)` array for the starting X, Y, Z orientation for the drone.
Expand Down Expand Up @@ -269,7 +267,6 @@ def register_controller(
"""Default register_controller.
Args:
----
controller_id (int): ID to bind to this controller
controller_constructor (type[ControlClass]): A class pointer to the controller implementation, must be subclass of `ControlClass`.
base_mode (int): Whether this controller uses outputs of an underlying controller as setpoints.
Expand Down
10 changes: 3 additions & 7 deletions PyFlyt/core/abstractions/base_wind_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def __call__(self, time: float, position: np.ndarray) -> np.ndarray:
"""When given the time float and a position as an (n, 3) array, must return a (n, 3) array representing the local wind velocity.
Args:
----
time (float): float representing the timestep of the simulation in seconds.
position (np.ndarray): (n, 3) array representing a series of n positions to sample wind velocites.
Expand All @@ -64,10 +63,7 @@ def _check_wind_field_validity(wind_field):
assert np.issubdtype(
test_velocity.dtype, np.floating
), f"Returned wind velocity must be type float, got {test_velocity.dtype}."
assert (
test_velocity.shape
== (
5,
3,
)
assert test_velocity.shape == (
5,
3,
), f"Returned wind velocity must be array of shape (n, 3), got (n+({test_velocity.shape[0] - 5}), {test_velocity.shape[1:]})."
19 changes: 5 additions & 14 deletions PyFlyt/core/abstractions/boosters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Boosters:
Additionally, some boosters, typically of the solid fuel variety, cannot be extinguished and reignited, a property we call reignitability.
Args:
----
p (bullet_client.BulletClient): PyBullet physics client ID.
physics_period (float): physics period of the simulation.
np_random (np.random.RandomState): random number generator of the simulation.
Expand Down Expand Up @@ -57,7 +56,6 @@ def __init__(
"""Used for simulating an array of boosters.
Args:
----
p (bullet_client.BulletClient): PyBullet physics client ID.
physics_period (float): physics period of the simulation.
np_random (np.random.RandomState): random number generator of the simulation.
Expand Down Expand Up @@ -111,7 +109,7 @@ def __init__(
self.max_fuel_rate = max_fuel_rate
self.max_inertia = max_inertia
self.max_thrust = max_thrust
self.thrust_unit = np.expand_dims(thrust_unit, axis=-1)
self.thrust_unit = thrust_unit[..., None]
self.reignitable = np.array(reignitable, dtype=bool)
self.min_thrust = min_thrust
self.ratio_min_throttle = self.min_thrust / self.max_thrust
Expand All @@ -123,7 +121,6 @@ def reset(self, starting_fuel_ratio: float | np.ndarray = 1.0):
"""Reset the boosters.
Args:
----
starting_fuel_ratio (float | np.ndarray): ratio amount of fuel that the booster is reset to.
"""
Expand All @@ -143,7 +140,6 @@ def get_states(self) -> np.ndarray:
- (c0, c1, ..., cn) represent the current throttle state
Returns:
-------
np.ndarray: A (3 * num_boosters, ) array
"""
Expand All @@ -165,7 +161,6 @@ def physics_update(
"""Converts booster settings into forces on the booster and inertia change on fuel tank.
Args:
----
ignition (np.ndarray): (num_boosters,) array of booleans for engine on or off.
pwm (np.ndarray): (num_boosters,) array of floats between [0, 1] for min or max thrust.
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.
Expand All @@ -178,13 +173,10 @@ def physics_update(
pwm <= 1.0
), f"{pwm=} has values out of bounds of 0.0 and 1.0."
if rotation is not None:
assert (
rotation.shape
== (
self.num_boosters,
3,
3,
)
assert rotation.shape == (
self.num_boosters,
3,
3,
), f"`rotation` should be of shape (num_boosters, 3, 3), got {rotation.shape}"

# compute thrust mass inertia
Expand Down Expand Up @@ -225,7 +217,6 @@ def _compute_thrust_mass_inertia(
"""_compute_thrust_mass_inertia.
Args:
----
ignition (np.ndarray): (num_boosters,) array of booleans for engine on or off.
pwm (np.ndarray): (num_boosters,) array of floats between [0, 1] for min or max thrust.
Expand Down
5 changes: 1 addition & 4 deletions PyFlyt/core/abstractions/boring_bodies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class BoringBodies:
The `BoringBodies` component is used to represent a normal body moving through the air.
Args:
----
p (bullet_client.BulletClient): PyBullet physics client ID.
physics_period (float): physics period of the simulation.
np_random (np.random.RandomState): random number generator of the simulation.
Expand All @@ -38,7 +37,6 @@ def __init__(
"""Used for simulating a body moving through the air.
Args:
----
p (bullet_client.BulletClient): PyBullet physics client ID.
physics_period (float): physics period of the simulation.
np_random (np.random.RandomState): random number generator of the simulation.
Expand Down Expand Up @@ -81,7 +79,6 @@ def state_update(self, rotation_matrix: np.ndarray):
"""Updates the local surface velocity of the boring body.
Args:
----
rotation_matrix (np.ndarray): (3, 3) rotation_matrix of the main body
"""
Expand All @@ -101,7 +98,7 @@ def state_update(self, rotation_matrix: np.ndarray):
# rotate all velocities to be in body frame
if rotation_matrix.shape == (len(self.body_ids), 3, 3):
body_velocities = np.matmul(
rotation_matrix, np.expand_dims(body_velocities, -1)
rotation_matrix, body_velocities[..., None]
).squeeze(-1)
elif rotation_matrix.shape == (3, 3):
body_velocities = np.matmul(rotation_matrix, body_velocities.T).T
Expand Down
4 changes: 0 additions & 4 deletions PyFlyt/core/abstractions/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Camera:
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.
Args:
----
p (bullet_client.BulletClient): PyBullet physics client ID.
uav_id (int): ID of the drone.
camera_id (int): integer representing the ID of the link that the camera is attached to.
Expand Down Expand Up @@ -50,7 +49,6 @@ def __init__(
"""Used for implementing camera modules.
Args:
----
p (bullet_client.BulletClient): PyBullet physics client ID.
uav_id (int): ID of the drone.
camera_id (int): integer representing the ID of the link that the camera is attached to.
Expand Down Expand Up @@ -102,7 +100,6 @@ def view_mat(self) -> np.ndarray:
"""Generates the view matrix for the camera depending on the current orientation and implicit parameters.
Returns:
-------
np.ndarray: view matrix.
"""
Expand Down Expand Up @@ -163,7 +160,6 @@ def capture_image(self) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""Captures the 3 relevant images from the camera.
Returns:
-------
tuple[np.ndarray, np.ndarray, np.ndarray]: rgbaImg, depthImg, segImg
"""
Expand Down
7 changes: 0 additions & 7 deletions PyFlyt/core/abstractions/gimbals.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Gimbals:
Each gimbal can rotate about two arbitrary axis that may not be orthogonal to each other.
Args:
----
p (bullet_client.BulletClient): PyBullet physics client ID.
physics_period (float): physics period of the simulation.
np_random (np.random.RandomState): random number generator of the simulation.
Expand All @@ -41,7 +40,6 @@ def __init__(
"""Used for simulating an array of gimbals.
Args:
----
p (bullet_client.BulletClient): PyBullet physics client ID.
physics_period (float): physics period of the simulation.
np_random (np.random.RandomState): random number generator of the simulation.
Expand Down Expand Up @@ -125,7 +123,6 @@ def get_states(self) -> np.ndarray:
"""Gets the current state of the components.
Returns:
-------
np.ndarray: a (2 * num_gimbals, ) array where every pair of values represents the current state of the gimbal
"""
Expand All @@ -149,11 +146,9 @@ def compute_rotation(self, gimbal_command: np.ndarray) -> np.ndarray:
"""Returns a rotation vector after the gimbal rotation.
Args:
----
gimbal_command (np.ndarray): (num_gimbals, 2) array of floats between [-1, 1].
Returns:
-------
rotation_vector (np.ndarray): (num_gimbals, 3, 3) rotation matrices for all gimbals.
"""
Expand Down Expand Up @@ -192,15 +187,13 @@ def _jitted_compute_rotation(
"""Compute the rotation matrix given the gimbal action values.
Args:
----
gimbal_angles (np.ndarray): gimbal_angles
w1 (np.ndarray): w1 from self
w2 (np.ndarray): w2 from self
w1_squared (np.ndarray): w1_squared from self
w2_squared (np.ndarray): w2_squared from self
Returns:
-------
tuple[np.ndarray, np.ndarray]:
"""
Expand Down
Loading

0 comments on commit 431b56e

Please sign in to comment.