PriorFactor.h 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. #pragma once
  2. #include <ros/assert.h>
  3. #include <iostream>
  4. #include <eigen3/Eigen/Dense>
  5. #include <ceres/ceres.h>
  6. #include "utils/math_tools.h"
  7. struct SpeedBiasPriorFactorAutoDiff {
  8. public:
  9. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  10. SpeedBiasPriorFactorAutoDiff(vector<double> speedBias) : speedBias_(speedBias) {}
  11. template <typename T> bool operator()(const T *speedBias, T *residuals) const {
  12. residuals[0] = T(15) * (speedBias[0] - T(speedBias_[0]));
  13. residuals[1] = T(15) * (speedBias[1] - T(speedBias_[1]));
  14. residuals[2] = T(15) * (speedBias[2] - T(speedBias_[2]));
  15. residuals[3] = T(15) * (speedBias[3] - T(speedBias_[3]));
  16. residuals[4] = T(15) * (speedBias[4] - T(speedBias_[4]));
  17. residuals[5] = T(15) * (speedBias[5] - T(speedBias_[5]));
  18. residuals[6] = T(15) * (speedBias[6] - T(speedBias_[6]));
  19. residuals[7] = T(15) * (speedBias[7] - T(speedBias_[7]));
  20. residuals[8] = T(15) * (speedBias[8] - T(speedBias_[8]));
  21. return true;
  22. }
  23. static ceres::CostFunction *Create(vector<double> speedBias_) {
  24. return (new ceres::AutoDiffCostFunction<SpeedBiasPriorFactorAutoDiff, 9, 9>(new SpeedBiasPriorFactorAutoDiff(speedBias_)));
  25. }
  26. private:
  27. vector<double> speedBias_;
  28. };