control/test_control_pd.cpp
Go to the documentation of this file.
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 #ifndef WIN32
13 #include <unistd.h>
14 #endif
15 
16 using namespace std;
17 
18 #include <dynamic-graph/entity.h>
19 #include <dynamic-graph/factory.h>
20 
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/output_test_stream.hpp>
30 #include <boost/test/unit_test.hpp>
31 
32 BOOST_AUTO_TEST_CASE(control_pd) {
33  sot::ControlPD *aControlPD = new ControlPD("acontrol_pd");
34  aControlPD->init(0.001);
35  std::istringstream Kpiss("[5](10.0,20.0,30.0,40.0,50.0)");
36  std::istringstream Kdiss("[5](0.10,0.20,0.30,0.40,0.50)");
37  aControlPD->KpSIN.set(Kpiss);
38  aControlPD->KdSIN.set(Kdiss);
39  std::istringstream posiss("[5](1.0,1.0,1.0,1.0,1.0)");
40  aControlPD->positionSIN.set(posiss);
41  std::istringstream dposiss("[5](3.0,3.1,3.2,3.3,3.4)");
42  aControlPD->desiredpositionSIN.set(dposiss);
43  std::istringstream veliss("[5](0.0,0.0,0.0,0.0,0.0)");
44  aControlPD->velocitySIN.set(veliss);
45  std::istringstream dveliss("[5](1.5,1.4,1.3,1.2,1.1)");
46  aControlPD->desiredvelocitySIN.set(dveliss);
47 
48  aControlPD->controlSOUT.recompute(0);
49  aControlPD->positionErrorSOUT.recompute(0);
50  aControlPD->velocityErrorSOUT.recompute(0);
51  {
52  boost::test_tools::output_test_stream output;
53  aControlPD->controlSOUT.get(output);
54  BOOST_CHECK(output.is_equal("20.15 42.28 66.39 92.48 120.55"));
55  }
56  {
57  boost::test_tools::output_test_stream output;
58  aControlPD->positionErrorSOUT.get(output);
59  BOOST_CHECK(output.is_equal("2 2.1 2.2 2.3 2.4"));
60  }
61  {
62  boost::test_tools::output_test_stream output;
63  aControlPD->velocityErrorSOUT.get(output);
64  BOOST_CHECK(output.is_equal("1.5 1.4 1.3 1.2 1.1"));
65  }
66 }
SignalTimeDependent< dynamicgraph::Vector, int > velocityErrorSOUT
Definition: control-pd.hh:76
virtual void set(std::istringstream &value)
SignalPtr< dynamicgraph::Vector, int > KpSIN
Definition: control-pd.hh:68
BOOST_AUTO_TEST_CASE(control_pd)
SignalPtr< dynamicgraph::Vector, int > desiredvelocitySIN
Definition: control-pd.hh:73
SignalPtr< dynamicgraph::Vector, int > desiredpositionSIN
Definition: control-pd.hh:71
virtual void recompute(const Time &t)
void init(const double &step)
Definition: control-pd.cpp:61
SignalPtr< dynamicgraph::Vector, int > velocitySIN
Definition: control-pd.hh:72
SignalPtr< dynamicgraph::Vector, int > KdSIN
Definition: control-pd.hh:69
SignalTimeDependent< dynamicgraph::Vector, int > controlSOUT
Definition: control-pd.hh:74
SignalTimeDependent< dynamicgraph::Vector, int > positionErrorSOUT
Definition: control-pd.hh:75
virtual void get(std::ostream &value) const
SignalPtr< dynamicgraph::Vector, int > positionSIN
Definition: control-pd.hh:70


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26