#include "testPidController.hxx" #include "testPidControllerData.hxx" #include "test_suite/FGTestApi/testGlobals.hxx" #include #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::test() { sg_srandom(999); // Define vertical-hold pid-controller (based on Harrier-GR3). // std::string config_text = 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 )"; 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->add_subsystem("ap", ap, SGSubsystemMgr::FDM); ap->bind(); ap->init(); assert(pidControllerInputs.size() == pidControllerOutputs.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"; } } }