sot-torque-control  1.6.2
Collection of dynamic-graph entities aimed at implementing torque control on different robots.
commands-helper.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011, Nicolas Mansard, LAAS-CNRS
3  *
4  */
5 
6 #ifndef __sot_torquecontrol_commands_helper_H__
7 #define __sot_torquecontrol_commands_helper_H__
8 
9 #include <boost/function.hpp>
10 
11 /* --- COMMON INCLUDE -------------------------------------------------- */
12 #include <dynamic-graph/config.hh>
13 #include <dynamic-graph/command.h>
14 #include <dynamic-graph/command-direct-setter.h>
15 #include <dynamic-graph/command-direct-getter.h>
16 #include <dynamic-graph/command-bind.h>
17 
18 /* --- HELPER ---------------------------------------------------------- */
19 namespace dynamicgraph {
20 namespace sot {
21 namespace dg = dynamicgraph;
22 namespace torquecontrol {
23 using ::dynamicgraph::command::docCommandVerbose;
24 using ::dynamicgraph::command::docCommandVoid0;
25 using ::dynamicgraph::command::docCommandVoid1;
26 using ::dynamicgraph::command::docCommandVoid2;
27 using ::dynamicgraph::command::docCommandVoid3;
28 using ::dynamicgraph::command::docCommandVoid4;
29 using ::dynamicgraph::command::docDirectGetter;
30 using ::dynamicgraph::command::docDirectSetter;
31 using ::dynamicgraph::command::makeCommandVerbose;
32 using ::dynamicgraph::command::makeCommandVoid0;
33 using ::dynamicgraph::command::makeCommandVoid1;
34 using ::dynamicgraph::command::makeCommandVoid2;
35 using ::dynamicgraph::command::makeCommandVoid3;
36 using ::dynamicgraph::command::makeCommandVoid4;
37 using ::dynamicgraph::command::makeDirectGetter;
38 using ::dynamicgraph::command::makeDirectSetter;
39 } // namespace torquecontrol
40 } // namespace sot
41 } // namespace dynamicgraph
42 
43 #if DYNAMIC_GRAPH_VERSION_AT_LEAST(4, 4, 0)
44 namespace dynamicgraph {
45 namespace sot {
46 namespace dg = dynamicgraph;
47 namespace torquecontrol {
51 using ::dynamicgraph::command::docCommandVoid8;
55 using ::dynamicgraph::command::makeCommandVoid8;
56 } // namespace torquecontrol
57 } // namespace sot
58 } // namespace dynamicgraph
59 #else
60 
61 namespace dynamicgraph {
62 namespace command {
63 
64 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
65 struct CommandVoid5 : public Command {
66  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&)> function_t;
67  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&)> memberFunction_t;
68  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&);
69 
70  CommandVoid5(E& entity, function_t function, const std::string& docString)
71  : Command(entity,
72  boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
73  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID),
74  docString),
75  fptr(function) {}
76 
77  protected:
78  virtual Value doExecute() {
79  assert(getParameterValues().size() == 5);
80  T1 val1 = getParameterValues()[0].value();
81  T2 val2 = getParameterValues()[1].value();
82  T3 val3 = getParameterValues()[2].value();
83  T4 val4 = getParameterValues()[3].value();
84  T5 val5 = getParameterValues()[4].value();
85  fptr(val1, val2, val3, val4, val5);
86  return Value(); // void
87  }
88 
89  private:
90  function_t fptr;
91 };
92 
93 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
95  E& entity, typename CommandVoid5<E, T1, T2, T3, T4, T5>::function_t function, const std::string& docString) {
96  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, function, docString);
97 }
98 
99 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
101  E& entity, boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&)> function,
102  const std::string& docString) {
103  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5),
104  docString);
105 }
106 
107 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
109  void (E::*function)(const T1&, const T2&, const T3&, const T4&,
110  const T5&),
111  const std::string& docString) {
112  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5),
113  docString);
114  return NULL;
115 }
116 
117 inline std::string docCommandVoid5(const std::string& doc, const std::string& type1, const std::string& type2,
118  const std::string& type3, const std::string& type4, const std::string& type5) {
119  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
120  "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
121  "Void return.\n\n");
122 }
123 
124 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
125 struct CommandVoid6 : public Command {
126  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> function_t;
127  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> memberFunction_t;
128  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&);
129 
130  CommandVoid6(E& entity, function_t function, const std::string& docString)
131  : Command(entity,
132  boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
133  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(ValueHelper<T6>::TypeID),
134  docString),
135  fptr(function) {}
136 
137  protected:
138  virtual Value doExecute() {
139  assert(getParameterValues().size() == 6);
140  T1 val1 = getParameterValues()[0].value();
141  T2 val2 = getParameterValues()[1].value();
142  T3 val3 = getParameterValues()[2].value();
143  T4 val4 = getParameterValues()[3].value();
144  T5 val5 = getParameterValues()[4].value();
145  T6 val6 = getParameterValues()[5].value();
146  fptr(val1, val2, val3, val4, val5, val6);
147  return Value(); // void
148  }
149 
150  private:
151  function_t fptr;
152 };
153 
154 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
156  E& entity, typename CommandVoid6<E, T1, T2, T3, T4, T5, T6>::function_t function, const std::string& docString) {
157  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, function, docString);
158 }
159 
160 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
162  E& entity, boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> function,
163  const std::string& docString) {
164  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
165  docString);
166 }
167 
168 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
170  void (E::*function)(const T1&, const T2&, const T3&,
171  const T4&, const T5&, const T6&),
172  const std::string& docString) {
173  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
174  docString);
175  return NULL;
176 }
177 
178 inline std::string docCommandVoid6(const std::string& doc, const std::string& type1, const std::string& type2,
179  const std::string& type3, const std::string& type4, const std::string& type5,
180  const std::string& type6) {
181  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
182  "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
183  "Input:\n - A " + type6 + ".\n" + "Void return.\n\n");
184 }
185 
186 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
187 struct CommandVoid7 : public Command {
188  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)>
190  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)>
192  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&);
193 
194  CommandVoid7(E& entity, function_t function, const std::string& docString)
195  : Command(
196  entity,
197  boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
198  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(ValueHelper<T6>::TypeID)(ValueHelper<T7>::TypeID),
199  docString),
200  fptr(function) {}
201 
202  protected:
203  virtual Value doExecute() {
204  assert(getParameterValues().size() == 7);
205  T1 val1 = getParameterValues()[0].value();
206  T2 val2 = getParameterValues()[1].value();
207  T3 val3 = getParameterValues()[2].value();
208  T4 val4 = getParameterValues()[3].value();
209  T5 val5 = getParameterValues()[4].value();
210  T6 val6 = getParameterValues()[5].value();
211  T7 val7 = getParameterValues()[6].value();
212  fptr(val1, val2, val3, val4, val5, val6, val7);
213  return Value(); // void
214  }
215 
216  private:
217  function_t fptr;
218 };
219 
220 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
222  E& entity, typename CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>::function_t function,
223  const std::string& docString) {
224  return new CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>(entity, function, docString);
225 }
226 
227 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
229  E& entity,
230  boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)> function,
231  const std::string& docString) {
233  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7), docString);
234 }
235 
236 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
238  E& entity, void (E::*function)(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&),
239  const std::string& docString) {
241  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7), docString);
242  return NULL;
243 }
244 
245 inline std::string docCommandVoid7(const std::string& doc, const std::string& type1, const std::string& type2,
246  const std::string& type3, const std::string& type4, const std::string& type5,
247  const std::string& type6, const std::string& type7) {
248  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
249  "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
250  "Input:\n - A " + type6 + ".\n" + "Input:\n - A " + type7 + ".\n" + "Void return.\n\n");
251 }
252 
253 } // namespace command
254 } // namespace dynamicgraph
255 #endif
256 
257 #endif // __sot_torquecontrol_commands_helper_H__
dynamicgraph::command::makeCommandVoid7
CommandVoid7< E, T1, T2, T3, T4, T5, T6, T7 > * makeCommandVoid7(E &entity, typename CommandVoid7< E, T1, T2, T3, T4, T5, T6, T7 >::function_t function, const std::string &docString)
Definition: commands-helper.hh:221
dynamicgraph::command::makeCommandVoid6
CommandVoid6< E, T1, T2, T3, T4, T5, T6 > * makeCommandVoid6(E &entity, typename CommandVoid6< E, T1, T2, T3, T4, T5, T6 >::function_t function, const std::string &docString)
Definition: commands-helper.hh:155
dynamicgraph::command::CommandVoid7::doExecute
virtual Value doExecute()
Definition: commands-helper.hh:203
dynamicgraph::command::makeCommandVoid5
CommandVoid5< E, T1, T2, T3, T4, T5 > * makeCommandVoid5(E &entity, void(E::*function)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &), const std::string &docString)
Definition: commands-helper.hh:108
dynamicgraph::command::CommandVoid5::function_t
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &)> function_t
Definition: commands-helper.hh:66
dynamicgraph::command::CommandVoid5::memberFunction_ptr_t
void(E::* memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &)
Definition: commands-helper.hh:68
dynamicgraph::command::CommandVoid7::memberFunction_ptr_t
void(E::* memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &)
Definition: commands-helper.hh:192
dynamicgraph
to read text file
Definition: treeview.dox:22
dynamicgraph::command::CommandVoid5::memberFunction_t
boost::function< void(E *, const T1 &, const T2 &, const T3 &, const T4 &, const T5 &)> memberFunction_t
Definition: commands-helper.hh:67
dynamicgraph::command::CommandVoid6::memberFunction_ptr_t
void(E::* memberFunction_ptr_t)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &)
Definition: commands-helper.hh:128
dynamicgraph::command::CommandVoid5
Definition: commands-helper.hh:65
dynamicgraph::command::CommandVoid5::doExecute
virtual Value doExecute()
Definition: commands-helper.hh:78
dynamicgraph::command::CommandVoid5::CommandVoid5
CommandVoid5(E &entity, function_t function, const std::string &docString)
Definition: commands-helper.hh:70
dynamicgraph::command::CommandVoid7::function_t
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &)> function_t
Definition: commands-helper.hh:189
dynamicgraph::command::CommandVoid6
Definition: commands-helper.hh:125
dynamicgraph::command::CommandVoid7::memberFunction_t
boost::function< void(E *, const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &)> memberFunction_t
Definition: commands-helper.hh:191
dynamicgraph::command::CommandVoid6::CommandVoid6
CommandVoid6(E &entity, function_t function, const std::string &docString)
Definition: commands-helper.hh:130
dynamicgraph::command::CommandVoid6::function_t
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &)> function_t
Definition: commands-helper.hh:126
dynamicgraph::command::CommandVoid7::CommandVoid7
CommandVoid7(E &entity, function_t function, const std::string &docString)
Definition: commands-helper.hh:194
dynamicgraph::command::docCommandVoid5
std::string docCommandVoid5(const std::string &doc, const std::string &type1, const std::string &type2, const std::string &type3, const std::string &type4, const std::string &type5)
Definition: commands-helper.hh:117
dynamicgraph::command::docCommandVoid7
std::string docCommandVoid7(const std::string &doc, const std::string &type1, const std::string &type2, const std::string &type3, const std::string &type4, const std::string &type5, const std::string &type6, const std::string &type7)
Definition: commands-helper.hh:245
dynamicgraph::command::makeCommandVoid5
CommandVoid5< E, T1, T2, T3, T4, T5 > * makeCommandVoid5(E &entity, typename CommandVoid5< E, T1, T2, T3, T4, T5 >::function_t function, const std::string &docString)
Definition: commands-helper.hh:94
dynamicgraph::command::makeCommandVoid7
CommandVoid7< E, T1, T2, T3, T4, T5, T6, T7 > * makeCommandVoid7(E &entity, void(E::*function)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &, const T7 &), const std::string &docString)
Definition: commands-helper.hh:237
dynamicgraph::command::CommandVoid7
Definition: commands-helper.hh:187
dynamicgraph::command::CommandVoid6::doExecute
virtual Value doExecute()
Definition: commands-helper.hh:138
dynamicgraph::command::docCommandVoid6
std::string docCommandVoid6(const std::string &doc, const std::string &type1, const std::string &type2, const std::string &type3, const std::string &type4, const std::string &type5, const std::string &type6)
Definition: commands-helper.hh:178
dynamicgraph::command::makeCommandVoid6
CommandVoid6< E, T1, T2, T3, T4, T5, T6 > * makeCommandVoid6(E &entity, void(E::*function)(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &), const std::string &docString)
Definition: commands-helper.hh:169
dynamicgraph::command::CommandVoid6::memberFunction_t
boost::function< void(E *, const T1 &, const T2 &, const T3 &, const T4 &, const T5 &, const T6 &)> memberFunction_t
Definition: commands-helper.hh:127