Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test/.DS_Store
.vscode
rpl-sim
build/*
data/*

# CMake Ignore
CMakeLists.txt.user
Expand Down
24 changes: 22 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include(FetchContent)
# PROJECT FILES
##############################################################################

set(RPLSIM_FILES src/PhoenixPositionProvider.cpp src/PhoenixPositionProviderUtility.cpp src/Vector3.cpp)
set(RPLSIM_FILES src/VirtualBarometer.cpp src/PhoenixPositionProvider.cpp src/PhoenixPositionProviderUtility.cpp src/Vector3.cpp)

##############################################################################
# CATCH2 AND EIGEN -- REMOTE SOURCE
Expand Down Expand Up @@ -101,8 +101,28 @@ add_executable(
target_link_libraries(tests LINK_PUBLIC Boost::boost Boost::program_options)
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain Eigen3::Eigen)

add_executable(
vbtests
test/VirtualBarometerTests.cpp
${RPLSIM_FILES}
)

target_link_libraries(vbtests LINK_PUBLIC Boost::boost Boost::program_options)
target_link_libraries(vbtests PRIVATE Catch2::Catch2WithMain Eigen3::Eigen)

# add_executable(
# fsimtests
# test/FluidToEngineSimTests.cpp
# ${RPLSIM_FILES}
# )

# target_link_libraries(fsimtests LINK_PUBLIC Boost::boost Boost::program_options)
# target_link_libraries(fsimtests PRIVATE Catch2::Catch2WithMain Eigen3::Eigen)

# https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
include(CTest)
include(Catch)
catch_discover_tests(tests)
catch_discover_tests(tests)
catch_discover_tests(vbtests)
# catch_discover_tests(fsimtests)
10 changes: 0 additions & 10 deletions Makefile

This file was deleted.

5 changes: 0 additions & 5 deletions data/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions data/atmosisa.csv

This file was deleted.

2 changes: 0 additions & 2 deletions data/mach_vs_cd.csv

This file was deleted.

2 changes: 0 additions & 2 deletions data/thrust_curve.csv

This file was deleted.

2 changes: 1 addition & 1 deletion src/PhoenixPositionProvider.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef PHOENIX_POSITION_PROVIDER_H
#define PHOENIX_POSITION_PROVIDER_H
#include <time.h> // for seeind rand
#include <ctime> // for seeding rand
#include <stdlib.h> // for rand
#include "PhoenixPositionProviderUtility.h"
#include "Vector3.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/PhoenixPositionProviderUtility.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef PHOENIX_POSITION_PROVIDER_UTILITY_H
#define PHOENIX_POSITION_PROVIDER_UTILITY_H
#define PHOmENIX_POSITION_PROVIDER_UTILITY_H
#include <boost/numeric/odeint.hpp>
#include "spline.h"
#include <cmath>
Expand Down
22 changes: 22 additions & 0 deletions src/VirtualBarometer.cpp
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing debug std::cout prints and instead either:

  • Print to file
  • Write function that prints state of barometer every simulation tick, and call that in simulate loop

position_provider.process(deltatime);
Copy link
Contributor

Choose a reason for hiding this comment

The 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 position_provider.process(deltatime) in the main simulation loop as a first step, then call VirtualBarometer::process() after it. This prevents coupling that is present here.

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;
}
22 changes: 22 additions & 0 deletions src/VirtualBarometer.h
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a pointer to position_provider. Currently, it is declared as a unique instance that is a member of this class. Consider change to PhoenixPositionProvider* position_provider.

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
61 changes: 61 additions & 0 deletions test/FluidToEngineSimTests.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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") {
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
}
43 changes: 43 additions & 0 deletions test/VirtualBarometerTests.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The 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));
}