sot-torque-control  1.5.3
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/command.h>
13 #include <dynamic-graph/command-direct-setter.h>
14 #include <dynamic-graph/command-direct-getter.h>
15 #include <dynamic-graph/command-bind.h>
16 
17 /* --- HELPER ---------------------------------------------------------- */
18 namespace dynamicgraph {
19 namespace sot {
20 namespace dg = dynamicgraph;
21 namespace torquecontrol {
22 using ::dynamicgraph::command::docCommandVerbose;
23 using ::dynamicgraph::command::docCommandVoid0;
24 using ::dynamicgraph::command::docCommandVoid1;
25 using ::dynamicgraph::command::docCommandVoid2;
26 using ::dynamicgraph::command::docDirectGetter;
27 using ::dynamicgraph::command::docDirectSetter;
28 using ::dynamicgraph::command::makeCommandVerbose;
29 using ::dynamicgraph::command::makeCommandVoid0;
30 using ::dynamicgraph::command::makeCommandVoid1;
31 using ::dynamicgraph::command::makeCommandVoid2;
32 using ::dynamicgraph::command::makeDirectGetter;
33 using ::dynamicgraph::command::makeDirectSetter;
34 } // namespace torquecontrol
35 } // namespace sot
36 } // namespace dynamicgraph
37 
38 namespace dynamicgraph {
39 namespace command {
40 
41 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
42 struct CommandVoid5 : public Command {
43  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&)> function_t;
44  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&)> memberFunction_t;
45  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&);
46 
47  CommandVoid5(E& entity, function_t function, const std::string& docString)
48  : Command(entity,
49  boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
50  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID),
51  docString),
52  fptr(function) {}
53 
54  protected:
55  virtual Value doExecute() {
56  assert(getParameterValues().size() == 5);
57  T1 val1 = getParameterValues()[0].value();
58  T2 val2 = getParameterValues()[1].value();
59  T3 val3 = getParameterValues()[2].value();
60  T4 val4 = getParameterValues()[3].value();
61  T5 val5 = getParameterValues()[4].value();
62  fptr(val1, val2, val3, val4, val5);
63  return Value(); // void
64  }
65 
66  private:
67  function_t fptr;
68 };
69 
70 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
72  E& entity, typename CommandVoid5<E, T1, T2, T3, T4, T5>::function_t function, const std::string& docString) {
73  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, function, docString);
74 }
75 
76 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
78  E& entity, boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&)> function,
79  const std::string& docString) {
80  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5),
81  docString);
82 }
83 
84 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5>
86  void (E::*function)(const T1&, const T2&, const T3&, const T4&,
87  const T5&),
88  const std::string& docString) {
89  return new CommandVoid5<E, T1, T2, T3, T4, T5>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5),
90  docString);
91  return NULL;
92 }
93 
94 inline std::string docCommandVoid5(const std::string& doc, const std::string& type1, const std::string& type2,
95  const std::string& type3, const std::string& type4, const std::string& type5) {
96  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
97  "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
98  "Void return.\n\n");
99 }
100 
101 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
102 struct CommandVoid6 : public Command {
103  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> function_t;
104  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> memberFunction_t;
105  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&);
106 
107  CommandVoid6(E& entity, function_t function, const std::string& docString)
108  : Command(entity,
109  boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
110  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(ValueHelper<T6>::TypeID),
111  docString),
112  fptr(function) {}
113 
114  protected:
115  virtual Value doExecute() {
116  assert(getParameterValues().size() == 6);
117  T1 val1 = getParameterValues()[0].value();
118  T2 val2 = getParameterValues()[1].value();
119  T3 val3 = getParameterValues()[2].value();
120  T4 val4 = getParameterValues()[3].value();
121  T5 val5 = getParameterValues()[4].value();
122  T6 val6 = getParameterValues()[5].value();
123  fptr(val1, val2, val3, val4, val5, val6);
124  return Value(); // void
125  }
126 
127  private:
128  function_t fptr;
129 };
130 
131 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
133  E& entity, typename CommandVoid6<E, T1, T2, T3, T4, T5, T6>::function_t function, const std::string& docString) {
134  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, function, docString);
135 }
136 
137 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
139  E& entity, boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&)> function,
140  const std::string& docString) {
141  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
142  docString);
143 }
144 
145 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
147  void (E::*function)(const T1&, const T2&, const T3&,
148  const T4&, const T5&, const T6&),
149  const std::string& docString) {
150  return new CommandVoid6<E, T1, T2, T3, T4, T5, T6>(entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6),
151  docString);
152  return NULL;
153 }
154 
155 inline std::string docCommandVoid6(const std::string& doc, const std::string& type1, const std::string& type2,
156  const std::string& type3, const std::string& type4, const std::string& type5,
157  const std::string& type6) {
158  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
159  "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
160  "Input:\n - A " + type6 + ".\n" + "Void return.\n\n");
161 }
162 
163 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
164 struct CommandVoid7 : public Command {
165  typedef boost::function<void(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)>
167  typedef boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)>
169  typedef void (E::*memberFunction_ptr_t)(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&);
170 
171  CommandVoid7(E& entity, function_t function, const std::string& docString)
172  : Command(
173  entity,
174  boost::assign::list_of(ValueHelper<T1>::TypeID)(ValueHelper<T2>::TypeID)(ValueHelper<T3>::TypeID)(
175  ValueHelper<T4>::TypeID)(ValueHelper<T5>::TypeID)(ValueHelper<T6>::TypeID)(ValueHelper<T7>::TypeID),
176  docString),
177  fptr(function) {}
178 
179  protected:
180  virtual Value doExecute() {
181  assert(getParameterValues().size() == 7);
182  T1 val1 = getParameterValues()[0].value();
183  T2 val2 = getParameterValues()[1].value();
184  T3 val3 = getParameterValues()[2].value();
185  T4 val4 = getParameterValues()[3].value();
186  T5 val5 = getParameterValues()[4].value();
187  T6 val6 = getParameterValues()[5].value();
188  T7 val7 = getParameterValues()[6].value();
189  fptr(val1, val2, val3, val4, val5, val6, val7);
190  return Value(); // void
191  }
192 
193  private:
194  function_t fptr;
195 };
196 
197 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
199  E& entity, typename CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>::function_t function,
200  const std::string& docString) {
201  return new CommandVoid7<E, T1, T2, T3, T4, T5, T6, T7>(entity, function, docString);
202 }
203 
204 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
206  E& entity,
207  boost::function<void(E*, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&)> function,
208  const std::string& docString) {
210  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7), docString);
211 }
212 
213 template <class E, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
215  E& entity, void (E::*function)(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&, const T7&),
216  const std::string& docString) {
218  entity, boost::bind(function, &entity, _1, _2, _3, _4, _5, _6, _7), docString);
219  return NULL;
220 }
221 
222 inline std::string docCommandVoid7(const std::string& doc, const std::string& type1, const std::string& type2,
223  const std::string& type3, const std::string& type4, const std::string& type5,
224  const std::string& type6, const std::string& type7) {
225  return (std::string("\n") + doc + "\n\n" + "Input:\n - A " + type1 + ".\n" + "Input:\n - A " + type2 + ".\n" +
226  "Input:\n - A " + type3 + ".\n" + "Input:\n - A " + type4 + ".\n" + "Input:\n - A " + type5 + ".\n" +
227  "Input:\n - A " + type6 + ".\n" + "Input:\n - A " + type7 + ".\n" + "Void return.\n\n");
228 }
229 
230 } // namespace command
231 } // namespace dynamicgraph
232 
233 #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:198
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:132
dynamicgraph::command::CommandVoid7::doExecute
virtual Value doExecute()
Definition: commands-helper.hh:180
dynamicgraph::command::CommandVoid5::function_t
boost::function< void(const T1 &, const T2 &, const T3 &, const T4 &, const T5 &)> function_t
Definition: commands-helper.hh:43
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:45
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:169
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:44
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:105
dynamicgraph::command::CommandVoid5
Definition: commands-helper.hh:42
dynamicgraph::command::CommandVoid5::doExecute
virtual Value doExecute()
Definition: commands-helper.hh:55
dynamicgraph::command::CommandVoid5::CommandVoid5
CommandVoid5(E &entity, function_t function, const std::string &docString)
Definition: commands-helper.hh:47
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:166
dynamicgraph::command::CommandVoid6
Definition: commands-helper.hh:102
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:168
dynamicgraph::command::CommandVoid6::CommandVoid6
CommandVoid6(E &entity, function_t function, const std::string &docString)
Definition: commands-helper.hh:107
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:103
dynamicgraph::command::CommandVoid7::CommandVoid7
CommandVoid7(E &entity, function_t function, const std::string &docString)
Definition: commands-helper.hh:171
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:94
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:222
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:71
dynamicgraph::command::CommandVoid7
Definition: commands-helper.hh:164
dynamicgraph::command::CommandVoid6::doExecute
virtual Value doExecute()
Definition: commands-helper.hh:115
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:155
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:104