LoadCalibration.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_LoadCalibration_h_
00003 #define INCLUDED_LoadCalibration_h_
00004
00005 #include "FileBrowserControl.h"
00006 #include "Motion/WalkMC.h"
00007
00008
00009
00010
00011
00012 class LoadCalibration : public FileBrowserControl {
00013 public:
00014
00015
00016 LoadCalibration(WalkMC::CalibrationParam* calp)
00017 : FileBrowserControl("Load Calibration...","",config->motion.root), cp(calp)
00018 { setFilter("*.txt"); }
00019
00020 LoadCalibration(const std::string& n,WalkMC::CalibrationParam* calp)
00021 : FileBrowserControl(n,"",config->motion.root), cp(calp)
00022 { setFilter("*.txt"); }
00023
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;
00030 static const unsigned int COLS=11;
00031
00032
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
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
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;
00078
00079 private:
00080 LoadCalibration(const LoadCalibration& );
00081 LoadCalibration& operator=(const LoadCalibration& );
00082 };
00083
00084
00085
00086
00087
00088
00089 #endif