navigation_main.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // Created by zx on 23-5-8.
  3. //
  4. #ifndef NAVIGATION_NAVIGATION_MAIN_H
  5. #define NAVIGATION_NAVIGATION_MAIN_H
  6. #include "navigation.h"
  7. class NavigationMain : public Navigation {
  8. public:
  9. NavigationMain();
  10. ~NavigationMain();
  11. virtual void ResetPose(const Pose2d &pose);
  12. virtual void Start(const NavMessage::NavCmd &cmd, NavMessage::NavResponse &response);
  13. virtual void publish_statu(NavMessage::NavStatu &statu);
  14. void ResetOtherClamp(ClampStatu statu);
  15. virtual void HandleAgvStatu(const MqttMsg &msg);
  16. virtual void SwitchMode(int mode, float wheelBase) {
  17. if (move_mode_ == mode)
  18. return;
  19. if (mode == eDouble) {
  20. if (timedBrotherPose_.timeout() == true || timedPose_.timeout() == true) {
  21. std::cout << "Brother/self pose is timeout can not set MainAGV pose" << std::endl;
  22. return;
  23. }
  24. //Pose2d transform(-wheelBase_/2.0,0,0);
  25. //Navigation::ResetPose(pose * transform);
  26. Pose2d brother = timedBrotherPose_.Get();
  27. Pose2d pose = timedPose_.Get();
  28. Pose2d diff = Pose2d::abs(Pose2d::relativePose(brother, pose));
  29. if (diff.x() > 3.4 || diff.x() < 2.3 || diff.y() > 0.2 || diff.theta() > 5 * M_PI / 180.0) {
  30. std::cout << " distance with two agv is too far diff: " << diff << std::endl;
  31. return;
  32. }
  33. Pose2d self_pose = timedPose_.Get();
  34. Pose2d brother_pose = timedBrotherPose_.Get();
  35. Pose2d brother_in_self = Pose2d::relativePose(brother_pose, self_pose);
  36. if (brother_in_self.x() <= 0)
  37. mode = mode | eMainInForward;
  38. else
  39. mode = mode | eMainInBackward;
  40. if (brother_in_self.theta() >= -M_PI / 2 && brother_in_self.theta() <= M_PI / 2)
  41. mode = mode | eChildSameToMain;
  42. else
  43. mode = mode | eChildOppositeToMain;
  44. printf(" Switch MoveMode --> main(%d)\n", mode);
  45. }
  46. wheelBase_ = wheelBase;
  47. move_mode_ = mode;
  48. };
  49. protected:
  50. virtual Navigation::MpcResult
  51. RotateBeforeEnterSpace(NavMessage::PathNode space, double wheelbase, NavMessage::PathNode &target);
  52. virtual void SendMoveCmd(int mode, ActionType type,
  53. double v, double angular);
  54. virtual bool clamp_close();
  55. virtual bool clamp_open();
  56. virtual bool CreateRobotStatuMsg(NavMessage::RobotStatu &robotStatu);
  57. protected:
  58. float wheelBase_; //两节agv的位姿与单节的位姿变换
  59. TimedLockData<int> timed_other_clamp_;
  60. };
  61. #endif //NAVIGATION_NAVIGATION_MAIN_H