main.cpp
Go to the documentation of this file.
00001 
00018 #include <cstdio>
00019 #include <iostream>
00020 #include <cstring>
00021 #include <fstream> 
00022 
00023 #include <boost/program_options.hpp>
00024 
00025 #include <log.h>
00026 #include <frame.h>
00027 #include <datapairs.h>
00028 #include <value_setter.h>
00029 #include <optimizer_goal.h>
00030 #include <optimizer_goal_global_position.h>
00031 #include <optimizer_goal_global_orientation.h>
00032 #include <optimizer_goal_orientation.h>
00033 #include <optimizer_goal_position.h>
00034 #include <optimizer_container.h>
00035 #include <optimizer_iv.h>
00036 
00037 using namespace robotLibPbD;
00038 namespace po = boost::program_options;
00039 
00040 // main function
00041 int main(int argc, char *argv[])
00042 {    
00043   std::string filename, initial, cfg;
00044   unsigned int iterations;
00045   bool useRandom;
00046   double trim, epsilon;
00047   bool useShowResult;
00048   //unsigned int trimming, examples;
00049   unsigned int examplesMax;
00050   unsigned int counterMod; 
00051   double ivLineWidth, ivSphereRadius, ivCoordScale;
00052   
00053 
00054   po::options_description desc("Usage : kinematic_chain_optimizer [options]");
00055   desc.add_options()
00056     ( "help,h","show help screen")
00057     ( "exit","show only initial error")
00058     ( "filename",po::value<std::string>(&filename)->default_value("data/calib_dump"),"load data from filename")
00059     ( "initial",po::value<std::string>(&initial)->default_value(""), "Initial value for optimization, e.g. 0.6 0.4 0.3 (n = 3)") 
00060     ( "cfg",po::value<std::string>(&cfg)->default_value("data/frames.xml"),"load cfg from filename")
00061     ( "debug",po::value<int>(&globalLog.debugLevel)->default_value(5),"debug level")
00062     ( "trim",po::value<double>(&trim)->default_value(0.2),"trimming percentage")
00063     ( "epsilon",po::value<double>(&epsilon)->default_value(1.0e-8),"convergence limit, 0.00000001")
00064     ( "random",po::value<bool>(&useRandom)->default_value(false),"use random start value" ) 
00065     ( "always",po::value<bool>(&useShowResult)->default_value(false),"always show result" ) 
00066     ( "max",po::value<unsigned int>(&examplesMax)->default_value(10000000),"use max number of data" )  
00067     ( "iterations",po::value<unsigned int>(&iterations)->default_value(500),"use max number of iterations" ) 
00068     ( "debugiterations",po::value<unsigned int>(&counterMod)->default_value(100),"show result each x iterations" ) 
00069     ( "ivlinewidth",po::value<double>(&ivLineWidth)->default_value(0.5),"width of Inventor line")
00070     ( "ivsphereradius",po::value<double>(&ivSphereRadius)->default_value(1.0),"radius of Inventor sphere")
00071     ( "ivcoordscale",po::value<double>(&ivCoordScale)->default_value(0.2),"scaleFactor of Inventor coordinate system")
00072     ;
00073  
00074   po::variables_map vm;
00075   po::store(po::parse_command_line(argc, argv, desc), vm);
00076   po::notify(vm);
00077 
00078   if (vm.count("help")) {
00079     std::cout << desc <<std::endl;
00080     return 0;
00081   }
00082 
00083   bool doQuit = vm.count("exit");
00084   
00085   // parse initial values
00086   std::vector<double> initialValues;
00087   strToArray(initial, initialValues);
00088 
00089   // set random generator
00090   unsigned int seed = (unsigned int) getTickCount(); 
00091   LOG_MSG(2, "Random Generator Seed is %d\n", seed);
00092   
00093   setUniformSeed(seed);
00094   srand(seed);
00095 
00096   COptimizerIv optimizer; 
00097 
00098   // set parameters
00099   optimizer.setEpsilon(epsilon);
00100   optimizer.setTrimming(trim);
00101   optimizer.setIterations(iterations);
00102   optimizer.setRandomStart(useRandom);
00103   optimizer.setQuit(doQuit);
00104   optimizer.setDataMax(examplesMax);
00105   optimizer.setShowResult(useShowResult);
00106   optimizer.setShowModulo(counterMod);
00107   optimizer.setIvLineWidth(ivLineWidth); 
00108   optimizer.setIvSphereRadius(ivSphereRadius);
00109   optimizer.setIvCoordScale(ivCoordScale);
00110  
00111   optimizer.load(cfg, filename); 
00112 
00113   optimizer.run(initialValues);
00114  
00115   COptimizerResult result;
00116   if (!optimizer.getResult(result))
00117     {
00118       LOG_MSG(1, "Error: Optimization failed\n.");
00119     }
00120   else
00121     {
00122       printf("Showing final result:\n");
00123       printf("Value: %f\n", result.result);
00124       printf("Values: %s\n", arrayToString(result.values).c_str());
00125 
00126       for (unsigned int i=0; i<result.optimizedPoses.size(); i++)
00127         {
00128           CMatrix pose = result.optimizedPoses[i].second;
00129           CVec position, quater; 
00130           position = pose[3];
00131           CMathLib::quaternionFromMatrix(pose, quater); 
00132           
00133           printf("Name: %s Position (xyz): %f %f %f Quaternion (wxyz): %f %f %f %f\n", result.optimizedPoses[i].first.c_str(),
00134                  position.x, position.y, position.z,
00135                  quater.w, quater.x, quater.y, quater.z);
00136         }
00137 
00138       optimizer.generateInventor(result.values, "data/plot.iv"); 
00139     }
00140 
00141   return 0;
00142 }
00143 
00144 


asr_kinematic_chain_optimizer
Author(s): Aumann Florian, Heller Florian, Jäkel Rainer, Wittenbeck Valerij
autogenerated on Sat Jun 8 2019 19:42:49