navigation_main.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. void ResetOtherLifter(LifterStatus status);
  16. virtual void HandleAgvStatu(const MqttMsg &msg);
  17. virtual void SwitchMode(int mode, float wheelBase) {
  18. printf("change mode to:%d\n", mode);
  19. if (move_mode_ == mode)
  20. return;
  21. if (mode == eDouble) {
  22. if (timedBrotherPose_.timeout() == true || timedPose_.timeout() == true) {
  23. std::cout << "Brother/self pose is timeout can not set MainAGV pose" << std::endl;
  24. return;
  25. }
  26. //Pose2d transform(-wheelBase_/2.0,0,0);
  27. //Navigation::ResetPose(pose * transform);
  28. Pose2d brother = timedBrotherPose_.Get();
  29. Pose2d pose = timedPose_.Get();
  30. Pose2d diff = Pose2d::abs(Pose2d::relativePose(brother, pose));
  31. if (diff.x() > 3.4 || diff.x() < 2.3 || diff.y() > 0.2 || diff.theta() > 5 * M_PI / 180.0) {
  32. std::cout << " distance with two agv is too far diff: " << diff << std::endl;
  33. return;
  34. }
  35. Pose2d self_pose = timedPose_.Get();
  36. Pose2d brother_pose = timedBrotherPose_.Get();
  37. Pose2d brother_in_self = Pose2d::relativePose(brother_pose, self_pose);
  38. if (brother_in_self.x() <= 0)
  39. mode = mode | eMainInForward;
  40. else
  41. mode = mode | eMainInBackward;
  42. if (brother_in_self.theta() >= -M_PI / 2 && brother_in_self.theta() <= M_PI / 2)
  43. mode = mode | eChildSameToMain;
  44. else
  45. mode = mode | eChildOppositeToMain;
  46. printf(" Switch MoveMode --> main(%d), wheelBase: %f\n", mode, wheelBase);
  47. }
  48. wheelBase_ = wheelBase;
  49. move_mode_ = mode;
  50. };
  51. protected:
  52. virtual Navigation::MpcResult
  53. RotateBeforeEnterSpace(NavMessage::PathNode space, double wheelbase, NavMessage::PathNode &target);
  54. virtual void SendMoveCmd(int mode, ActionType type, double v[], double angular[]);
  55. virtual bool clamp_close();
  56. virtual bool clamp_open();
  57. virtual bool lifter_rise();
  58. virtual bool lifter_down();
  59. virtual bool CreateRobotStatuMsg(NavMessage::RobotStatu &robotStatu);
  60. protected:
  61. float wheelBase_; //两节agv的位姿与单节的位姿变换
  62. TimedLockData<int> timed_other_clamp_;
  63. TimedLockData<int> timed_other_lifter_;
  64. };
  65. #endif //NAVIGATION_NAVIGATION_MAIN_H