kmlFactories.cpp
Go to the documentation of this file.
1 
2 #include "KNI/kmlFactories.h"
3 
4 namespace KNI {
5 
6 kmlFactory::kmlFactory() : _configfile() {}
7 
8 void kmlFactory::_readEntry(char* dest, int destsz, const char* section, const char* subsection, const char* entry) {
9 
10  char line[256];
11  short pos = 0;
12  short idx = 0;
13 
14  _configfile.seekg(0); //goto the begin
15 
16  if(!_configfile.good())
18 
19 
20  do { //search section
21  memset(line,0,sizeof(line));
22  _configfile.getline(line, sizeof(line));
23  strtok(line,"\r"); // strip off the CR
24  } while (strcmp(line,section));
25 
26  if (_configfile.eof())
28 
29  do { //search subsection
30  memset(line,0,sizeof(line));
31  _configfile.getline(line, sizeof(line));
32  strtok(line,"\r"); // strip off the CR
33  } while (strcmp(line,subsection));
34  if (_configfile.eof())
35  throw ConfigFileSubsectionNotFoundException(subsection);
36 
37  do { //search entry
38  memset(line,0,sizeof(line));
39  _configfile.getline(line, sizeof(line));
40  strtok(line,"\r"); // strip off the CR
41  } while (strncmp(line,entry,strlen(entry)));
42  if (_configfile.eof())
44 
45  //parse input line the detect entry value
46 
47  while (line[pos++] != '=') {
48  if (pos == 256)
50  }
51  while (line[pos++] != '"') {
52  if (pos == 256)
54  }
55 
56  memset(dest,0,destsz);
57  while (line[pos] != '"') {
58  dest[idx++] = line[pos++];
59  if (pos == 256)
61  }
62  while (line[pos++] != ';') {
63  if (pos == 256)
65  }
66 
67 }
68 
69 
71  char input[256];
72  TKatGNL gnl;
73 
74  _readEntry(input,sizeof(input),"[KATANA]","[GENERAL]","addr");
75  gnl.adr = atoi(input);
76 
77  _readEntry(input,sizeof(input),"[KATANA]","[GENERAL]","modelName");
78  sprintf(gnl.modelName, "%s", input);
79 
80  return gnl;
81 }
82 
83 
84 
86  char input[256];
87  TKatMOT mot;
88  _readEntry(input,sizeof(input),"[KATANA]","[GENERAL]","motcnt");
89  mot.cnt = atoi(input);
90  mot.arr = NULL;
91  mot.desc = getMotDesc(mot.cnt);
92  return mot;
93 }
94 
95 
96 
98  char input[256];
99  TKatSCT katsct;
100  _readEntry(input,sizeof(input),"[KATANA]","[GENERAL]","sctcnt");
101  katsct.cnt = atoi(input);
102  katsct.arr = NULL;
103  katsct.desc = getSctDesc(katsct.cnt);
104  return katsct;
105 }
106 
108  char input[256];
109  _readEntry(input,sizeof(input),"[KATANA]","[GENERAL]","type");
110  return atoi(input);
111 }
112 
114  char input [256];
115  _readEntry(input,sizeof(input),"[KATANA]","[GENERAL]","kinematics");
116  if(!strcmp("Analytical", input))
117  return 0;
118  if(!strcmp("RobAnaGuess", input))
119  return 1;
120  //default: RobAnaGuess
121  return 1;
122 }
123 
124 
126  char input[256];
127  TKatEFF eff;
128  _readEntry(input,sizeof(input),"[ENDEFFECTOR]","[GENERAL]","segment1");
129  eff.arr_segment[0] = atof(input) ;
130  _readEntry(input,sizeof(input),"[ENDEFFECTOR]","[GENERAL]","segment2");
131  eff.arr_segment[1] = atof(input) ;
132  _readEntry(input,sizeof(input),"[ENDEFFECTOR]","[GENERAL]","segment3");
133  eff.arr_segment[2] = atof(input) ;
134  _readEntry(input,sizeof(input),"[ENDEFFECTOR]","[GENERAL]","segment4");
135  eff.arr_segment[3] = atof(input) ;
136  return eff;
137 }
138 
139 
140 
142  char input[256];
143  char section[256];
144 
145  TMotDesc* motdesc = new TMotDesc[count];
146  for(int i = 0; i < count; ++i) {
147  memset(section,0,sizeof(section));
148  sprintf(section,"[MOT[%d]]",i);
149  _readEntry(input,sizeof(input),section,"[GENERAL]","slvID");
150  motdesc[i].slvID = atoi(input);
151  }
152  return motdesc;
153 }
154 
156  char input[256];
157  char section[256];
158 
159  TSctDesc* sctdesc = new TSctDesc[count];
160 
161  for(int i = 0; i < count; ++i) {
162  memset(section,0,sizeof(section));
163  sprintf(section,"[SCT[%d]]", i);
164  _readEntry(input,sizeof(input),section,"[GENERAL]","ctrlID");
165  sctdesc[i].ctrlID = atoi(input);
166  _readEntry(input,sizeof(input),section,"[GENERAL]","sens_res");
167  sctdesc[i].sens_res = atoi(input);
168  _readEntry(input,sizeof(input),section,"[GENERAL]","sens_count");
169  sctdesc[i].sens_count = atoi(input);
170  }
171  return sctdesc;
172 }
173 
174 
176  char input[256];
177  char section[256];
178 
179  TMotCLB clb;
180 
181  memset(section,0,sizeof(section));
182  sprintf(section,"[MOT[%d]]", number);
183 
184  _readEntry(input,sizeof(input),section,"[CALIBRATION]","enable");
185  clb.enable = strcmp("TRUE",input) ? false : true;
186 
187  _readEntry(input,sizeof(input),section,"[CALIBRATION]","order");
188  clb.order = atoi(input);
189 
190  _readEntry(input,sizeof(input),section,"[CALIBRATION]","dir");
191  clb.dir = strcmp("DIR_POSITIVE",input) ? DIR_NEGATIVE : DIR_POSITIVE;
192 
193  //_readEntry(input,sizeof(input),section,"[CALIBRATION]","diff");
194  //clbarr[i].diff = atoi(input);
195 
196  _readEntry(input,sizeof(input),section,"[CALIBRATION]","mcf");
197  if(!strcmp("MCF_OFF", input))
198  clb.mcf = MCF_OFF;
199  if(!strcmp("MCF_ON", input))
200  clb.mcf = MCF_ON;
201  if(!strcmp("MCF_FREEZE",input))
202  clb.mcf = MCF_FREEZE;
203 
204  //_readEntry(input,sizeof(input),section,"[CALIBRATION]","timeout");
205  //clbarr[i].timeout = strcmp("TM_ENDLESS", input) ? atoi(input) : TM_ENDLESS;
206 
207 
208  //_readEntry(input,sizeof(input),section,"[CALIBRATION]","enc_tolerance");
209  //clbarr[i].enc_tolerance = atoi(input);
210 
211  _readEntry(input,sizeof(input),section,"[CALIBRATION]","encoderPositionAfter");
212  clb.encoderPositionAfter = atoi(input);
213 
214  return clb;
215 }
216 
218  TMotSCP scp;
219  char input[256];
220  char section[256];
221 
222 
223  memset(section,0,sizeof(section));
224  sprintf(section,"[MOT[%d]]", number);
225 
226  _readEntry(input,sizeof(input),section,"[STATIC]","maxppwm");
227  scp.maxppwm = atoi(input);
228 
229  _readEntry(input,sizeof(input),section,"[STATIC]","maxnpwm");
230  scp.maxnpwm = atoi(input);
231 
232  _readEntry(input,sizeof(input),section,"[STATIC]","kP");
233  scp.kP = atoi(input);
234 
235  _readEntry(input,sizeof(input),section,"[STATIC]","kI");
236  scp.kI = atoi(input);
237 
238  _readEntry(input,sizeof(input),section,"[STATIC]","kD");
239  scp.kD = atoi(input);
240 
241  _readEntry(input,sizeof(input),section,"[STATIC]","kARW");
242  scp.kARW = atoi(input);
243 
244  _readEntry(input,sizeof(input),section,"[STATIC]","kP_speed");
245  scp.kP_speed = atoi(input);
246 
247  _readEntry(input,sizeof(input),section,"[STATIC]","kI_speed");
248  scp.kI_speed = atoi(input);
249 
250  _readEntry(input,sizeof(input),section,"[STATIC]","kD_speed");
251  scp.kD_speed = atoi(input);
252 
253  _readEntry(input,sizeof(input),section,"[STATIC]","maxppwm_nmp");
254  scp.maxppwm_nmp = atoi(input);
255 
256  _readEntry(input,sizeof(input),section,"[STATIC]","maxnpwm_nmp");
257  scp.maxnpwm_nmp = atoi(input);
258 
259  _readEntry(input,sizeof(input),section,"[STATIC]","kspeed_nmp");
260  scp.kspeed_nmp = atoi(input);
261 
262  _readEntry(input,sizeof(input),section,"[STATIC]","kpos_nmp");
263  scp.kpos_nmp = atoi(input);
264 
265  _readEntry(input,sizeof(input),section,"[STATIC]","kI_nmp");
266  scp.kI_nmp = atoi(input);
267 
268  _readEntry(input,sizeof(input),section,"[STATIC]","crash_limit_nmp");
269  scp.crash_limit_nmp = atoi(input);
270 
271  _readEntry(input,sizeof(input),section,"[STATIC]","crash_limit_lin_nmp");
272  scp.crash_limit_lin_nmp = atoi(input);
273 
274  return scp;
275 }
276 
278  TMotDYL dyl;
279  char input[256];
280  char section[256];
281 
282  memset(section,0,sizeof(section));
283  sprintf(section,"[MOT[%d]]", number);
284 
285  _readEntry(input,sizeof(input),section,"[DYNAMIC]","maxaccel");
286  dyl.maxaccel = atoi(input);
287 
288  _readEntry(input,sizeof(input),section,"[DYNAMIC]","maxdecel");
289  dyl.maxdecel = atoi(input);
290 
291  _readEntry(input,sizeof(input),section,"[DYNAMIC]","minpos");
292  dyl.minpos = atoi(input);
293 
294  _readEntry(input,sizeof(input),section,"[DYNAMIC]","maxpspeed");
295  dyl.maxpspeed = atoi(input);
296 
297  _readEntry(input,sizeof(input),section,"[DYNAMIC]","maxnspeed");
298  dyl.maxnspeed = atoi(input);
299 
300  _readEntry(input,sizeof(input),section,"[DYNAMIC]","maxcurr");
301  dyl.maxcurr = atoi(input);
302 
303  dyl.actcurr = 0;
304 
305  _readEntry(input,sizeof(input),section,"[DYNAMIC]","maxaccel_nmp");
306  dyl.maxaccel_nmp = atoi(input);
307 
308  _readEntry(input,sizeof(input),section,"[DYNAMIC]","maxpspeed_nmp");
309  dyl.maxpspeed_nmp = atoi(input);
310 
311  _readEntry(input,sizeof(input),section,"[DYNAMIC]","maxnspeed_nmp");
312  dyl.maxnspeed_nmp = atoi(input);
313 
314  _readEntry(input,sizeof(input),section,"[DYNAMIC]","maxcurr_nmp");
315  dyl.maxcurr_nmp = atoi(input);
316 
317  return dyl;
318 }
319 
320 
322  char input[256];
323  char section[256];
324  TMotInit init;
325  memset(section,0,sizeof(section));
326  sprintf(section,"[MOT[%d]]", number);
327 
328  _readEntry(input,sizeof(input),section,"[INIT]","encodersPerCycle");
329  init.encodersPerCycle = atoi(input);
330 
331  _readEntry(input,sizeof(input),section,"[INIT]","encoderOffset");
332  init.encoderOffset = atoi(input);
333 
334  _readEntry(input,sizeof(input),section,"[INIT]","rotationDirection");
335  init.rotationDirection = strcmp("DIR_POSITIVE",input) ? -1 : 1;
336 
337  _readEntry(input,sizeof(input),section,"[INIT]","angleOffset");
338  init.angleOffset = atof(input);
339 
340  _readEntry(input,sizeof(input),section,"[INIT]","angleRange");
341  init.angleRange = atof(input);
342 
343  return init;
344 }
345 
346 void
347 kmlFactory::getGripperParameters(bool& isPresent, int& openEncoders, int& closeEncoders) {
348  char input[256];
349 
350  _readEntry(input,sizeof(input),"[KATANA]","[GRIPPER]","isPresent");
351  isPresent = strcmp("YES",input) ? false : true;
352 
353  _readEntry(input,sizeof(input),"[KATANA]","[GRIPPER]","openEncoders");
354  openEncoders = atoi(input);
355 
356  _readEntry(input,sizeof(input),"[KATANA]","[GRIPPER]","closeEncoders");
357  closeEncoders = atoi(input);
358 }
359 
360 }
361 
TMotCmdFlg mcf
motor flag after calibration
Definition: kmlMotBase.h:187
byte actcurr
actual current
Definition: kmlMotBase.h:150
char modelName[255]
model name
Definition: kmlBase.h:69
int encoderPositionAfter
Definition: kmlMotBase.h:189
void _readEntry(char *dest, int destsz, const char *section, const char *subsection, const char *entry)
Definition: kmlFactories.cpp:8
byte maxppwm
max. val for pos. voltage
Definition: kmlMotBase.h:114
TMotSCP getMotSCP(short number)
byte kI_speed
Integral factor of the speed compensator.
Definition: kmlMotBase.h:122
double arr_segment[4]
length of the Katana segments
Definition: kmlBase.h:114
short sens_count
count of sensors
Definition: kmlSctBase.h:36
byte kD
derivate factor of pos comp
Definition: kmlMotBase.h:118
[SCT] every sens ctrl&#39;s attributes
Definition: kmlSctBase.h:41
bool enable
enable/disable
Definition: kmlMotBase.h:183
int encoderOffset
Definition: kmlMotBase.h:200
Initial motor parameters.
Definition: kmlMotBase.h:199
byte kI
not yet active
Definition: kmlMotBase.h:117
TMotDYL getMotDYL(short number)
int encodersPerCycle
Definition: kmlMotBase.h:201
byte ctrlID
controller number (ID)
Definition: kmlSctBase.h:34
TSctDesc * desc
description[]
Definition: kmlSctBase.h:44
byte kD_speed
Derivative factor of the speed compensator.
Definition: kmlMotBase.h:123
CMotBase * arr
array of motors
Definition: kmlMotBase.h:42
byte maxppwm_nmp
Max. value for positive voltage (0 => 0%, +70 => 100%)
Definition: kmlMotBase.h:127
std::ifstream _configfile
Definition: kmlFactories.h:80
byte kARW
not yet active
Definition: kmlMotBase.h:119
TMotCLB getMotCLB(short number)
short maxnspeed
max. allowed reverse speed; pos!
Definition: kmlMotBase.h:146
TMotDesc * getMotDesc(short count)
byte maxnpwm
max. val for neg. voltage; pos!
Definition: kmlMotBase.h:115
byte maxcurr
max current
Definition: kmlMotBase.h:149
int crash_limit_lin_nmp
Limit of error in position in linear movement.
Definition: kmlMotBase.h:133
[DYL] dynamic limits
Definition: kmlMotBase.h:138
Calibration structure for single motors.
Definition: kmlMotBase.h:182
Inverse Kinematics structure of the endeffektor.
Definition: kmlBase.h:113
[MOT] every motor&#39;s attributes
Definition: kmlMotBase.h:40
search direction for the meachanical stopper
Definition: kmlMotBase.h:70
byte adr
jumper adress
Definition: kmlBase.h:68
byte kI_nmp
Integral factor (1/kI) of control output added to the final control output.
Definition: kmlMotBase.h:131
int rotationDirection
Definition: kmlMotBase.h:204
short maxpspeed
max. allowed forward speed
Definition: kmlMotBase.h:145
TMotInit getMotInit(short number)
short minpos
not yet active
Definition: kmlMotBase.h:144
double angleRange
Definition: kmlMotBase.h:203
sensor controller description (partly)
Definition: kmlSctBase.h:33
CSctBase * arr
array of sens ctrl&#39;s
Definition: kmlSctBase.h:43
[SCP] static controller parameters
Definition: kmlMotBase.h:110
TMotDesc * desc
description[]
Definition: kmlMotBase.h:43
TKatGNL getGNL()
byte slvID
slave number
Definition: kmlMotBase.h:35
byte maxcurr_nmp
set the maximal current
Definition: kmlMotBase.h:157
double angleOffset
Definition: kmlMotBase.h:202
void getGripperParameters(bool &isPresent, int &openEncoders, int &closeEncoders)
int crash_limit_nmp
Limit of error in position.
Definition: kmlMotBase.h:132
short order
order in which this motor will be calibrated. range: 0..5
Definition: kmlMotBase.h:184
[GNL] general robot attributes
Definition: kmlBase.h:67
TSearchDir dir
search direction for mech. stopper
Definition: kmlMotBase.h:186
byte kP_speed
Proportional factor of the speed compensator.
Definition: kmlMotBase.h:121
short cnt
count of motors
Definition: kmlMotBase.h:41
set the motor on
Definition: kmlMotBase.h:52
motor description (partly)
Definition: kmlMotBase.h:34
byte maxdecel
max deceleration
Definition: kmlMotBase.h:143
TKatMOT getMOT()
TSctDesc * getSctDesc(short count)
short sens_res
resolution: 8/12 bit
Definition: kmlSctBase.h:35
byte maxaccel_nmp
Maximal acceleration and deceleration.
Definition: kmlMotBase.h:154
byte maxaccel
max acceleration
Definition: kmlMotBase.h:142
freeze the motor
Definition: kmlMotBase.h:51
byte maxnpwm_nmp
Max. value for negative voltage (0 => 0%, +70 => 100%)
Definition: kmlMotBase.h:128
byte kP
prop. factor of pos comp
Definition: kmlMotBase.h:116
short maxpspeed_nmp
Max. allowed forward speed.
Definition: kmlMotBase.h:155
byte kpos_nmp
Proportional factor of position compensator.
Definition: kmlMotBase.h:130
short maxnspeed_nmp
Max. allowed reverse speed.
Definition: kmlMotBase.h:156
byte kspeed_nmp
Proportional factor of speed compensator.
Definition: kmlMotBase.h:129
set the motor off
Definition: kmlMotBase.h:49
TKatSCT getSCT()
short cnt
count of sens ctrl&#39;s
Definition: kmlSctBase.h:42
Definition: Timer.h:30


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