PoseSpeedFactor.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // Created by zx on 23-6-20.
  3. //
  4. #include "PoseSpeedFactor.h"
  5. Vector PoseSpeedFactor::evaluateError(const Pose2& p1, const Vector2 & speed1, const Pose2& p2,
  6. boost::optional<Matrix&> H1,
  7. boost::optional<Matrix&> H2,
  8. boost::optional<Matrix&> H3) const{
  9. double v1=speed1[0];
  10. double w1=speed1[1];
  11. double x1=p1.x();
  12. double y1=p1.y();
  13. double th1=p1.theta();
  14. double x2=p2.x();
  15. double y2=p2.y();
  16. double th2=p2.theta();
  17. //loss 对 p1求导
  18. if(H1){
  19. *H1 = (Matrix(3, 3) << ( 0, 0, 1.0/w1,
  20. 1.0/(cos(th1)*v1), 0, -(x2-x1)*v1*sin(th1)/pow(cos(th1)*v1,2),
  21. 0, 1.0/(sin(th1)*v1), (y2-y1)*v1*cos(th1)/pow(sin(th1)*v1,2) )).finished();
  22. }
  23. if(H2){
  24. *H2 = (Matrix(3, 2) << ( 0, (th2-th1)/(w1*w1),
  25. (x2-x1)*cos(th1)/pow(cos(th1)*v1,2),0,
  26. (y2-y1)*sin(th1)/pow(sin(th1)*v1,2),0 )).finished();
  27. }
  28. if(H3){
  29. *H3 = (Matrix(3, 3) << ( 0, 0,0,
  30. -1.0/(cos(th1)*v1), 0, 0,
  31. 0, -1.0/(sin(th1)*v1), 0 )).finished();
  32. }
  33. return (Vector(3)<<dt_[0]-(th2-th1)/w1 ,dt_[1]-(x2-x1)/(cos(th1)*v1), dt_[2]-(y2-y1)/(sin(th1)*v1) ).finished();
  34. }