#include "testPidController.hxx" #include "testPidControllerData.hxx" #include "test_suite/FGTestApi/testGlobals.hxx" #include #include #include
#include
#include #include // Set up function for each test. void PidControllerTests::setUp() { FGTestApi::setUp::initTestGlobals("ap-pidcontroller"); } // Clean up after each test. void PidControllerTests::tearDown() { FGTestApi::tearDown::shutdownTestGlobals(); } SGPropertyNode_ptr PidControllerTests::configFromString(const std::string& s) { SGPropertyNode_ptr config = new SGPropertyNode; std::istringstream iss(s); readProperties(iss, config); return config; } void PidControllerTests::test0() { test(false /*startup_current*/); } void PidControllerTests::test1() { test(true /*startup_current*/); } void PidControllerTests::test(bool startup_current) { sg_srandom(999); // Define vertical-hold pid-controller (based on Harrier-GR3). // std::string config_text0 = R"( Vertical Speed Hold false true /velocities/vertical-speed-fps /autopilot/settings/vertical-speed-fpm 0.01667 /controls/flight/elevator -0.025 1.0 0.1 0.0 5 0.01 -1 1 )"; // Set the element. std::string from = ""; std::string config_text = config_text0; config_text.replace(config_text.find(from), from.size(), (startup_current) ? "true" : "false" ); assert(config_text != config_text0); std::cout << "config_text is:\n" << config_text << "\n"; SGPropertyNode_ptr config = configFromString(config_text); auto ap = new FGXMLAutopilot::Autopilot(globals->get_props(), config); globals->get_subsystem_mgr()->add("ap", ap); ap->bind(); ap->init(); const std::vector& outputs = (startup_current) ? pidControllerOutputs1 : pidControllerOutputs0; assert(pidControllerInputs.size() == outputs.size()); fgSetDouble("/controls/flight/elevator", 0); for (unsigned i=0; iupdate(0.00833333 /*dt*/); double elevator = fgGetDouble("/controls/flight/elevator"); CPPUNIT_ASSERT_DOUBLES_EQUAL(output.output, elevator, 0.0001); if (0) { // This generates C++ text for setting the vector above. std::cout << "{ " << elevator << "},\n"; } } }