magnetometer_error.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Michael Ferguson
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // Author: Michael Ferguson
18 
19 #ifndef ROBOT_CALIBRATION_CERES_MAGNETOMETER_ERROR_H
20 #define ROBOT_CALIBRATION_CERES_MAGNETOMETER_ERROR_H
21 
22 #include <ceres/ceres.h>
23 
29 {
30 public:
31  HardIronOffsetError(double x, double y, double z)
32  {
33  x_ = x;
34  y_ = y;
35  z_ = z;
36  }
37 
38  template <typename T>
39  bool operator()(const T* const params, T* residuals) const
40  {
41  // Parameters are:
42  // 0 = local magnetic field strength
43  // 1 = x offset
44  // 2 = y offset
45  // 3 = z offset
46  residuals[0] = (x_ - params[1]) * (x_ - params[1]) +
47  (y_ - params[2]) * (y_ - params[2]) +
48  (z_ - params[3]) * (z_ - params[3]) -
49  (params[0] * params[0]);
50 
51  return true;
52  }
53 
54  static ceres::CostFunction* Create(double x, double y, double z)
55  {
56  ceres::CostFunction* func
57  = new ceres::AutoDiffCostFunction<HardIronOffsetError, 1, 4>(new HardIronOffsetError(x, y, z));
58  return func;
59  }
60 
61 private:
62  // The actual sampled data
63  double x_, y_, z_;
64 };
65 
66 #endif // ROBOT_CALIBRATION_CERES_MAGNETOMETER_ERROR_H
HardIronOffsetError(double x, double y, double z)
bool operator()(const T *const params, T *residuals) const
static ceres::CostFunction * Create(double x, double y, double z)
Cost functor for magnetometer sample when doing only hard iron offsets.


robot_calibration
Author(s): Michael Ferguson
autogenerated on Tue Nov 3 2020 17:30:30