Tracker_Calibration_impl.cc
Go to the documentation of this file.
00001 
00018 /* system includes */
00019 #include <qwidget.h>
00020 #include <qpushbutton.h>
00021 #include <qlineedit.h>
00022 #include <qtextbrowser.h>
00023 #include <qprogressbar.h>
00024 #include <qmessagebox.h>
00025 #include <qfiledialog.h>
00026 #include <qpixmap.h>
00027 #include <qlabel.h>
00028 #include <qdialog.h>
00029 #include <qtable.h>
00030 #include <qcheckbox.h>
00031 
00032 #include <sstream>
00033 
00034 /* my includes */
00035 #include "qt_editdata_impl.h"
00036 #include "qt_calibration.uic.h"
00037 #include "Tracker_Calibration_impl.h"
00038 
00039 #define DIEonERR(x) if (x < 0) {printf("Fehler %u in %s:%u Datenbankbefehl\n",x,__FILE__,__LINE__);}
00040 
00041 
00042 Tracker_Calibration_impl::Tracker_Calibration_impl()
00043 {
00044   trackLeft=false;
00045   trackRight=false;
00046   fcountLeft=0;
00047   fcountRight=0;
00048   coordCountLeft=0;
00049   coordCountRight=0;
00050   pushButton10->setEnabled(false);
00051   logBrowser->clear();
00052   logBrowser->append("Started tracker calibration.\n");
00053 }
00054 
00055 Tracker_Calibration_impl::~Tracker_Calibration_impl()
00056 {
00057   closeDevice();
00058 }
00059 
00060 void
00061 Tracker_Calibration_impl::updateCounter()
00062 {  std::stringstream s;
00063   s  << "World coordinates: " << (coordCountLeft+coordCountRight) << " Tracker coordinates: " << (fcountLeft+fcountRight);
00064   textFulcrumCount->setText(s.str().c_str());
00065 }
00066 
00067 
00068 void
00069 Tracker_Calibration_impl::connectSlot(){
00070 
00071   
00072   std::string serverNameLeft((trackerName->text()).latin1());
00073   std::string serverNameRight((trackerName_2->text()).latin1());
00074 
00075   trackLeft = (Use_Left_Tracker->isChecked());
00076   trackRight= (Use_Right_Tracker->isChecked());
00077 
00078   openDevice(serverNameLeft, serverNameRight);
00079 
00080 
00081   if(!(trackLeft|trackRight)){
00082     QMessageBox::critical(this, "TrackerCalibration", "Could not connect to any tracker server.", "OK");
00083     logBrowser->append("Could not connect to any tracker server.\n");
00084     connectedLabel->setText("Not connected");
00085     connectedLabel->setPaletteForegroundColor(QColor("red"));
00086     buttonConnectToTracker->setDefault(true);
00087   }
00088   else{
00089     std::stringstream s;
00090     if (trackLeft) s << "Connected to left server " << trackerName->text() << "\n";
00091     if (trackRight) s << "Connected to right server " << trackerName->text() << "\n";
00092     logBrowser->append(s.str().c_str());
00093     if (trackLeft&trackRight) connectedLabel->setText("Both connected"); else
00094       if (trackLeft) connectedLabel->setText("Left connected"); else
00095         connectedLabel->setText("Right connected");
00096     connectedLabel->setPaletteForegroundColor(QColor("green"));
00097     pushButton14->setDefault(true);
00098   }
00099   logBrowser->scrollToBottom();
00100 }
00101 
00102 
00103 int Tracker_Calibration_impl::openDevice(std::string &trackLeftId, std::string &trackRightId) {
00104   int err;
00105     std::string temp;
00106     
00107   /* establish database connection
00108    * the cycle time is 0,03s this means this client does not ask for new data more than 30 times per second,
00109    * this has to be measured or estimated! The database stalls read until this delay is met! */
00110   err = kogmo_rtdb_connect_initinfo (&dbinfo, "", "TrackerCalibrationClient", 0.03); DIEonERR(err);
00111   oidLeft = kogmo_rtdb_connect (&dbc, &dbinfo); DIEonERR(oidLeft);
00112   
00113   //search for our objecttype. Wait until it is registered
00114   
00115   if (trackLeft){
00116 
00117     temp = trackLeftId + "_raw";
00118     oidLeft = kogmo_rtdb_obj_searchinfo_wait (dbc, temp.c_str(), KOGMO_RTDB_OBJTYPE_E1_FOBTRACKER_RAW, 0, 0);  DIEonERR(oidLeft);
00119     if (err <0) 
00120       trackLeft=false;
00121     err = kogmo_rtdb_obj_readinfo (dbc, oidLeft, 0, &dataobj_left_info); DIEonERR(err);
00122     if (err <0) 
00123       trackLeft=false;
00124         
00125     dataobj_left = (kogmo_rtdb_obj_e1_fobtracker_t *) malloc(dataobj_left_info.size_max);
00126     err = kogmo_rtdb_obj_initdata (dbc, &dataobj_left_info, dataobj_left); DIEonERR(err);
00127     if (err <0) 
00128       trackLeft=false;
00129 
00130   }
00131   if (trackRight) {
00132     temp = trackRightId + "_raw";
00133     oidRight = kogmo_rtdb_obj_searchinfo_wait (dbc, temp.c_str(), KOGMO_RTDB_OBJTYPE_E1_FOBTRACKER_RAW, 0, 0);  DIEonERR(oidRight);
00134     if (err <0) 
00135       trackRight=false;
00136     err = kogmo_rtdb_obj_readinfo (dbc, oidRight, 0, &dataobj_right_info);
00137     if (err <0) 
00138       trackRight=false;
00139     dataobj_right = (kogmo_rtdb_obj_e1_fobtracker_t *) malloc(dataobj_right_info.size_max);
00140     err = kogmo_rtdb_obj_initdata (dbc, &dataobj_right_info, dataobj_right);
00141     if (err <0) 
00142       trackRight=false;
00143   }
00144 
00145   return 0;
00146 }
00147 
00148 
00149 /*
00150  * close the db connection
00151  */
00152 int Tracker_Calibration_impl::closeDevice(){
00153   signed int err;
00154   err = kogmo_rtdb_obj_delete (dbc, &dataobj_left_info); DIEonERR(err);
00155   err = kogmo_rtdb_obj_delete (dbc, &dataobj_right_info); DIEonERR(err);
00156   err = kogmo_rtdb_disconnect(dbc, NULL); DIEonERR(err);
00157   free(dataobj_left);
00158   free(dataobj_right);
00159   return 0;
00160 }
00161 
00162 
00163 bool
00164 Tracker_Calibration_impl::displayCal(trackerCal cal){
00165 
00166   std::stringstream s;
00167   s << "Calibration data:\n";
00168   for (unsigned int i=0; i<cal.size(); i++){
00169     
00170     for (unsigned int j=0; j<cal[i].size(); j++){
00171       s << (cal[i])[j].first << ":" << (cal[i])[j].second;
00172       if(j < cal[i].size()-1)
00173         s << " ";
00174       else
00175         s << "\n";
00176     }
00177   }
00178   logBrowser->append(s.str().c_str());
00179   logBrowser->scrollToBottom();
00180   
00181   return true;
00182 }
00183 
00184 
00185 void
00186 Tracker_Calibration_impl::saveSlot(){
00187 
00188   QString qfile = QFileDialog::getSaveFileName(QString::null,
00189                                                "Tracker calibrations (*.calib)",
00190                                                this,
00191                                                "save file dialog",
00192                                                "Choose a filename to save under" );
00193 
00194   bool res;
00195   std::string filename;
00196   std::stringstream s;
00197   
00198   if(qfile != NULL){
00199     filename = std::string(qfile.latin1());
00200     FILE *f;
00201     res = ((f=fopen(filename.c_str(), "w"))!=NULL);
00202     if (res)
00203       {
00204         printf("fcountLeft:%i, fcountRight:%i\n",fcountLeft,fcountRight);
00205         fwrite(&fcountLeft,sizeof(fcountLeft),1,f);
00206         fwrite(&fcountRight,sizeof(fcountRight),1,f);
00207         printf("fulcrumyArrayLeft(%i):\n",fcountRight);
00208         for(int i=0;i < fcountRight;i++) {
00209           printf("\nentry %i:\n",i);
00210           printFulcrum(fulcrumarrayLeft[i]);
00211         }
00212         printf("fulcrumyArrayRight(%i):\n",fcountLeft);
00213         for(int i=0;i < fcountRight;i++) {
00214           printf("\nentry %i:\n",i);
00215           printFulcrum(fulcrumarrayRight[i]);
00216         }
00217         fwrite(&fulcrumarrayLeft,sizeof(fulcrumarrayLeft[0]),fcountLeft,f);
00218         fwrite(&fulcrumarrayRight,sizeof(fulcrumarrayRight[0]),fcountRight,f);
00219         s << "Saved " << (fcountLeft+fcountRight) << " fulcrums\n";
00220         fclose(f);
00221       }
00222   }
00223   else
00224     res = false;
00225   
00226   if(res)
00227     s  << "Saved data to file " << filename << "\n";
00228   else
00229     s << "File " << filename << " not saved.\n";
00230   logBrowser->append(s.str().c_str());
00231   logBrowser->scrollToBottom();
00232 }
00233 
00234   void Tracker_Calibration_impl::printFulcrum(fulcrum fulc) {
00235     printf("sensorVal: %3.3f, %3.3f, %3.3f\n",fulc.sensorVal[0] ,fulc.sensorVal[1], fulc.sensorVal[2]);
00236     printf("sensorAngle: %3.3f, %3.3f, %3.3f\n",fulc.sensorAngle[0] ,fulc.sensorAngle[1], fulc.sensorAngle[2]);
00237     printf("worldVal: %3.3f, %3.3f, %3.3f\n",fulc.worldVal[0] ,fulc.worldVal[1], fulc.worldVal[2]);
00238     printf("worldAngle: %3.3f, %3.3f, %3.3f\n",fulc.worldAngle[0] ,fulc.worldAngle[1], fulc.worldAngle[2]);
00239   }
00240   
00241 void
00242 Tracker_Calibration_impl::loadSlot(){
00243 
00244   QString qfile = QFileDialog::getOpenFileName(QString::null,
00245                                                "Tracker calibrations (*.calib)",
00246                                                this,
00247                                                "open file dialog",
00248                                                "Choose a file to open" );
00249 
00250   bool res;
00251   std::string filename;
00252   std::stringstream s;
00253   
00254   if(qfile != NULL){
00255     filename = std::string(qfile.latin1());
00256     FILE *f;
00257     res = ((f=fopen(filename.c_str(), "r"))!=NULL);
00258     if (res)
00259       {
00260         fread(&fcountLeft,sizeof(fcountLeft),1,f);
00261         fread(&fcountRight,sizeof(fcountRight),1,f);
00262 
00263         printf("fcountLeft:%i, fcountRight:%i\n",fcountLeft,fcountRight);
00264 
00265         fread(&fulcrumarrayLeft,sizeof(fulcrumarrayLeft[0]),fcountLeft,f);
00266         fread(&fulcrumarrayRight,sizeof(fulcrumarrayRight[0]),fcountRight,f);
00267 
00268         printf("fulcrumyArrayLeft(%i):\n",fcountRight);
00269         for(int i=0;i < fcountRight;i++) {
00270           printf("\nentry %i:\n",i);
00271           printFulcrum(fulcrumarrayLeft[i]);
00272         }
00273         printf("fulcrumyArrayRight(%i):\n",fcountLeft);
00274         for(int i=0;i < fcountRight;i++) {
00275           printf("\nentry %i:\n",i);
00276           printFulcrum(fulcrumarrayRight[i]);
00277         }
00278 
00279         s << "Loaded " << (fcountLeft+fcountRight) << " fulcrums\n";
00280         fclose(f);
00281         coordCountLeft=fcountLeft;
00282         coordCountRight=fcountRight;
00283       }
00284   }
00285   else
00286     res = false;
00287   
00288   if(res){
00289     s  << "Loaded data from file " << filename << "\n";
00290   }
00291   else
00292     s << "File " << filename << " not opened.\n";
00293   logBrowser->append(s.str().c_str());
00294   logBrowser->scrollToBottom();
00295   updateCounter();
00296 }
00297 
00298 
00299 void
00300 Tracker_Calibration_impl::loadCoord()
00301 {
00302   loadSlot();
00303   fcountLeft=0;
00304   fcountRight=0;
00305   if (coordCountLeft>0)
00306     {
00307       std::stringstream xl,yl,zl;
00308       xl << fulcrumarrayLeft[fcountLeft].worldVal[0];
00309       WorldX->setText(xl.str().c_str());
00310       yl << fulcrumarrayLeft[fcountLeft].worldVal[1];
00311       WorldY->setText(yl.str().c_str());
00312       zl << fulcrumarrayLeft[fcountLeft].worldVal[2];
00313       WorldZ->setText(zl.str().c_str());
00314     }
00315   if (coordCountRight>0)
00316     {
00317       std::stringstream xr,yr,zr;
00318       xr << fulcrumarrayRight[fcountRight].worldVal[0];
00319       WorldX_2->setText(xr.str().c_str());
00320       yr << fulcrumarrayRight[fcountRight].worldVal[1];
00321       WorldY_2->setText(yr.str().c_str());
00322       zr << fulcrumarrayRight[fcountRight].worldVal[2];
00323       WorldZ_2->setText(zr.str().c_str());
00324     }
00325   updateCounter();
00326 }
00327 
00328 void
00329 Tracker_Calibration_impl::saveCoord()
00330 { int l=fcountLeft;
00331   int r=fcountRight;
00332   fcountLeft=coordCountLeft;
00333   fcountRight=coordCountRight;
00334   saveSlot();
00335   fcountLeft=l;
00336   fcountRight=r;
00337 }
00338 
00339 
00340 void
00341 Tracker_Calibration_impl::helpSlot(){
00342 
00343   QMessageBox::about(this,
00344                      "TrackerCalibration",
00345                      "If you really need some help, there should be a readme file in your Tracker Calibration directory.");
00346   BGDBG(0, "See readme file for help\n");
00347 }
00348 
00349 
00350 void
00351 Tracker_Calibration_impl::GetNAdd_clicked()
00352 {
00353   int err;
00354 
00355   Tracker_Calibration_impl::fulcrum fLeft, fRight;
00356   std::stringstream s;
00357 
00358   //read object from database
00359   err = kogmo_rtdb_obj_readdata (dbc, oidLeft, 0, dataobj_left, dataobj_left_info.size_max); 
00360   if (err <0)
00361         logBrowser->append("Left tracker server dead? Could not connect.\n");
00362   err = kogmo_rtdb_obj_readdata (dbc, oidRight, 0, dataobj_right, dataobj_right_info.size_max);
00363   if (err <0)
00364       logBrowser->append("RightTracker server dead? Could not connect.\n");
00365   
00366 
00367   if (trackLeft)
00368     {
00369       fLeft.sensorVal[0]=dataobj_left->data.data[0];
00370       fLeft.sensorVal[1]=dataobj_left->data.data[1];
00371       fLeft.sensorVal[2]=dataobj_left->data.data[2];
00372       fLeft.worldVal[0]=strtod(WorldX->text(),NULL);
00373       fLeft.worldVal[1]=strtod(WorldY->text(),NULL);
00374       fLeft.worldVal[2]=strtod(WorldZ->text(),NULL);
00375       fulcrumarrayLeft[fcountLeft++]=fLeft;
00376       if (fcountLeft>coordCountLeft) coordCountLeft++; else
00377         {
00378           std::stringstream x,y,z;
00379           x << fulcrumarrayLeft[fcountLeft].worldVal[0];
00380           WorldX->setText(x.str().c_str());
00381           y << fulcrumarrayLeft[fcountLeft].worldVal[1];
00382           WorldY->setText(y.str().c_str());
00383           z << fulcrumarrayLeft[fcountLeft].worldVal[2];
00384           WorldZ->setText(z.str().c_str());
00385         }
00386     }
00387   if (trackRight)
00388     {
00389       fRight.sensorVal[0]=dataobj_right->data.data[0];
00390       fRight.sensorVal[1]=dataobj_right->data.data[1];
00391       fRight.sensorVal[2]=dataobj_right->data.data[2];
00392       fRight.worldVal[0]=strtod(WorldX_2->text(),NULL);
00393       fRight.worldVal[1]=strtod(WorldY_2->text(),NULL);
00394       fRight.worldVal[2]=strtod(WorldZ_2->text(),NULL);
00395       fulcrumarrayRight[fcountRight++]=fRight;
00396       if (fcountRight>coordCountRight) coordCountRight++; else
00397         {
00398           std::stringstream x,y,z;
00399           x << fulcrumarrayRight[fcountRight].worldVal[0];
00400           WorldX_2->setText(x.str().c_str());
00401           y << fulcrumarrayRight[fcountRight].worldVal[1];
00402           WorldY_2->setText(y.str().c_str());
00403           z << fulcrumarrayRight[fcountRight].worldVal[2];
00404           WorldZ_2->setText(z.str().c_str());
00405         }
00406     }
00407   if (trackLeft)
00408     {
00409       s << "Left: ";
00410       for (int i=0;i<3;i++)
00411         s << fLeft.sensorVal[i] << " ";
00412     }
00413   if (trackRight)
00414     {
00415       s << "Right: ";
00416       for (int i=0;i<3;i++)
00417         s << fRight.sensorVal[i] << " ";
00418     }
00419   logBrowser->append(s.str().c_str());
00420   updateCounter();
00421   
00422 }
00423 
00424 void
00425 Tracker_Calibration_impl::ResetCalib_clicked()
00426 {
00427   fcountLeft=0;
00428   fcountRight=0;
00429   if (coordCountLeft>0)
00430     {
00431       std::stringstream xl,yl,zl;
00432       xl << fulcrumarrayLeft[fcountLeft].worldVal[0];
00433       WorldX->setText(xl.str().c_str());
00434       yl << fulcrumarrayLeft[fcountLeft].worldVal[1];
00435       WorldY->setText(yl.str().c_str());
00436       zl << fulcrumarrayLeft[fcountLeft].worldVal[2];
00437       WorldZ->setText(zl.str().c_str());
00438     }
00439   if (coordCountRight>0)
00440     {
00441       std::stringstream xr,yr,zr;
00442       xr << fulcrumarrayRight[fcountRight].worldVal[0];
00443       WorldX_2->setText(xr.str().c_str());
00444       yr << fulcrumarrayRight[fcountRight].worldVal[1];
00445       WorldY_2->setText(yr.str().c_str());
00446       zr << fulcrumarrayRight[fcountRight].worldVal[2];
00447       WorldZ_2->setText(zr.str().c_str());
00448     }
00449   updateCounter();
00450 }
00451 
00452 void
00453 Tracker_Calibration_impl::clearAllData()
00454 {
00455   fcountLeft=0;
00456   fcountRight=0;
00457   coordCountLeft=0;
00458   coordCountRight=0;
00459   updateCounter();
00460 }
00461  
00462 
00463 
00464   // we don'T use CORBA anymore so this is not working
00465   // calibration is done as usual, results are saved
00466   // in a file which is loaded by trackerServer
00467   // (haass)
00468 void
00469 Tracker_Calibration_impl::SendDataToTracker_clicked()
00470 {
00471   /*
00472   tracker::allSensorCal dataLeft,dataRight;
00473   std::stringstream s;
00474   s << "Sent " << fcountLeft << " fulcrums fo left\n";
00475   for (int i = 0; i < fcountLeft; i++)
00476     s <<  fulcrumarrayLeft[i].sensorVal[0] << " "
00477       <<  fulcrumarrayLeft[i].sensorVal[1] << " "
00478       <<  fulcrumarrayLeft[i].sensorVal[2] << " -> "
00479       <<  fulcrumarrayLeft[i].worldVal[0] << " "
00480       <<  fulcrumarrayLeft[i].worldVal[1] << " "
00481       <<  fulcrumarrayLeft[i].worldVal[2] << "\n";
00482       
00483   s << "Sent " << fcountRight << " fulcrums fo right\n";
00484   for (int i = 0; i < fcountRight; i++)
00485     s <<  fulcrumarrayRight[i].sensorVal[0] << " "
00486       <<  fulcrumarrayRight[i].sensorVal[1] << " "
00487       <<  fulcrumarrayRight[i].sensorVal[2] << " -> "
00488       <<  fulcrumarrayRight[i].worldVal[0] << " "
00489       <<  fulcrumarrayRight[i].worldVal[1] << " "
00490       <<  fulcrumarrayRight[i].worldVal[2] << "\n";
00491 
00492   if (trackLeft)
00493     {
00494       dataLeft.length(fcountLeft);
00495       for (int i=0;i<fcountLeft;i++)
00496         dataLeft[i]=fulcrumarrayLeft[i];
00497       myCalLeft->myTracker->loadCalibration(dataLeft);
00498     }
00499   if (trackRight)
00500     {
00501       dataRight.length(fcountRight);
00502       for (int i=0;i<fcountRight;i++)
00503         dataRight[i]=fulcrumarrayRight[i];
00504       myCalRight->myTracker->loadCalibration(dataRight);
00505     }
00506   logBrowser->append(s.str().c_str());
00507   */
00508 }
00509 
00510 
00511 #if Tracker_Calibration_test
00512 #include <stdio.h>
00513 int main(int argc, char **argv)
00514 {
00515   // This is a module-test block. You can put code here that tests
00516   // just the contents of this C file, and build it by saying
00517   //             make Tracker_Calibration_test
00518   // Then, run the resulting executable (Tracker_Calibration_test).
00519   // If it works as expected, the module is probably correct. ;-)
00520 
00521   fprintf(stderr, "For testing simply run the application\n");
00522 
00523   return 0;
00524 }
00525 #endif /* Tracker_Calibration_test */


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 Sat Jun 8 2019 19:36:21