00001 00039 #ifndef XML_CALIBRATION_PARSER_H_ 00040 # define XML_CALIBRATION_PARSER_H_ 00041 00042 //xml parser library 00043 #include <tinyxml.h> 00044 00045 //generic C/C++ include 00046 #include <string> 00047 #include <vector> 00048 #include <map> 00049 00050 namespace xml_calibration_parser{ 00051 00052 class XmlCalibrationParser 00053 { 00054 public: 00055 XmlCalibrationParser(){}; 00056 XmlCalibrationParser(std::string path_to_calibration); 00057 ~XmlCalibrationParser(){}; 00058 00059 float get_calibration_value(float position, std::string joint_name); 00060 00061 struct Calibration 00062 { 00063 float raw_value; 00064 float calibrated_value; 00065 }; 00066 00067 struct JointCalibration 00068 { 00069 std::string name; 00070 std::vector<Calibration> calibrations; 00071 }; 00072 00073 00074 std::vector<JointCalibration> getJointsCalibrations(); 00075 00076 protected: 00077 void parse_calibration_file( TiXmlNode* pParent ); 00078 std::vector<Calibration> parse_joint_attributes( TiXmlNode* pParent ); 00079 00081 std::vector<JointCalibration> jointsCalibrations; 00082 // use a map to easily access the value 00083 typedef std::map<std::string, std::vector<float> > mapType; 00084 mapType joints_calibrations_map; 00085 00086 int build_calibration_table(); 00087 00088 std::vector<float> calibration_to_lookup_table(std::vector<Calibration> calib); 00089 00090 float compute_lookup_value(int index, std::vector<Calibration> calib); 00091 00092 float linear_interpolate( float x , 00093 float x0, float y0, 00094 float x1, float y1 ); 00095 00096 // consts for the lookup tables 00097 static const float lookup_precision; 00098 static const float lookup_offset; 00099 00107 int round(float number); 00108 00117 int return_index_from_raw_position(float raw_position); 00118 00127 static inline float return_raw_position_from_index(int lookup_index) 00128 { 00129 return ((float)lookup_index)/lookup_precision; 00130 }; 00131 00132 }; // end class XmlCalibrationParser 00133 00134 } // end namespace 00135 #endif /* !XML_CALIBRATION_PARSER_H_ */