navigation.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. enum ActionType
  18. {
  19. eReady=0,
  20. eRunning
  21. };
  22. public:
  23. Navigation();
  24. ~Navigation();
  25. //连接AGV emqx服务
  26. bool Init(const Navigation_parameter& parameter);
  27. void ResetPose(const Pose2d& pose);
  28. void ResetStatu(double v,double a);
  29. TimedLockData<Pose2d>& RealTimePose(){
  30. return timedPose_;
  31. }
  32. TimedLockData<double>& RealTimeV(){
  33. return timedV_;
  34. }
  35. TimedLockData<double>& RealTimeA(){
  36. return timedA_;
  37. }
  38. bool Start(const NavMessage::NavCmd& cmd);
  39. void Cancel();
  40. void Pause();
  41. protected:
  42. static void RobotStatuCallback(double x,double y,double theta,double v,double vth,void* context);
  43. static void NavCmdCallback(const MqttMsg& msg,void* context);
  44. static void BrotherAgvStatuCallback(const MqttMsg& msg,void* context);
  45. static bool IsArrived(const Pose2d& cur,double velocity,double angular,const Pose2d& target,const Pose2d& diff);
  46. bool execute_along_action(const Pose2d& target,const Pose2d& target_diff);
  47. bool exec_adjust_action(const Pose2d& target,const Pose2d& target_diff);
  48. bool mpc_once(const Trajectory& traj,std::vector<double>& out);
  49. void navigatting();
  50. /*
  51. * 发布导航模块状态
  52. */
  53. void publish_statu();
  54. protected:
  55. std::mutex mtx_;
  56. bool exit_=false;
  57. std::thread* pubthread_= nullptr;
  58. bool inited_=false;
  59. Monitor_emqx* monitor_= nullptr;
  60. Terminator_emqx* terminator_= nullptr;
  61. TimedLockData<Pose2d> timedPose_; //当前位姿
  62. TimedLockData<double> timedV_; //底盘数据
  63. TimedLockData<double> timedA_;
  64. TimedLockData<Pose2d> timedBrotherPose_; //当前位姿
  65. TimedLockData<double> timedBrotherV_; //底盘数据
  66. TimedLockData<double> timedBrotherA_;
  67. NavMessage::NavCmd global_navCmd_; //导航任务,包含一系列动作
  68. std::queue<NavMessage::Action> unfinished_cations_; //未完成的动作
  69. std::thread* thread_= nullptr;
  70. bool running_=false;
  71. bool pause_=false;
  72. bool cancel_=false;
  73. TimedLockData<Trajectory> selected_traj_;
  74. TimedLockData<Trajectory> predict_traj_;
  75. Navigation_parameter parameter_;
  76. };
  77. #endif //LIO_LIVOX_CPP_MPC_NAVIGATION_H_