navigation_main.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 void SendMoveCmd(int mode, ActionType type, double v[], double angular[], int space_id, double distance);
  56. virtual bool clamp_close();
  57. virtual bool clamp_open();
  58. virtual bool lifter_rise();
  59. virtual bool lifter_down();
  60. virtual bool CreateRobotStatuMsg(NavMessage::RobotStatu &robotStatu);
  61. protected:
  62. float wheelBase_; //两节agv的位姿与单节的位姿变换
  63. TimedLockData<int> timed_other_clamp_;
  64. TimedLockData<int> timed_other_lifter_;
  65. };
  66. #endif //NAVIGATION_NAVIGATION_MAIN_H