-
Notifications
You must be signed in to change notification settings - Fork 0
Virtual Altimeter base code + initial tests #21
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
base: main
Are you sure you want to change the base?
Changes from all commits
a01224b
0eefd82
333a2c5
b274f67
fa43a54
d9de739
e13df6d
fa6d9ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ test/.DS_Store | |
| .vscode | ||
| rpl-sim | ||
| build/* | ||
| data/* | ||
|
|
||
| # CMake Ignore | ||
| CMakeLists.txt.user | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #include "VirtualBarometer.h" | ||
|
|
||
| VirtualBarometer::VirtualBarometer(unsigned int rs, double alt, double ns): | ||
| random_seed{rs}, altitude_of_launch_site{alt}, noise{ns}, position_provider{}, | ||
| rng {rs}, distribution {-ns, ns} | ||
| { | ||
| // initialize position provider | ||
| current_position = Vector3{0, 0, altitude_of_launch_site}; | ||
| }; | ||
|
|
||
| void VirtualBarometer::process(double deltatime) { | ||
| std::cout << "PROCESSING NEW POSITION" << '\n'; | ||
| position_provider.process(deltatime); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if you folks are changing the architecture, but you probably want to call |
||
| Vector3 new_position = position_provider.getPosition(); | ||
| current_position = current_position + new_position; | ||
| } | ||
|
|
||
| double VirtualBarometer::get_reported_altitude() { | ||
| std::cout << "GETTING REPORTED ALTITUDE" << '\n'; | ||
| double rand = distribution(rng); | ||
| return current_position.z + rand; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #ifndef VIRTUAL_BAROMETER | ||
| #define VIRTUAL_BAROMETER | ||
| #include "PhoenixPositionProvider.h" | ||
| #include <random> | ||
| #include "Vector3.hpp" | ||
|
|
||
| class VirtualBarometer { | ||
| public: | ||
| VirtualBarometer(unsigned int rs, double alt, double ns); | ||
| double get_reported_altitude(); | ||
| void process(double); | ||
| PhoenixPositionProvider position_provider; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be a pointer to |
||
| private: | ||
| unsigned int random_seed; | ||
| double altitude_of_launch_site; | ||
| double noise; | ||
| Vector3 current_position; | ||
| std::default_random_engine rng; | ||
| std::uniform_real_distribution<double> distribution; | ||
| }; | ||
|
|
||
| #endif | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These look good, but check with someone more familiar with the vehicle, I have been retired for a while. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #include "catch2/catch_test_macros.hpp" | ||
| #include "../src/fluid_engine_sim/FluidToEngineSubsystem.cpp" | ||
|
|
||
| // Checking to see default construtor sets status appropriately | ||
| TEST_CASE("WAITING FOR LAUNCH COMMAND", "NORMAL") { | ||
| FluidToEngineSubsystem fs {}; | ||
| REQUIRE( fs.getStatus() == FluidToEngineStatus::WAITING_FOR_LAUNCH_COMMAND); | ||
| } | ||
|
|
||
| // Status set incorrectly, solenoids weren't opened | ||
| TEST_CASE("Ignite Bad Status", "Unexpected Status: WAITING FOR LAUNCH COMMAND") { | ||
| FluidToEngineSubsystem fs {}; | ||
| REQUIRE_THROWS_AS(fs.ignite(), std::runtime_error); | ||
| } | ||
|
|
||
| // Status set correctly, solenoids weren't opened | ||
| TEST_CASE("Ignite Closed Solenoids", "CLOSED SOLENIDS") { | ||
| FluidToEngineSubsystem fs {}; | ||
| fs.setStatus(FluidToEngineStatus::SOLENOIDS_OPEN_FUEL_FLOWING); | ||
| REQUIRE_THROWS_AS(fs.ignite(), std::runtime_error); | ||
| } | ||
|
|
||
| TEST_CASE("Process Loop Run Normal", "Normal") { | ||
| FluidToEngineSubsystem fs {}; | ||
| double solenoid_timer {0.0}; | ||
| double target {300.0}; | ||
| while (solenoid_timer < 201) { | ||
| REQUIRE_NOTHROW([&](){ // C++ anonymous function | ||
| if (solenoid_timer == 200) { | ||
| fs.ignite(); | ||
| }else { | ||
| fs.process(solenoid_timer, target); | ||
| } | ||
| }()); // make sure to actually call lambda function immediately lolz | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lolz |
||
| solenoid_timer++; | ||
| } | ||
| while (solenoid_timer < target) { | ||
| REQUIRE(fs.getStatus() == FluidToEngineStatus::ENGINE_RUNNING); | ||
| REQUIRE(fs.getSolenoidState(Solenoid::LNG_solenoid) == true); | ||
| REQUIRE(fs.getSolenoidState(Solenoid::LOX_solenoid) == true); | ||
|
|
||
| solenoid_timer++; | ||
| } | ||
| } | ||
|
|
||
| TEST_CASE("Process Loop Run Bad Engine", "Engine never ignites") { | ||
| FluidToEngineSubsystem fs {}; | ||
| double solenoid_timer {301.0}; | ||
| double target {300.0}; | ||
| CHECK_THROWS_AS(fs.process(solenoid_timer, target), std::runtime_error); | ||
| } | ||
|
|
||
| TEST_CASE("Process Loop Run Explode", "Engine explodes cuz someone closed solenoid while it was running") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Engine will probably not explode if this happens, it will probably just sputter out. Check w/ Fluid Systems and/or Prop. |
||
| FluidToEngineSubsystem fs {}; | ||
| double solenoid_timer {0.0}; | ||
| double target {300.0}; | ||
| fs.process(solenoid_timer, target); | ||
| fs.ignite(); | ||
| fs.setSolenoidState(Solenoid::LNG_solenoid, false); | ||
| CHECK_THROWS_AS(fs.process(solenoid_timer, target), std::runtime_error); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great tests, especially checking for determinism! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #include "catch2/catch_test_macros.hpp" | ||
| #include "../src/PhoenixPositionProvider.h" | ||
| #include "../src/VirtualBarometer.h" | ||
| #include "catch2/matchers/catch_matchers_floating_point.hpp" | ||
|
|
||
| constexpr double delta = 0.001; | ||
|
|
||
| TEST_CASE("Compare Barometer - Position Provider", "NORMAL") { | ||
| unsigned int seed = 5; | ||
| double alt = 0.0; | ||
| double noise = 0.1; | ||
| VirtualBarometer vb {seed, alt, noise}; | ||
| vb.process(1); | ||
| double target = vb.position_provider.getPosition().z; | ||
| REQUIRE_THAT(vb.get_reported_altitude(), Catch::Matchers::WithinAbs(target, noise)); | ||
| } | ||
|
|
||
| TEST_CASE("Ensure deterministic - Seperate barometers") { | ||
| unsigned int seed = 5; | ||
| double alt = 0.0; | ||
| double noise = 0.1; | ||
| VirtualBarometer vb1 {seed, alt, noise}; | ||
| VirtualBarometer vb2 {seed, alt, noise}; | ||
| vb1.process(1); | ||
| vb2.process(1); | ||
| double vb1Altitude = vb1.get_reported_altitude(); | ||
| double vb2Altitude = vb2.get_reported_altitude(); | ||
| REQUIRE_THAT(vb1Altitude, Catch::Matchers::WithinAbs(vb2Altitude, delta)); | ||
| } | ||
|
|
||
| TEST_CASE("Check altitude changes after process - Single barometer") { | ||
| unsigned int seed = 5; | ||
| double alt = 0.0; | ||
| double noise = 0.1; | ||
| VirtualBarometer vb {seed, alt, noise}; | ||
| vb.process(1); | ||
| double altitude_before = vb.get_reported_altitude(); | ||
| vb.process(1); | ||
| double altitude_after = vb.get_reported_altitude(); | ||
| double diff = altitude_after - altitude_before; | ||
| REQUIRE_THAT(diff, Catch::Matchers::WithinAbs(altitude_before, noise)); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider removing debug
std::coutprints and instead either: