navigation.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. eRotate=0,
  20. eLine,
  21. eMPC
  22. };
  23. public:
  24. Navigation();
  25. ~Navigation();
  26. //连接AGV emqx服务
  27. bool Init(const Navigation_parameter& parameter);
  28. void ResetPose(const Pose2d& pose);
  29. void ResetStatu(double v,double a);
  30. TimedLockData<Pose2d>& RealTimePose(){
  31. return timedPose_;
  32. }
  33. TimedLockData<double>& RealTimeV(){
  34. return timedV_;
  35. }
  36. TimedLockData<double>& RealTimeA(){
  37. return timedA_;
  38. }
  39. bool Start(std::queue<Trajectory> global_trajectorys);
  40. void Cancel();
  41. void Pause();
  42. protected:
  43. static void RobotStatuCallback(double x,double y,double theta,double v,double vth,void* context);
  44. static void NavCmdCallback(const NavCmd& cmd,void* context);
  45. static bool IsArrived(const Pose2d& cur,double speed,const Pose2d& target,const Pose2d& diff);
  46. bool execute_edge(const Trajectory& child,const Pose2d& head_diff,const Pose2d& target_diff);
  47. bool moveToPoint(const Pose2d& pose,const Pose2d& distance);
  48. bool mpc_once(const Trajectory& traj,std::vector<double>& out);
  49. void navigatting();
  50. /*
  51. * 发布导航模块状态,当前动作类型、角速度、线速度
  52. */
  53. void publish_statu(ActionType type,float velocity,float angular);
  54. protected:
  55. std::mutex mtx_;
  56. bool inited_=false;
  57. Monitor_emqx* monitor_= nullptr;
  58. Terminator_emqx* terminator_= nullptr;
  59. TimedLockData<Pose2d> timedPose_; //当前位姿
  60. TimedLockData<double> timedV_; //底盘数据
  61. TimedLockData<double> timedA_;
  62. std::queue<Trajectory> global_trajectorys_; //多段轨迹
  63. std::thread* thread_= nullptr;
  64. bool running_=false;
  65. bool pause_=false;
  66. bool cancel_=false;
  67. TimedLockData<Trajectory> selected_traj_;
  68. TimedLockData<Trajectory> predict_traj_;
  69. };
  70. #endif //LIO_LIVOX_CPP_MPC_NAVIGATION_H_