27 #define NUM_SENSORS 22 28 #define NUM_TOTAL_STEPS 8 29 #define MIN_JOINT_RESOLUTION 20 32 const char *
CAL_STEP_TEXT[] = {
"Press your hand against a flat surface, all fingers pointing parallel, and press \"Record Sample\" when ready.",
33 "Press your hand against a flat surface, open all fingers, and press \"Record Sample\" when ready.",
34 "Close your index, middle, ring, pinky finger as much as possible, and press \"Record Sample\" when ready.",
35 "Do an ok gesture by touching the thumb tip with the index tip, and press \"Record Sample\" when ready.",
36 "Bend your wrist up, and press Enter when ready.",
37 "Bend your wrist down, and press Enter when ready.",
38 "Bend your wrist inside, with your thumb towards the forearm. Press Enter when ready.",
39 "Bend your wrist outside, and press Enter when ready.",
40 "Calibration finished. Now save and/or load it to the server." 45 "images/1hand-flat-open.jpg",
46 "images/2hand-fingers-closed.jpg",
47 "images/3hand-ok-gesture.jpg",
48 "images/4hand-wrist-up.jpg",
49 "images/5hand-wrist-down.jpg",
50 "images/6hand-wirst-in.jpg",
51 "images/7hand-wirst-out.jpg",
52 "images/00glove-calibration.jpg" 69 CORBA::Object_ptr newObjectPointer = bgcorba::resolveObject(trackerServerName);
70 myTracker = tracker::trackerServer::_narrow(newObjectPointer);
72 if (CORBA::is_nil(myTracker)) {
73 BGDBG(0,
"Could not find a trackerServer.\n");
77 BGDBG(0,
"trackerServer found!\n");
105 if(step <= NUM_TOTAL_STEPS && step >= 0)
115 if(step <= NUM_TOTAL_STEPS && step >= 0)
126 std::vector<double> c;
127 IPRFilterModule::TimeDataVector measure;
131 measure = *(myTracker->getRawData());
133 BGDBG(0,
"Glove server dead? Could not connect.\n");
137 for (
unsigned int i=0; i<measure.v.vector.length(); i++)
138 c.push_back(measure.v.vector[i]);
174 if ((f=fopen(fileName.c_str(),
"w")) == NULL)
176 BGDBG(0,
"save calibration file - error: open file !\n");
180 for (
unsigned int i=0; i<
data.size(); i++){
182 for (
unsigned int j=0; j<
data[i].size(); j++){
183 fprintf(f,
"%f:%f", (
data[i])[j].first, (
data[i])[j].second);
184 if(j <
data[i].size()-1)
192 BGDBG(0,
"Saved calibration successfully!\n");
201 std::ifstream inputFile (fileName.c_str());
202 if (!inputFile.is_open()){
203 BGDBG(0,
"open calibration file - error while opening file !\n");
209 bg::strlist lines = bg::string(inputFile).split(
"\n");
213 for (
unsigned int lineNo=0; lineNo<lines.size(); lineNo++){
216 bg::strlist fulcs = lines[lineNo].split(
" ");
220 for(
unsigned int fulcNo=0; fulcNo<fulcs.size(); fulcNo++){
223 bg::strlist oneF = fulcs[fulcNo].split(
":");
224 if(oneF.size() != 2){
225 BGDBG(0,
"Read calibration file - error while reading file. Incomplete data.\n");
228 f.first = oneF[0].toDouble();
229 f.second = oneF[1].toDouble();
232 tcal.push_back(scal);
236 BGDBG(0,
"Opened calibration file successfully!\n");
237 BGDBG(3,
"File contained %d lines, first line contained %d entries.\n", tcal.size(), tcal[0].size());
247 std::vector<unsigned int> bad;
250 for (
unsigned int i=0; i<
data.size(); i++){
260 BGDBG(3,
"Calibration data not ok.\n");
261 s <<
"********************************************************************\n";
262 s <<
"Bad calibration data.\n";
263 for(
unsigned int i=0; i<bad.size(); i++){
264 s <<
"Joint " <<
JOINT_NAME[bad[i]] <<
" does not achieve minimum resolution.\n";
265 s <<
"Joint resolution: " << (int)fabs(
data[bad[i]][1].second -
data[bad[i]][0].second)
267 if(fabs(
data[bad[i]][1].second -
data[bad[i]][0].second) < 2)
268 s <<
"GloveServer will bail out when reading this data!\n";
271 s <<
"It is strongly recommended to repeat the calibration.\n";
272 s <<
"********************************************************************\n";
274 print = std::string(s.str());
278 s <<
"Calibration data ok.\n";
279 print = std::string(s.str());
280 BGDBG(3,
"Calibration data ok.\n");
330 std::vector<double> a1, a2;
339 BGDBG(0,
"Error in computeCalibration(). Input data not ok.\n");
562 int main(
int argc,
char **argv)
570 fprintf(stderr,
"Testing cData\n");
trackerCal data
calibration data
const char * CAL_STEP_PIC[]
#define MIN_JOINT_RESOLUTION
const char * CAL_STEP_TEXT[]
bool openCalibration(std::string fileName)
int main(int argc, char **argv)
trackerCal getCalibration()
std::pair< double, double > fulcrum
bool setCalibration(trackerCal g)
const char * JOINT_NAME[]
for debug output
bool checkConsistency(std::string &print)
unsigned int numTotalSteps
current and total step number
bool saveCalibration(std::string fileName)
trackerCal computeCalibration(std::vector< std::vector< double > > r)
unsigned int getNumTotalSteps()
bool connectToTrackerServer(std::string trackerServerName)
std::string getPicForStep(int)
std::vector< sensorCal > trackerCal
const char * CAL_DEFAULT_PIC
std::vector< double > calibrateNextStep()
unsigned int getCurrentStep()
std::vector< fulcrum > sensorCal
std::string getTextForStep(int)
const char * CAL_DEFAULT_TEXT
std::vector< std::vector< double > > rawData
recorded raw data
bool tellServerLoadCurrentCalibration()