Tracker_Calibration_impl.cc
Go to the documentation of this file.
1 
18 /* system includes */
19 #include <qwidget.h>
20 #include <qpushbutton.h>
21 #include <qlineedit.h>
22 #include <qtextbrowser.h>
23 #include <qprogressbar.h>
24 #include <qmessagebox.h>
25 #include <qfiledialog.h>
26 #include <qpixmap.h>
27 #include <qlabel.h>
28 #include <qdialog.h>
29 #include <qtable.h>
30 #include <qcheckbox.h>
31 
32 #include <sstream>
33 
34 /* my includes */
35 #include "qt_editdata_impl.h"
36 #include "qt_calibration.uic.h"
38 
39 #define DIEonERR(x) if (x < 0) {printf("Fehler %u in %s:%u Datenbankbefehl\n",x,__FILE__,__LINE__);}
40 
41 
43 {
44  trackLeft=false;
45  trackRight=false;
46  fcountLeft=0;
47  fcountRight=0;
50  pushButton10->setEnabled(false);
51  logBrowser->clear();
52  logBrowser->append("Started tracker calibration.\n");
53 }
54 
56 {
57  closeDevice();
58 }
59 
60 void
62 { std::stringstream s;
63  s << "World coordinates: " << (coordCountLeft+coordCountRight) << " Tracker coordinates: " << (fcountLeft+fcountRight);
64  textFulcrumCount->setText(s.str().c_str());
65 }
66 
67 
68 void
70 
71 
72  std::string serverNameLeft((trackerName->text()).latin1());
73  std::string serverNameRight((trackerName_2->text()).latin1());
74 
75  trackLeft = (Use_Left_Tracker->isChecked());
76  trackRight= (Use_Right_Tracker->isChecked());
77 
78  openDevice(serverNameLeft, serverNameRight);
79 
80 
81  if(!(trackLeft|trackRight)){
82  QMessageBox::critical(this, "TrackerCalibration", "Could not connect to any tracker server.", "OK");
83  logBrowser->append("Could not connect to any tracker server.\n");
84  connectedLabel->setText("Not connected");
85  connectedLabel->setPaletteForegroundColor(QColor("red"));
86  buttonConnectToTracker->setDefault(true);
87  }
88  else{
89  std::stringstream s;
90  if (trackLeft) s << "Connected to left server " << trackerName->text() << "\n";
91  if (trackRight) s << "Connected to right server " << trackerName->text() << "\n";
92  logBrowser->append(s.str().c_str());
93  if (trackLeft&trackRight) connectedLabel->setText("Both connected"); else
94  if (trackLeft) connectedLabel->setText("Left connected"); else
95  connectedLabel->setText("Right connected");
96  connectedLabel->setPaletteForegroundColor(QColor("green"));
97  pushButton14->setDefault(true);
98  }
99  logBrowser->scrollToBottom();
100 }
101 
102 
103 int Tracker_Calibration_impl::openDevice(std::string &trackLeftId, std::string &trackRightId) {
104  int err;
105  std::string temp;
106 
107  /* establish database connection
108  * the cycle time is 0,03s this means this client does not ask for new data more than 30 times per second,
109  * this has to be measured or estimated! The database stalls read until this delay is met! */
110  err = kogmo_rtdb_connect_initinfo (&dbinfo, "", "TrackerCalibrationClient", 0.03); DIEonERR(err);
111  oidLeft = kogmo_rtdb_connect (&dbc, &dbinfo); DIEonERR(oidLeft);
112 
113  //search for our objecttype. Wait until it is registered
114 
115  if (trackLeft){
116 
117  temp = trackLeftId + "_raw";
118  oidLeft = kogmo_rtdb_obj_searchinfo_wait (dbc, temp.c_str(), KOGMO_RTDB_OBJTYPE_E1_FOBTRACKER_RAW, 0, 0); DIEonERR(oidLeft);
119  if (err <0)
120  trackLeft=false;
121  err = kogmo_rtdb_obj_readinfo (dbc, oidLeft, 0, &dataobj_left_info); DIEonERR(err);
122  if (err <0)
123  trackLeft=false;
124 
125  dataobj_left = (kogmo_rtdb_obj_e1_fobtracker_t *) malloc(dataobj_left_info.size_max);
126  err = kogmo_rtdb_obj_initdata (dbc, &dataobj_left_info, dataobj_left); DIEonERR(err);
127  if (err <0)
128  trackLeft=false;
129 
130  }
131  if (trackRight) {
132  temp = trackRightId + "_raw";
133  oidRight = kogmo_rtdb_obj_searchinfo_wait (dbc, temp.c_str(), KOGMO_RTDB_OBJTYPE_E1_FOBTRACKER_RAW, 0, 0); DIEonERR(oidRight);
134  if (err <0)
135  trackRight=false;
136  err = kogmo_rtdb_obj_readinfo (dbc, oidRight, 0, &dataobj_right_info);
137  if (err <0)
138  trackRight=false;
139  dataobj_right = (kogmo_rtdb_obj_e1_fobtracker_t *) malloc(dataobj_right_info.size_max);
140  err = kogmo_rtdb_obj_initdata (dbc, &dataobj_right_info, dataobj_right);
141  if (err <0)
142  trackRight=false;
143  }
144 
145  return 0;
146 }
147 
148 
149 /*
150  * close the db connection
151  */
153  signed int err;
154  err = kogmo_rtdb_obj_delete (dbc, &dataobj_left_info); DIEonERR(err);
155  err = kogmo_rtdb_obj_delete (dbc, &dataobj_right_info); DIEonERR(err);
156  err = kogmo_rtdb_disconnect(dbc, NULL); DIEonERR(err);
157  free(dataobj_left);
158  free(dataobj_right);
159  return 0;
160 }
161 
162 
163 bool
165 
166  std::stringstream s;
167  s << "Calibration data:\n";
168  for (unsigned int i=0; i<cal.size(); i++){
169 
170  for (unsigned int j=0; j<cal[i].size(); j++){
171  s << (cal[i])[j].first << ":" << (cal[i])[j].second;
172  if(j < cal[i].size()-1)
173  s << " ";
174  else
175  s << "\n";
176  }
177  }
178  logBrowser->append(s.str().c_str());
179  logBrowser->scrollToBottom();
180 
181  return true;
182 }
183 
184 
185 void
187 
188  QString qfile = QFileDialog::getSaveFileName(QString::null,
189  "Tracker calibrations (*.calib)",
190  this,
191  "save file dialog",
192  "Choose a filename to save under" );
193 
194  bool res;
195  std::string filename;
196  std::stringstream s;
197 
198  if(qfile != NULL){
199  filename = std::string(qfile.latin1());
200  FILE *f;
201  res = ((f=fopen(filename.c_str(), "w"))!=NULL);
202  if (res)
203  {
204  printf("fcountLeft:%i, fcountRight:%i\n",fcountLeft,fcountRight);
205  fwrite(&fcountLeft,sizeof(fcountLeft),1,f);
206  fwrite(&fcountRight,sizeof(fcountRight),1,f);
207  printf("fulcrumyArrayLeft(%i):\n",fcountRight);
208  for(int i=0;i < fcountRight;i++) {
209  printf("\nentry %i:\n",i);
211  }
212  printf("fulcrumyArrayRight(%i):\n",fcountLeft);
213  for(int i=0;i < fcountRight;i++) {
214  printf("\nentry %i:\n",i);
216  }
217  fwrite(&fulcrumarrayLeft,sizeof(fulcrumarrayLeft[0]),fcountLeft,f);
218  fwrite(&fulcrumarrayRight,sizeof(fulcrumarrayRight[0]),fcountRight,f);
219  s << "Saved " << (fcountLeft+fcountRight) << " fulcrums\n";
220  fclose(f);
221  }
222  }
223  else
224  res = false;
225 
226  if(res)
227  s << "Saved data to file " << filename << "\n";
228  else
229  s << "File " << filename << " not saved.\n";
230  logBrowser->append(s.str().c_str());
231  logBrowser->scrollToBottom();
232 }
233 
235  printf("sensorVal: %3.3f, %3.3f, %3.3f\n",fulc.sensorVal[0] ,fulc.sensorVal[1], fulc.sensorVal[2]);
236  printf("sensorAngle: %3.3f, %3.3f, %3.3f\n",fulc.sensorAngle[0] ,fulc.sensorAngle[1], fulc.sensorAngle[2]);
237  printf("worldVal: %3.3f, %3.3f, %3.3f\n",fulc.worldVal[0] ,fulc.worldVal[1], fulc.worldVal[2]);
238  printf("worldAngle: %3.3f, %3.3f, %3.3f\n",fulc.worldAngle[0] ,fulc.worldAngle[1], fulc.worldAngle[2]);
239  }
240 
241 void
243 
244  QString qfile = QFileDialog::getOpenFileName(QString::null,
245  "Tracker calibrations (*.calib)",
246  this,
247  "open file dialog",
248  "Choose a file to open" );
249 
250  bool res;
251  std::string filename;
252  std::stringstream s;
253 
254  if(qfile != NULL){
255  filename = std::string(qfile.latin1());
256  FILE *f;
257  res = ((f=fopen(filename.c_str(), "r"))!=NULL);
258  if (res)
259  {
260  fread(&fcountLeft,sizeof(fcountLeft),1,f);
261  fread(&fcountRight,sizeof(fcountRight),1,f);
262 
263  printf("fcountLeft:%i, fcountRight:%i\n",fcountLeft,fcountRight);
264 
265  fread(&fulcrumarrayLeft,sizeof(fulcrumarrayLeft[0]),fcountLeft,f);
266  fread(&fulcrumarrayRight,sizeof(fulcrumarrayRight[0]),fcountRight,f);
267 
268  printf("fulcrumyArrayLeft(%i):\n",fcountRight);
269  for(int i=0;i < fcountRight;i++) {
270  printf("\nentry %i:\n",i);
272  }
273  printf("fulcrumyArrayRight(%i):\n",fcountLeft);
274  for(int i=0;i < fcountRight;i++) {
275  printf("\nentry %i:\n",i);
277  }
278 
279  s << "Loaded " << (fcountLeft+fcountRight) << " fulcrums\n";
280  fclose(f);
283  }
284  }
285  else
286  res = false;
287 
288  if(res){
289  s << "Loaded data from file " << filename << "\n";
290  }
291  else
292  s << "File " << filename << " not opened.\n";
293  logBrowser->append(s.str().c_str());
294  logBrowser->scrollToBottom();
295  updateCounter();
296 }
297 
298 
299 void
301 {
302  loadSlot();
303  fcountLeft=0;
304  fcountRight=0;
305  if (coordCountLeft>0)
306  {
307  std::stringstream xl,yl,zl;
309  WorldX->setText(xl.str().c_str());
311  WorldY->setText(yl.str().c_str());
313  WorldZ->setText(zl.str().c_str());
314  }
315  if (coordCountRight>0)
316  {
317  std::stringstream xr,yr,zr;
319  WorldX_2->setText(xr.str().c_str());
321  WorldY_2->setText(yr.str().c_str());
323  WorldZ_2->setText(zr.str().c_str());
324  }
325  updateCounter();
326 }
327 
328 void
330 { int l=fcountLeft;
331  int r=fcountRight;
334  saveSlot();
335  fcountLeft=l;
336  fcountRight=r;
337 }
338 
339 
340 void
342 
343  QMessageBox::about(this,
344  "TrackerCalibration",
345  "If you really need some help, there should be a readme file in your Tracker Calibration directory.");
346  BGDBG(0, "See readme file for help\n");
347 }
348 
349 
350 void
352 {
353  int err;
354 
355  Tracker_Calibration_impl::fulcrum fLeft, fRight;
356  std::stringstream s;
357 
358  //read object from database
359  err = kogmo_rtdb_obj_readdata (dbc, oidLeft, 0, dataobj_left, dataobj_left_info.size_max);
360  if (err <0)
361  logBrowser->append("Left tracker server dead? Could not connect.\n");
362  err = kogmo_rtdb_obj_readdata (dbc, oidRight, 0, dataobj_right, dataobj_right_info.size_max);
363  if (err <0)
364  logBrowser->append("RightTracker server dead? Could not connect.\n");
365 
366 
367  if (trackLeft)
368  {
369  fLeft.sensorVal[0]=dataobj_left->data.data[0];
370  fLeft.sensorVal[1]=dataobj_left->data.data[1];
371  fLeft.sensorVal[2]=dataobj_left->data.data[2];
372  fLeft.worldVal[0]=strtod(WorldX->text(),NULL);
373  fLeft.worldVal[1]=strtod(WorldY->text(),NULL);
374  fLeft.worldVal[2]=strtod(WorldZ->text(),NULL);
375  fulcrumarrayLeft[fcountLeft++]=fLeft;
377  {
378  std::stringstream x,y,z;
379  x << fulcrumarrayLeft[fcountLeft].worldVal[0];
380  WorldX->setText(x.str().c_str());
381  y << fulcrumarrayLeft[fcountLeft].worldVal[1];
382  WorldY->setText(y.str().c_str());
383  z << fulcrumarrayLeft[fcountLeft].worldVal[2];
384  WorldZ->setText(z.str().c_str());
385  }
386  }
387  if (trackRight)
388  {
389  fRight.sensorVal[0]=dataobj_right->data.data[0];
390  fRight.sensorVal[1]=dataobj_right->data.data[1];
391  fRight.sensorVal[2]=dataobj_right->data.data[2];
392  fRight.worldVal[0]=strtod(WorldX_2->text(),NULL);
393  fRight.worldVal[1]=strtod(WorldY_2->text(),NULL);
394  fRight.worldVal[2]=strtod(WorldZ_2->text(),NULL);
395  fulcrumarrayRight[fcountRight++]=fRight;
397  {
398  std::stringstream x,y,z;
399  x << fulcrumarrayRight[fcountRight].worldVal[0];
400  WorldX_2->setText(x.str().c_str());
401  y << fulcrumarrayRight[fcountRight].worldVal[1];
402  WorldY_2->setText(y.str().c_str());
403  z << fulcrumarrayRight[fcountRight].worldVal[2];
404  WorldZ_2->setText(z.str().c_str());
405  }
406  }
407  if (trackLeft)
408  {
409  s << "Left: ";
410  for (int i=0;i<3;i++)
411  s << fLeft.sensorVal[i] << " ";
412  }
413  if (trackRight)
414  {
415  s << "Right: ";
416  for (int i=0;i<3;i++)
417  s << fRight.sensorVal[i] << " ";
418  }
419  logBrowser->append(s.str().c_str());
420  updateCounter();
421 
422 }
423 
424 void
426 {
427  fcountLeft=0;
428  fcountRight=0;
429  if (coordCountLeft>0)
430  {
431  std::stringstream xl,yl,zl;
433  WorldX->setText(xl.str().c_str());
435  WorldY->setText(yl.str().c_str());
437  WorldZ->setText(zl.str().c_str());
438  }
439  if (coordCountRight>0)
440  {
441  std::stringstream xr,yr,zr;
443  WorldX_2->setText(xr.str().c_str());
445  WorldY_2->setText(yr.str().c_str());
447  WorldZ_2->setText(zr.str().c_str());
448  }
449  updateCounter();
450 }
451 
452 void
454 {
455  fcountLeft=0;
456  fcountRight=0;
457  coordCountLeft=0;
458  coordCountRight=0;
459  updateCounter();
460 }
461 
462 
463 
464  // we don'T use CORBA anymore so this is not working
465  // calibration is done as usual, results are saved
466  // in a file which is loaded by trackerServer
467  // (haass)
468 void
470 {
471  /*
472  tracker::allSensorCal dataLeft,dataRight;
473  std::stringstream s;
474  s << "Sent " << fcountLeft << " fulcrums fo left\n";
475  for (int i = 0; i < fcountLeft; i++)
476  s << fulcrumarrayLeft[i].sensorVal[0] << " "
477  << fulcrumarrayLeft[i].sensorVal[1] << " "
478  << fulcrumarrayLeft[i].sensorVal[2] << " -> "
479  << fulcrumarrayLeft[i].worldVal[0] << " "
480  << fulcrumarrayLeft[i].worldVal[1] << " "
481  << fulcrumarrayLeft[i].worldVal[2] << "\n";
482 
483  s << "Sent " << fcountRight << " fulcrums fo right\n";
484  for (int i = 0; i < fcountRight; i++)
485  s << fulcrumarrayRight[i].sensorVal[0] << " "
486  << fulcrumarrayRight[i].sensorVal[1] << " "
487  << fulcrumarrayRight[i].sensorVal[2] << " -> "
488  << fulcrumarrayRight[i].worldVal[0] << " "
489  << fulcrumarrayRight[i].worldVal[1] << " "
490  << fulcrumarrayRight[i].worldVal[2] << "\n";
491 
492  if (trackLeft)
493  {
494  dataLeft.length(fcountLeft);
495  for (int i=0;i<fcountLeft;i++)
496  dataLeft[i]=fulcrumarrayLeft[i];
497  myCalLeft->myTracker->loadCalibration(dataLeft);
498  }
499  if (trackRight)
500  {
501  dataRight.length(fcountRight);
502  for (int i=0;i<fcountRight;i++)
503  dataRight[i]=fulcrumarrayRight[i];
504  myCalRight->myTracker->loadCalibration(dataRight);
505  }
506  logBrowser->append(s.str().c_str());
507  */
508 }
509 
510 
511 #if Tracker_Calibration_test
512 #include <stdio.h>
513 int main(int argc, char **argv)
514 {
515  // This is a module-test block. You can put code here that tests
516  // just the contents of this C file, and build it by saying
517  // make Tracker_Calibration_test
518  // Then, run the resulting executable (Tracker_Calibration_test).
519  // If it works as expected, the module is probably correct. ;-)
520 
521  fprintf(stderr, "For testing simply run the application\n");
522 
523  return 0;
524 }
525 #endif /* Tracker_Calibration_test */
filename
f
kogmo_rtdb_obj_e1_fobtracker_t * dataobj_right
int main(int argc, char **argv)
XmlRpcServer s
#define DIEonERR(x)
kogmo_rtdb_obj_info_t dataobj_left_info
TFSIMD_FORCE_INLINE const tfScalar & y() const
std::vector< sensorCal > trackerCal
kogmo_rtdb_connect_info_t dbinfo
kogmo_rtdb_obj_e1_fobtracker_t * dataobj_left
TFSIMD_FORCE_INLINE const tfScalar & x() const
double l
TFSIMD_FORCE_INLINE const tfScalar & z() const
int openDevice(std::string &trackLeftId, std::string &trackRightId)
kogmo_rtdb_obj_info_t dataobj_right_info


asr_flock_of_birds
Author(s): Bernhardt Andre, Engelmann Stephan, Giesler Björn, Heller Florian, Jäkel Rainer, Nguyen Trung, Pardowitz Michael, Weckesser Peter, Yi Xie, Zöllner Raoul
autogenerated on Mon Jun 10 2019 12:44:40