Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

LoadCalibration.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_LoadCalibration_h_
00003 #define INCLUDED_LoadCalibration_h_
00004 
00005 #include "FileBrowserControl.h"
00006 #include "Motion/WalkMC.h"
00007 
00008 //! will load calibration parameters from a text file into a forward and backward matrix
00009 /*! normally the calibration parameters are stored in the binary walk parameter file itself,
00010  *  but this will load a new set of calibration parameters from a text file as written by
00011  *  the tools/walk_calibration/WalkCalibration.m matlab script. */
00012 class LoadCalibration : public FileBrowserControl {
00013 public:
00014 
00015   //!Constructor
00016   LoadCalibration(WalkMC::CalibrationParam* calp)
00017     : FileBrowserControl("Load Calibration...","",config->motion.root), cp(calp)
00018   { setFilter("*.txt"); }
00019   //!Constructor
00020   LoadCalibration(const std::string& n,WalkMC::CalibrationParam* calp)
00021     : FileBrowserControl(n,"",config->motion.root), cp(calp)
00022   { setFilter("*.txt"); }
00023   //!Constructor
00024   LoadCalibration(const std::string& n, const std::string& d,WalkMC::CalibrationParam* calp)
00025     : FileBrowserControl(n,d,config->motion.root), cp(calp)
00026   { setFilter("*.txt"); }
00027 
00028 protected:
00029   static const unsigned int ROWS=3;  //!< number of degrees of freedom of movement (probably won't change)
00030   static const unsigned int COLS=11; //!< number of basis functions (may change)
00031 
00032   //!calls readData() for each of the matrices
00033   virtual ControlBase* selectedFile(const std::string& f) {
00034     FILE * file=fopen(config->portPath(f).c_str(),"r");
00035     if(readMaxs(file))
00036       if(readData(file,cp->f_calibration))
00037         readData(file,cp->b_calibration);
00038     fclose(file);
00039     FileBrowserControl::selectedFile(f);
00040     return NULL;
00041   }
00042 
00043   //!does the actual loading once a file is selected
00044   bool readData(FILE * f, float mat[ROWS][COLS]) {
00045     const unsigned int curl=500;
00046     char curs[curl];
00047     for(unsigned int i=0; i<ROWS; i++) {
00048       fgets(curs,curl,f);
00049       if(feof(f)) {
00050         serr->printf("ERROR: short read, got %d lines.\n",1+(mat==cp->f_calibration?i:i+ROWS));
00051         return false;
00052       } else {
00053         char *c=curs;
00054         for(unsigned int col=0; col<COLS; col++)
00055           mat[i][col]=static_cast<float>(strtod(c,&c));
00056       }
00057     }
00058     return true;
00059   }
00060 
00061   //!reads the maximum forward, backward, strafe, and rotation velocities
00062   bool readMaxs(FILE * f) {
00063     const unsigned int curl=500;
00064     char curs[curl];
00065     fgets(curs,curl,f);
00066     if(feof(f)) {
00067       serr->printf("ERROR: short read, got %d lines.\n",0);
00068       return false;
00069     } else {
00070       char *c=curs;
00071       for(unsigned int col=0; col<WalkMC::CalibrationParam::NUM_DIM; col++)
00072         cp->max_vel[col]=static_cast<float>(strtod(c,&c));
00073     }
00074     return true;
00075   }
00076 
00077   WalkMC::CalibrationParam * cp; //!< pointer to the calibration parameter structure
00078 
00079 private:
00080   LoadCalibration(const LoadCalibration& ); //!< don't call
00081   LoadCalibration& operator=(const LoadCalibration& ); //!< don't call
00082 };
00083 
00084 /*! @file
00085  * @brief Defines LoadCalibration, which will load calibration parameters from a text file into a forward and backward matrix
00086  * @author ejt (Creator)
00087  */
00088 
00089 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:43 2016 by Doxygen 1.6.3