Skip to content

Commit 3df6bc9

Browse files
committed
Add simple tests for kalman filters
1 parent 22d7f72 commit 3df6bc9

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

tests/unit/test_estimators.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,45 @@
44

55
from typing import TYPE_CHECKING
66

7+
import numpy as np
78
import pytest
9+
from drone_models import available_models, model_features
10+
from drone_models.drones import available_drones
811

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
1314

14-
Array = NDArray | JaxArray | Tensor
15+
if TYPE_CHECKING:
16+
from typing import Callable
1517

1618

1719
@pytest.mark.unit
1820
def test_placeholder():
1921
"""Placeholder test."""
2022
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

Comments
 (0)