PriorFactor.h 1.3 KB

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