|
| 1 | +/* |
| 2 | + * Copyright 2019, |
| 3 | + * Olivier Stasse, |
| 4 | + * |
| 5 | + * CNRS/AIST |
| 6 | + * |
| 7 | + */ |
| 8 | + |
| 9 | +#include <iostream> |
| 10 | +#include <sot/core/debug.hh> |
| 11 | + |
| 12 | + |
| 13 | +#ifndef WIN32 |
| 14 | +#include <unistd.h> |
| 15 | +#endif |
| 16 | + |
| 17 | +using namespace std; |
| 18 | + |
| 19 | +#include <dynamic-graph/factory.h> |
| 20 | +#include <dynamic-graph/entity.h> |
| 21 | +#include <sot/core/control-pd.hh> |
| 22 | +#include <sstream> |
| 23 | + |
| 24 | +using namespace dynamicgraph; |
| 25 | +using namespace dynamicgraph::sot; |
| 26 | + |
| 27 | +#define BOOST_TEST_MODULE debug-control-pd |
| 28 | + |
| 29 | +#include <boost/test/unit_test.hpp> |
| 30 | +#include <boost/test/output_test_stream.hpp> |
| 31 | + |
| 32 | +BOOST_AUTO_TEST_CASE(control_pd) |
| 33 | +{ |
| 34 | + sot::ControlPD *aControlPD = new ControlPD("acontrol_pd"); |
| 35 | + aControlPD->init(0.001); |
| 36 | + std::istringstream Kpiss("[5](10.0,20.0,30.0,40.0,50.0)"); |
| 37 | + std::istringstream Kdiss("[5](0.10,0.20,0.30,0.40,0.50)"); |
| 38 | + aControlPD->KpSIN.set(Kpiss); |
| 39 | + aControlPD->KdSIN.set(Kdiss); |
| 40 | + std::istringstream posiss("[5](1.0,1.0,1.0,1.0,1.0)"); |
| 41 | + aControlPD->positionSIN.set(posiss); |
| 42 | + std::istringstream dposiss("[5](3.0,3.1,3.2,3.3,3.4)"); |
| 43 | + aControlPD->desiredpositionSIN.set(dposiss); |
| 44 | + std::istringstream veliss("[5](0.0,0.0,0.0,0.0,0.0)"); |
| 45 | + aControlPD->velocitySIN.set(veliss); |
| 46 | + std::istringstream dveliss("[5](1.5,1.4,1.3,1.2,1.1)"); |
| 47 | + aControlPD->desiredvelocitySIN.set(dveliss); |
| 48 | + |
| 49 | + aControlPD->controlSOUT.recompute(0); |
| 50 | + aControlPD->positionErrorSOUT.recompute(0); |
| 51 | + aControlPD->velocityErrorSOUT.recompute(0); |
| 52 | + { |
| 53 | + boost::test_tools::output_test_stream output; |
| 54 | + aControlPD->controlSOUT.get(output); |
| 55 | + BOOST_CHECK(output.is_equal(" 20.15\n 42.28\n 66.39\n 92.48\n120.55\n")); |
| 56 | + } |
| 57 | + { |
| 58 | + boost::test_tools::output_test_stream output; |
| 59 | + aControlPD->positionErrorSOUT.get(output); |
| 60 | + BOOST_CHECK(output.is_equal(" 2\n2.1\n2.2\n2.3\n2.4\n")); |
| 61 | + } |
| 62 | + { |
| 63 | + boost::test_tools::output_test_stream output; |
| 64 | + aControlPD->velocityErrorSOUT.get(output); |
| 65 | + BOOST_CHECK(output.is_equal("1.5\n1.4\n1.3\n1.2\n1.1\n")); |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | + |
0 commit comments