navigation.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // Created by zx on 22-12-2.
  3. //
  4. #ifndef LIO_LIVOX_CPP_MPC_NAVIGATION_H_
  5. #define LIO_LIVOX_CPP_MPC_NAVIGATION_H_
  6. #include "../define/timedlockdata.hpp"
  7. #include "pose2d.h"
  8. #include "trajectory.h"
  9. #include "monitor/monitor_emqx.h"
  10. #include "monitor/terminator_emqx.h"
  11. #include "parameter.pb.h"
  12. #include <queue>
  13. #include <thread>
  14. class Navigation
  15. {
  16. public:
  17. typedef struct{
  18. double min;
  19. double max;
  20. }stLimit;
  21. enum ActionType
  22. {
  23. eReady=0,
  24. eRunning
  25. };
  26. public:
  27. Navigation();
  28. ~Navigation();
  29. //连接AGV emqx服务
  30. bool Init(const Navigation_parameter& parameter);
  31. void ResetPose(const Pose2d& pose);
  32. void ResetStatu(double v,double a);
  33. TimedLockData<Pose2d>& RealTimePose(){
  34. return timedPose_;
  35. }
  36. TimedLockData<double>& RealTimeV(){
  37. return timedV_;
  38. }
  39. TimedLockData<double>& RealTimeA(){
  40. return timedA_;
  41. }
  42. bool Start(const NavMessage::NavCmd& cmd);
  43. void Cancel();
  44. void Pause();
  45. protected:
  46. static void RobotPoseCallback(const MqttMsg& msg,void* context);
  47. static void RobotSpeedCallback(const MqttMsg& msg,void* context);
  48. static void NavCmdCallback(const MqttMsg& msg,void* context);
  49. static void BrotherAgvStatuCallback(const MqttMsg& msg,void* context);
  50. static bool IsArrived(const Pose2d& cur,double velocity,double angular,const Pose2d& target,
  51. const Pose2d& diff);
  52. bool execute_along_action(const Pose2d& target,const Pose2d& target_diff,stLimit limit_v);
  53. bool exec_adjust_action(const Pose2d& target,const Pose2d& target_diff,
  54. stLimit limit_v,stLimit limit_h,stLimit limit_rotate);
  55. bool mpc_once(const Trajectory& traj,stLimit limit_v,std::vector<double>& out);
  56. void navigatting();
  57. /*
  58. * 发布导航模块状态
  59. */
  60. void publish_statu();
  61. protected:
  62. std::mutex mtx_;
  63. bool exit_=false;
  64. std::thread* pubthread_= nullptr;
  65. bool inited_=false;
  66. Monitor_emqx* monitor_= nullptr;
  67. Terminator_emqx* terminator_= nullptr;
  68. TimedLockData<Pose2d> timedPose_; //当前位姿
  69. TimedLockData<double> timedV_; //底盘数据
  70. TimedLockData<double> timedA_;
  71. TimedLockData<Pose2d> timedBrotherPose_; //当前位姿
  72. TimedLockData<double> timedBrotherV_; //底盘数据
  73. TimedLockData<double> timedBrotherA_;
  74. NavMessage::NavCmd global_navCmd_; //导航任务,包含一系列动作
  75. std::queue<NavMessage::Action> unfinished_cations_; //未完成的动作
  76. std::thread* thread_= nullptr;
  77. bool running_=false;
  78. bool pause_=false;
  79. bool cancel_=false;
  80. TimedLockData<Trajectory> selected_traj_;
  81. TimedLockData<Trajectory> predict_traj_;
  82. Navigation_parameter parameter_;
  83. };
  84. #endif //LIO_LIVOX_CPP_MPC_NAVIGATION_H_