test_factory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 /* -------------------------------------------------------------------------- */
11 /* --- INCLUDES ------------------------------------------------------------- */
12 /* -------------------------------------------------------------------------- */
13 #include <dynamic-graph/entity.h>
15 
16 #include <iostream>
17 #include <sot/core/debug.hh>
19 #include <sot/core/factory.hh>
21 #include <string>
22 
23 #include "../test-paths.h"
24 using namespace std;
25 using namespace dynamicgraph::sot;
26 using namespace dg;
27 
28 #ifdef WIN32
29 #include <Windows.h>
30 #else
31 #include <dlfcn.h>
32 #endif
33 
34 #ifdef WIN32
35 typedef HMODULE sotPluginKey;
36 #else
37 typedef void *sotPluginKey;
38 #endif
39 
40 class TestFeature : public FeatureAbstract {
41  public:
43  virtual ~TestFeature(void) {}
44  virtual unsigned int &getDimension(unsigned int &res, int /*time*/) {
45  return res;
46  }
47 
48  virtual dg::Vector &computeError(dg::Vector &res, int /*time*/) {
49  return res;
50  }
51  virtual dg::Matrix &computeJacobian(dg::Matrix &res, int /*time*/) {
52  return res;
53  }
54  virtual dg::Vector &computeActivation(dg::Vector &res, int /*time*/) {
55  return res;
56  }
57 };
58 
59 int main() {
60  sotDEBUG(0) << "# In {" << endl;
61  // Entity test("");
62  // ExceptionFeature t2(ExceptionFeature::BAD_INIT);
63  // ExceptionSignal t4(ExceptionSignal::COPY_NOT_INITIALIZED);
64  // Flags t3;
65  // TestFeature t5;
66 
67 #ifdef WIN32
68  sotPluginKey dlib = LoadLibrary(PLUGIN_LIB_INSTALL_PATH
69  "/feature-visual-point" TESTS_DYNLIBSUFFIX);
70 #else
71  sotPluginKey dlib =
72  dlopen(PLUGIN_LIB_INSTALL_PATH "/feature-visual-point" TESTS_DYNLIBSUFFIX,
73  RTLD_NOW);
74 #endif
75 
76  if (NULL == dlib) {
77  cerr << " Error dl" << endl;
78 #ifndef WIN32
79  cerr << dlerror() << endl;
80 #else
81  // Retrieve the system error message for the last-error code
82  LPTSTR pszMessage;
83  DWORD dwLastError = GetLastError();
84  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
85  FORMAT_MESSAGE_IGNORE_INSERTS,
86  NULL, dwLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
87  (LPTSTR)&pszMessage, 0, NULL);
88 
89  cerr << pszMessage << endl;
90  LocalFree(pszMessage);
91 #endif
92 
93  exit(1);
94  }
95 
96 #ifdef WIN32
97  dlib =
98  LoadLibrary(PLUGIN_LIB_INSTALL_PATH "/gain-adaptive" TESTS_DYNLIBSUFFIX);
99 #else
100  dlib = dlopen(PLUGIN_LIB_INSTALL_PATH "/gain-adaptive" TESTS_DYNLIBSUFFIX,
101  RTLD_NOW);
102 #endif
103 
104  if (NULL == dlib) {
105  cerr << " Error dl" << endl;
106 #ifndef WIN32
107  cerr << dlerror() << endl;
108 #else
109  // Retrieve the system error message for the last-error code
110  LPTSTR pszMessage;
111  DWORD dwLastError = GetLastError();
112  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
113  FORMAT_MESSAGE_IGNORE_INSERTS,
114  NULL, dwLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
115  (LPTSTR)&pszMessage, 0, NULL);
116 
117  cerr << pszMessage << endl;
118  LocalFree(pszMessage);
119 #endif
120  exit(1);
121  }
122 
123  Entity *gain =
124  FactoryStorage::getInstance()->newEntity("GainAdaptive", "Gain");
125  FeatureAbstract *point =
126  sotFactory.newFeature("FeatureVisualPoint", "DynamicTest.");
127 
128  try {
129  gain->display(cout);
130  cout << endl;
131  cout << gain->getClassName();
132  cout << endl;
133 
134  point->display(cout);
135  cout << endl;
136  cout << point->getClassName();
137  cout << endl;
138  } catch (ExceptionSignal e) {
139  cout << "Exception caught! " << e << endl;
140  }
141 
142  sotDEBUG(0) << "# Out }" << endl;
143 }
int main()
TestFeature(void)
Eigen::VectorXd Vector
void * sotPluginKey
virtual dg::Vector & computeError(dg::Vector &res, int)
Compute the error between the desired feature and the current value of the feature measured or deduce...
virtual ~TestFeature(void)
virtual const std::string & getClassName() const
virtual const std::string & getClassName(void) const
Returns the name class.
virtual unsigned int & getDimension(unsigned int &res, int)
Verbose method.
virtual void display(std::ostream &os) const
virtual dg::Vector & computeActivation(dg::Vector &res, int)
#define sotDEBUG(level)
Definition: debug.hh:165
This class gives the abstract definition of a feature.
Eigen::MatrixXd Matrix
virtual dg::Matrix & computeJacobian(dg::Matrix &res, int)
Compute the Jacobian of the error according the robot state.


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