control_select.cpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2004 Etienne Lachance
3 
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8 
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 Report problems and direct all questions to:
20 
21 email: etienne.lachance@polymtl.ca or richard.gourdeau@polymtl.ca
22 
23 -------------------------------------------------------------------------------
24 Revision_history:
25 
26 2004/07/13: Ethan Tira-Thompson
27  -Added support for newmat's use_namespace #define, using ROBOOP namespace
28  -Using config::select_real instead of select_double
29 
30 2004/08/14: Ethan Tira-Thompson
31  -Replace select_real and select_double by select.
32 
33 2004/09/18: Etienne Lachance
34  -Controller type NONE
35 
36 2005/11/06: Etienne Lachance
37  - No need to provide a copy constructor and the assignment operator
38  (operator=) for Control_Select class. Instead we use the one provide by the
39  compiler.
40 -------------------------------------------------------------------------------
41 */
42 
48 static const char rcsid[] = "$Id: control_select.cpp,v 1.7 2006/05/16 19:24:26 gourdeau Exp $";
50 
51 #include "config.h"
52 #include "control_select.h"
53 #include "trajectory.h"
54 
55 #ifdef use_namespace
56 namespace ROBOOP {
57  using namespace NEWMAT;
58 #endif
59 
62 {
63  type = NONE;
64  space_type = NONE;
65  dof = 0;
66 }
67 
68 Control_Select::Control_Select(const string & filename)
73 {
74  set_control(filename);
75 }
76 
79 {
80  return dof;
81 }
82 
83 void Control_Select::set_control(const string & filename)
85 {
86  Config conf(true);
87  ifstream inconffile(filename.c_str(), std::ios::in);
88  if (conf.read_conf(inconffile))
89  {
90  cerr << "Control_Select::set_control: unable to read input config file." << endl;
91  }
92 
93  conf.select(CONTROLLER, "type", ControllerName);
94 
95  if (ControllerName == PROPORTIONAL_DERIVATIVE)
96  {
97  type = PD;
98  space_type = JOINT_SPACE;
99  }
100  else if(ControllerName == COMPUTED_TORQUE_METHOD)
101  {
102  type = CTM;
103  space_type = JOINT_SPACE;
104  }
105  else if(ControllerName == RESOLVED_RATE_ACCELERATION)
106  {
107  type = RRA;
108  space_type = CARTESIAN_SPACE;
109  }
110  else if(ControllerName == IMPEDANCE)
111  {
112  type = IMP;
113  space_type = CARTESIAN_SPACE;
114  }
115  else
116  {
117  ControllerName = "";
118  type = NONE;
119  space_type = 0;
120  }
121 
122  conf.select(CONTROLLER, "dof", dof);
123 
124  switch (type) {
125  case PD:
126  {
127  pd = Proportional_Derivative(dof);
128  DiagonalMatrix Kp(dof), Kd(dof);
129  for(int i = 1; i <= dof; i++)
130  {
131  ostringstream Kp_ostr, Kd_ostr;
132  Kp_ostr << "Kp_" << i;
133  Kd_ostr << "Kd_" << i;
134  conf.select("GAINS", Kp_ostr.str(), Kp(i));
135  conf.select("GAINS", Kd_ostr.str(), Kd(i));
136  }
137  pd.set_Kp(Kp);
138  pd.set_Kd(Kd);
139  }
140  break;
141 
142  case CTM:
143  {
144  ctm = Computed_torque_method(dof);
145  DiagonalMatrix Kp(dof), Kd(dof);
146  for(int i = 1; i <= dof; i++)
147  {
148  ostringstream Kp_ostr, Kd_ostr;
149  Kp_ostr << "Kp_" << i;
150  Kd_ostr << "Kd_" << i;
151  conf.select("GAINS", Kp_ostr.str(), Kp(i));
152  conf.select("GAINS", Kd_ostr.str(), Kd(i));
153  }
154  ctm.set_Kp(Kp);
155  ctm.set_Kd(Kd);
156  }
157  break;
158 
159  case RRA:
160  {
161  rra = Resolved_acc(dof);
162  Real Kvp, Kpp, Kvo, Kpo;
163  conf.select("GAINS", "Kvp", Kvp);
164  conf.select("GAINS", "Kpp", Kpp);
165  conf.select("GAINS", "Kvo", Kvo);
166  conf.select("GAINS", "Kpo", Kpo);
167 
168  rra.set_Kvp( Kvp );
169  rra.set_Kpp( Kpp );
170  rra.set_Kvo( Kvo );
171  rra.set_Kpo( Kpo );
172  }
173  break;
174 
175  case IMP:
176  {
177  }
178  break;
179 
180  default:
181  break;
182  }
183 }
184 
185 #ifdef use_namespace
186 }
187 #endif
188 
Computer torque method controller class.
Definition: controller.h:220
void set_control(const std::string &filename)
Select the proper controller from filename.
#define CONTROLLER
short read_conf(std::ifstream &inconffile)
Read a configuration file.
Definition: config.cpp:72
Header file for trajectory generation class.
Header file for Control_Select class definitions.
Resolved rate acceleration controller class.
Definition: controller.h:171
#define IMPEDANCE
Header file for Config class definitions.
double Real
Definition: include.h:307
bool select(const std::string &section, const std::string &parameter, T &value) const
Get a parameter data, of a certain section, into the string value.
Definition: config.h:109
Handle configuration files.
Definition: config.h:97
#define IMP
#define JOINT_SPACE
Definition: trajectory.h:109
static const char rcsid[]
RCS/CVS version.
#define RESOLVED_RATE_ACCELERATION
#define CARTESIAN_SPACE
Definition: trajectory.h:110
#define NONE
Diagonal matrix.
Definition: newmat.h:896
Control_Select()
Constructor.
#define RRA
#define PROPORTIONAL_DERIVATIVE
int get_dof()
Return the degree of freedom.
Proportional derivative controller class.
Definition: controller.h:252
#define PD
#define COMPUTED_TORQUE_METHOD
#define CTM


kni
Author(s): Martin Günther
autogenerated on Fri Jun 7 2019 22:06:44