Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jun 22, 2023
1 parent 5dc0a29 commit afb04b3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
5 changes: 2 additions & 3 deletions src/jdrones/energy_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import numpy as np
import numpy.typing as npt

from jdrones.data_models import URDFModel
from jdrones.envs.dronemodels import DronePlus

Expand Down Expand Up @@ -188,9 +187,9 @@ def p_induced(self, v: npt.ArrayLike):
def power(self, v: npt.ArrayLike):
"""
Total power required at the system velocity
.. math::
P_{total} = P_{blade} + P_{parasite} + P_{induced}
Expand Down
23 changes: 12 additions & 11 deletions src/jdrones/wrappers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from typing import SupportsFloat, Any
from typing import Any
from typing import SupportsFloat

import gymnasium
import numpy as np
from gymnasium.core import WrapperActType, WrapperObsType

from gymnasium.core import WrapperActType
from gymnasium.core import WrapperObsType
from jdrones.energy_model import BaseEnergyModel
from jdrones.energy_model import StaticPropellerVariableVelocityEnergyModel
from jdrones.envs.base.basedronenev import BaseDroneEnv
from jdrones.energy_model import (
StaticPropellerVariableVelocityEnergyModel,
BaseEnergyModel,
)


class EnergyCalculationWrapper(gymnasium.Wrapper):
Expand All @@ -29,8 +28,9 @@ def __init__(
elif hasattr(self.env, "env"):
model = self.env.env.model
else:
raise ValueError("Could not find model information within the wrapped "
"environment")
raise ValueError(
"Could not find model information within the wrapped " "environment"
)
self.energy_calculation = energy_model(env.dt, model)

def step(
Expand All @@ -43,8 +43,9 @@ def step(
elif hasattr(self.env, "env"):
vel = self.env.env.state.vel
else:
raise ValueError("Could not find velocity information within the wrapped "
"environment")
raise ValueError(
"Could not find velocity information within the wrapped " "environment"
)
speed = np.linalg.norm(vel)
info["energy"] = self.energy_calculation.energy(speed)

Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def tau_Q(request):
def drag_coeffs(request):
return request.param


@pytest.fixture(params=[1.225])
def rho(request):
return request.param



@pytest.fixture(params=["droneplus.urdf"])
def filepath(request):
root = pathlib.Path("src")
Expand Down Expand Up @@ -167,7 +167,7 @@ def urdfmodel(
tau_Q,
drag_coeffs,
mass,
rho,
rho,
filepath,
mixing_matrix,
):
Expand All @@ -184,7 +184,7 @@ def urdfmodel(
filepath=str(filepath),
mixing_matrix=mixing_matrix,
max_vel_ms=1,
rho=rho
rho=rho,
)


Expand Down
5 changes: 3 additions & 2 deletions tests/envs/position/test_stress.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2023 Jan-Hendrik Ewers
# SPDX-License-Identifier: GPL-3.0-only
import pytest

from jdrones.wrappers import EnergyCalculationWrapper


Expand Down Expand Up @@ -32,6 +31,7 @@ def run(T, dt, env):
)
T_PARAM = pytest.mark.parametrize("T", [2, 10, 100])


@pytest.mark.slow_integration
@AS_PARAM
@T_PARAM
Expand All @@ -52,10 +52,11 @@ def test_long_poly_position(T, dt, fifthorderpolypositiondroneenv):
def test_long_lookahead_position(T, dt, fifthorderpolypositionlookaheaddroneenv):
run(T, dt, fifthorderpolypositionlookaheaddroneenv)


@pytest.mark.slow_integration
@AS_PARAM
@pytest.mark.parametrize("T", [2])
@pytest.mark.parametrize("wrapper",[EnergyCalculationWrapper])
@pytest.mark.parametrize("wrapper", [EnergyCalculationWrapper])
def test_wrappers(T, dt, wrapper, firstorderploypositiondroneenv):
env = wrapper(firstorderploypositiondroneenv)
run(T, dt, env)
7 changes: 2 additions & 5 deletions tests/test_energy_model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import numpy as np
import pytest

from jdrones.energy_model import (
BaseEnergyModel,
StaticPropellerVariableVelocityEnergyModel,
)
from jdrones.energy_model import BaseEnergyModel
from jdrones.energy_model import StaticPropellerVariableVelocityEnergyModel


@pytest.fixture
Expand Down
1 change: 0 additions & 1 deletion tests/test_wrappers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import gymnasium
import numpy as np
import pytest

from jdrones.envs import DronePlus
from jdrones.envs.base.basedronenev import BaseDroneEnv
from jdrones.wrappers import EnergyCalculationWrapper
Expand Down

0 comments on commit afb04b3

Please sign in to comment.