2
* @file calibration_parser.cpp
3
* @author Ugo Cupcic <ugo@shadowrobot.com>, Contact <contact@shadowrobot.com>
4
* @date Thu May 13 11:41:56 2010
6
* @brief This is where the calibration matrix is read from a file, stored and where the actual mapping take place.
14
#include <boost/algorithm/string.hpp>
15
#include <boost/algorithm/string/find_iterator.hpp>
16
#include "sr_remappers/calibration_parser.h"
20
const std::string CalibrationParser::default_path = "/etc/robot/mappings/default_mapping";
22
CalibrationParser::CalibrationParser()
24
ROS_WARN("No calibration path was specified, using default path");
28
CalibrationParser::CalibrationParser(std::string path)
33
int CalibrationParser::init(std::string path)
35
//reserve enough lines
36
calibration_matrix.reserve(25);
38
ifstream calibration_file;
39
calibration_file.open(path.c_str());
42
if(!calibration_file.is_open())
44
ROS_ERROR("Couldn't open the file %s", path.c_str());
48
//we read the file and put all the data in this matrix
49
std::vector< std::vector<double> > tmp_matrix;
52
while( !calibration_file.eof() )
54
getline( calibration_file, line );
56
//remove leading and trailing whitespaces
57
line = boost::algorithm::trim_copy(line);
60
if( line.size() == 0 )
67
std::vector<std::string> splitted_string;
68
boost::split(splitted_string, line, boost::is_any_of("\t "));
70
std::vector<double> double_line(splitted_string.size());
71
for(unsigned int index_col=0; index_col< splitted_string.size(); ++index_col)
72
double_line[index_col] = convertToDouble(splitted_string[index_col]);
74
calibration_matrix.push_back(double_line);
76
calibration_file.close();
82
std::vector<double> CalibrationParser::get_remapped_vector(std::vector<double> input_vector)
84
//check the size of the matrix
85
if(input_vector.size() != calibration_matrix.size())
87
ROS_ERROR("The size of the given vector doesn't correspond to the mapping: received %d, wanted %d", input_vector.size(), calibration_matrix.size());
88
return std::vector<double>(calibration_matrix[0].size());
91
std::vector<double> result(calibration_matrix[0].size());
94
for(unsigned int col = 0; col < calibration_matrix[0].size(); ++col)
97
for(unsigned int index_vec = 0; index_vec < calibration_matrix.size(); ++index_vec)
99
tmp_value += (input_vector[index_vec]*calibration_matrix[index_vec][col]);
101
result[col] = tmp_value;