void SMCTest::test_itw_ZOH() { initTwisting(); SP::ControlZOHSimulation simZOH(new ControlZOHSimulation(_t0, _T, _h)); simZOH->setSaveOnlyMainSimulation(true); simZOH->addDynamicalSystem(_DS); simZOH->addSensor(_sensor, _h); simZOH->addActuator(_itw, _h); simZOH->initialize(); simZOH->run(); SimpleMatrix& data = *simZOH->data(); ioMatrix::write("itw_ZOH.dat", "ascii", data, "noDim"); // Reference Matrix SimpleMatrix dataRef(data); dataRef.zero(); ioMatrix::read("itw.ref", "ascii", dataRef); // it is a bad idea to compare solutions to an AVI that does not admit a unique solution SiconosVector lambda1 = SiconosVector(data.size(0)); SiconosVector lambda2 = SiconosVector(data.size(0)); data.getCol(3, lambda1); data.getCol(4, lambda2); axpy(_beta, lambda2, lambda1); SiconosVector lambda1Ref = SiconosVector(data.size(0)); SiconosVector lambda2Ref = SiconosVector(data.size(0)); dataRef.getCol(3, lambda1Ref); dataRef.getCol(4, lambda2Ref); axpy(_beta, lambda2Ref, lambda1Ref); data.setCol(3, lambda1); dataRef.setCol(3, lambda1Ref); data.resize(data.size(0), 4); dataRef.resize(data.size(0), 4); std::cout << "------- Integration done, error = " << (data - dataRef).normInf() << " -------" <<std::endl; CPPUNIT_ASSERT_EQUAL_MESSAGE("test_itw_ZOH : ", (data - dataRef).normInf() < _tol, true); }
void PIDTest::testPIDZOH() { init(); SP::ControlZOHSimulation simZOH(new ControlZOHSimulation(_t0, _T, _h)); simZOH->addDynamicalSystem(_DS); simZOH->addSensor(_sensor, _h); simZOH->addActuator(_PIDcontroller, _h); simZOH->initialize(); simZOH->run(); SimpleMatrix& data = *simZOH->data(); ioMatrix::write("PIDZOH.dat", "ascii", data, "noDim"); // Reference Matrix SimpleMatrix dataRef(data); dataRef.zero(); ioMatrix::read("PID.ref", "ascii", dataRef); std::cout << "------- Integration done, error = " << (data - dataRef).normInf() << " -------" <<std::endl; CPPUNIT_ASSERT_EQUAL_MESSAGE("testPIDZOH : ", (data - dataRef).normInf() < _tol, true); }
void ObserverTest::test_SMO_ZOH() { init(); SP::ControlZOHSimulation simZOH(new ControlZOHSimulation(_t0, _T, _h)); simZOH->addDynamicalSystem(_DS); simZOH->addSensor(_sensor, _h); simZOH->addActuator(_pid, _h); SP::Observer smo(new SlidingReducedOrderObserver(_sensor, *_xHat0, _C, _L)); simZOH->addObserver(smo, _h); simZOH->initialize(); simZOH->run(); SimpleMatrix& data = *simZOH->data(); ioMatrix::write("SMO_ZOH.dat", "ascii", data, "noDim"); double error =0.0; bool test = !((error=ioMatrix::compareRefFile(data, "SMO.ref", _tol)) >= 0.0 && error > _tol); std::cout << "------- Integration done -------" << test <<std::endl; CPPUNIT_ASSERT_EQUAL_MESSAGE("test_SMO_ZOH : ", test, true); }
void ObserverTest::test_SMO_ZOH() { init(); SP::ControlZOHSimulation simZOH(new ControlZOHSimulation(_t0, _T, _h)); simZOH->addDynamicalSystem(_DS); simZOH->addSensor(_sensor, _h); simZOH->addActuator(_pid, _h); SP::Observer smo(new SlidingReducedOrderObserver(_sensor, *_xHat0, _C, _L)); simZOH->addObserver(smo, _h); simZOH->initialize(); simZOH->run(); SimpleMatrix& data = *simZOH->data(); ioMatrix::write("SMO_ZOH.dat", "ascii", data, "noDim"); // Reference Matrix SimpleMatrix dataRef(data); dataRef.zero(); ioMatrix::read("SMO.ref", "ascii", dataRef); std::cout << "------- Integration done, error = " << (data - dataRef).normInf() << " -------" <<std::endl; CPPUNIT_ASSERT_EQUAL_MESSAGE("test_SMO_ZOH : ", (data - dataRef).normInf() < _tol, true); }