Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Harness #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ add_subdirectory(src)

# python library
add_subdirectory(python-bindings)

# tests
add_subdirectory(tests)
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@ sudo make install

## Tests

Proper testing is TBD, with the coverage
* `f16_flight_dynamics` C++ unit tests
* `f16dynamics` python unit tests
* Testing the C++ dynamics against the VVaerobench implementation and CSAF
* Integration testing with VVaerobench and CSAF
### Core Unit Tests
CMake will download GoogleTest for unit testing the C++ pieces. Under the `<CMake build folder>/test`, run
```shell
ctest
```

### Integration Tests
Python bindings require pytest. Run
```shell
pytest
```

## Jupyter Notebooks

Expand Down
7 changes: 5 additions & 2 deletions src/f16_flight_dynamics/F16Model/src/LowLevelController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ enum F16StateIdxs {
} F16StateIdxs;

/* aircraft trim state */
f16_state_type default_xequil = {502.0, 0.0389, 0.0, 0.0, 0.0389, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1000.0, 9.0567};
//f16_state_type default_xequil = {502.0, 0.0389, 0.0, 0.0, 0.0389, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1000.0, 9.0567};
f16_state_type default_xequil = {502.0, 0.03887505597600522, 0.0, 0.0, 0.03887505597600522, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1000.0,
9.05666543872074};

/* control trim input */
llc_output_type default_uequil = {0.1395, -0.7496, 0.0, 0.0};
//llc_output_type default_uequil = {0.1395, -0.7496, 0.0, 0.0};
llc_output_type default_uequil = {0.13946204864060271, -0.7495784725828754, 0.0, 0.0};

LowLevelController::LowLevelController() {
xequil = default_xequil;
Expand Down
29 changes: 29 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()

add_executable(
core_tests
core/F16PlantTests.cpp
)
target_link_libraries(
core_tests
gtest_main
${PROJECT_NAME}
)

include(GoogleTest)
gtest_discover_tests(core_tests)

# now allow it to be accessed
enable_testing()
add_test(NAME CoreTests COMMAND core_tests)
add_test(NAME PythonBindingTests COMMAND pytest tests/ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

24 changes: 24 additions & 0 deletions tests/core/F16PlantTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by elew on 4/29/22.
//
#include <gtest/gtest.h>
#include <f16_flight_dynamics/F16Model/F16Plant.h>

TEST(F16Plant, Construct) {
F16Components::F16Plant plant = F16Components::F16Plant();
F16Components::f16_input_type in;
F16Components::f16_state_type x{0};
F16Components::f16_full_type xd{0};

/* fill with zeros */
std::fill(in.begin(), in.end(), 0.1);
std::fill(x.begin(), x.end(), 0.1);
std::fill(xd.begin(), xd.end(), 0.0);

/* hmmm... this isn't good */
std::for_each(xd.begin(), xd.end(), [](double &d) { ASSERT_EQ(d, 0.0); });

plant.subf16_model(x, in, xd);

std::for_each(xd.begin(), xd.end(), [](double &d) { ASSERT_NE(d, 0.0); });
}
17 changes: 17 additions & 0 deletions tests/integration/test_f16plant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import csaf.utils as csafutils
import numpy as np


def test_f16simple_csaf():
"""test that the fast version of CSAF F16 Simple matches within tolerance"""
from csaf_f16.systems import F16Simple
from f16dynamics.csaf import F16FastSimple

# error that we're willing to accept over 20s
abs_tol_20s = 0.4

sys = F16Simple()
sys_fast = F16FastSimple()
trajs = sys.simulate_tspan((0.0, 20.0))
trajs_fast = sys_fast.simulate_tspan((0.0, 20.0))
assert np.all(np.isclose(np.array(trajs["plant"].states), np.array(trajs_fast["plant"].states), atol=abs_tol_20s))