|
4 | 4 |
|
5 | 5 | from typing import TYPE_CHECKING |
6 | 6 |
|
| 7 | +import numpy as np |
7 | 8 | import pytest |
| 9 | +from drone_models import available_models, model_features |
| 10 | +from drone_models.drones import available_drones |
8 | 11 |
|
9 | | -if TYPE_CHECKING: |
10 | | - from jax import Array as JaxArray |
11 | | - from numpy.typing import NDArray |
12 | | - from torch import Tensor |
| 12 | +from drone_estimators.estimator import KalmanFilter |
| 13 | +from drone_estimators.utils.dynamics import dynamics_function |
13 | 14 |
|
14 | | - Array = NDArray | JaxArray | Tensor |
| 15 | +if TYPE_CHECKING: |
| 16 | + from typing import Callable |
15 | 17 |
|
16 | 18 |
|
17 | 19 | @pytest.mark.unit |
18 | 20 | def test_placeholder(): |
19 | 21 | """Placeholder test.""" |
20 | 22 | pass |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.unit |
| 26 | +@pytest.mark.parametrize("model_name, model", available_models.items()) |
| 27 | +@pytest.mark.parametrize("drone_type", available_drones) |
| 28 | +@pytest.mark.unit |
| 29 | +def test_model_loading(model_name: str, model: Callable, drone_type: str): |
| 30 | + """Tests if the models for the kalman filters can be imported.""" |
| 31 | + dynamics_function(model_name, drone_type) |
| 32 | + |
| 33 | + |
| 34 | +# TODO test if the whole filterpy chain is jitable |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.unit |
| 38 | +@pytest.mark.parametrize("model_name, model", available_models.items()) |
| 39 | +@pytest.mark.parametrize("drone_type", available_drones) |
| 40 | +@pytest.mark.unit |
| 41 | +def test_kalman(model_name: str, model: Callable, drone_type: str): |
| 42 | + """Tests if the Kalman filter can be imported and stepped.""" |
| 43 | + supports_dynamics = model_features(dynamics_function(model_name, drone_type))["rotor_dynamics"] |
| 44 | + kf = KalmanFilter(1 / 200, model_name, drone_type, estimate_rotor_vel=supports_dynamics) |
| 45 | + |
| 46 | + kf.predict(1 / 240, np.array([0.0, 0.0, 0.0, 0.5])) |
| 47 | + |
| 48 | + kf.correct(np.array([0.0, 0.0, 0.0]), np.array([0.0, 0.0, 0.0, 1.0])) |
0 commit comments