calibration.cpp
Go to the documentation of this file.
1 
31 
32 #include <boost/assert.hpp>
33 #include <boost/foreach.hpp>
34 
35 #include <algorithm>
36 #include <vector>
37 #include <iostream>
38 
39 namespace shadow_robot
40 {
41  JointCalibration::JointCalibration(std::vector<joint_calibration::Point> calibration_table)
42  {
43  this->calibration_table_ = calibration_table;
44  // calibration size - 1 because we use this number to access the last value in the vector
45  if (calibration_table.size())
46  calibration_table_size_ = calibration_table.size() - 1;
47  else
49 
50  // fails if we have only one calibration point as it's not possible
51  // to interpolate from one point
52  BOOST_ASSERT(calibration_table_size_ > 0);
53 
54  /*
55  * make sure that the given calibration table is ordered by
56  * growing values of the raw_value
57  */
58  std::sort(this->calibration_table_.begin(), this->calibration_table_.end(),
60  }
61 
69  double JointCalibration::compute(double raw_reading)
70  {
75  joint_calibration::Point low_point, high_point;
76 
77  // That takes care of computing a reading that's before
78  // the calibration table as well as a reading that's in the
79  // first calibration table case.
80  low_point = calibration_table_[0];
81  high_point = calibration_table_[1];
82 
83  bool found = false;
84 
85  // if we have more than 2 points in our calibration table
86  // or if the raw value isn't before the calibration table
87  if (raw_reading > calibration_table_[0].raw_value)
88  {
90  {
91  for (unsigned int index_cal = 1; index_cal < calibration_table_size_; ++index_cal)
92  {
93  if ((raw_reading >= calibration_table_[index_cal - 1].raw_value) &&
94  (raw_reading < calibration_table_[index_cal].raw_value))
95  {
96  low_point = calibration_table_[index_cal - 1];
97  high_point = calibration_table_[index_cal];
98 
99  found = true;
100  break;
101  }
102  } // end for
103 
104  // the point is outside of the table
105  if (!found)
106  {
107  low_point = calibration_table_[calibration_table_size_ - 1];
109  }
110  } // end if 2 values only in the table
111  } // end if raw_reading before table
112 
113  return sr_math_utils::linear_interpolate_(raw_reading, low_point.raw_value,
114  low_point.calibrated_value,
115  high_point.raw_value,
116  high_point.calibrated_value);
117  }
118 } // namespace shadow_robot
119 
120 /* For the emacs weenies in the crowd.
121 Local Variables:
122  c-basic-offset: 2
123 End:
124 */
JointCalibration(std::vector< joint_calibration::Point > calibration_table)
Definition: calibration.cpp:41
static double linear_interpolate_(double x, double x0, double y0, double x1, double y1)
std::vector< joint_calibration::Point > calibration_table_
Definition: calibration.hpp:97
double compute(double raw_reading)
Definition: calibration.cpp:69
This class contains the algorithm which takes the raw ADC reading, and uses the N-point piecewise lin...
static bool sort_growing_raw_operator(const Point &p1, const Point &p2)
Definition: calibration.hpp:57
This is a header library used to implement some useful math functions. It is used in our different pa...


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Tue Oct 13 2020 03:55:49