dispatch_manager.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // Created by huli on 2020/7/20.
  3. //
  4. #ifndef NNXX_TESTS_DISPATCH_MANAGER_H
  5. #define NNXX_TESTS_DISPATCH_MANAGER_H
  6. #include "../error_code/error_code.h"
  7. #include "../communication/communication_message.h"
  8. #include "../system/system_communication.h"
  9. #include "../tool/singleton.h"
  10. #include "../tool/thread_condition.h"
  11. #include "../tool/TaskQueue/TQFactory.h"
  12. #include "../tool/TaskQueue/BaseTask.h"
  13. //#include "../dispatch/carrier.h"
  14. //#include "../dispatch/catcher.h"
  15. //#include "../dispatch/passageway.h"
  16. //#include "../dispatch/dispatch_process.h"
  17. #include "../message/dispatch_control.pb.h"
  18. #include "../message/dispatch_message.pb.h"
  19. #include "../dispatch/dispatch_parameter.pb.h"
  20. #include "../dispatch/dispatch_plc.h"
  21. #include "../message/measure_message.pb.h"
  22. #include <vector>
  23. #include <glog/logging.h>
  24. #include <atomic>
  25. //lacate测量结果结构体, 整车的信息,
  26. typedef struct Locate_information
  27. {
  28. float locate_x; //整车的中心点x值, 四轮的中心
  29. float locate_y; //整车的中心点y值, 四轮的中心
  30. float locate_angle; //整车的旋转角, 四轮的旋转角
  31. float locate_length; //整车的长度, 用于规避碰撞
  32. float locate_width; //整车的宽度, 用于规避碰撞
  33. float locate_height; //整车的高度, 用于规避碰撞
  34. float locate_wheel_base; //整车的轮距, 前后轮的距离, 用于机器人或agv的抓车
  35. float locate_wheel_width; //整车的轮距, 左右轮的距离, 用于机器人或agv的抓车
  36. bool locate_correct; //整车的校准标记位
  37. //注:理论上, 车宽和左右轮距应该是一样的, 但是实际上车宽比左右轮距略大,
  38. }Locate_information;
  39. //调度管理模块
  40. class Dispatch_manager:public Singleton<Dispatch_manager>
  41. {
  42. // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
  43. friend class Singleton<Dispatch_manager>;
  44. public:
  45. //调度设备参数
  46. #define DISPATCH_DEVICE_PARAMETER_PATH "../setting/dispatch_device.prototxt"
  47. //存车任务数量的限制, 大于等于限则, 则使用缓存位, 默认5个
  48. #define DISPATCH_MANAHER_STORE_LIST_SIZE_LIMIT 5
  49. //调度管理 的状态
  50. enum Dispatch_manager_status
  51. {
  52. E_DISPATCH_MANAGER_UNKNOW = 0, //未知
  53. E_DISPATCH_MANAGER_READY = 1, //准备,待机
  54. E_DISPATCH_MANAGER_STORE = 2, //正在存车
  55. E_DISPATCH_MANAGER_PICKUP = 3, //正在取车
  56. E_DISPATCH_MANAGER_FAULT = 100, //故障
  57. };
  58. //调度方向, 停车取车
  59. enum Dispatch_motion_direction
  60. {
  61. E_STORE_CAR =0, //停车, 出入口 -> 停车位
  62. E_PICKUP_CAR =1, //取车, 停车位 -> 出入口
  63. };
  64. private:
  65. // 父类的构造函数必须保护,子类的构造函数必须私有。
  66. Dispatch_manager();
  67. public:
  68. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  69. Dispatch_manager(const Dispatch_manager& other) = delete;
  70. Dispatch_manager& operator =(const Dispatch_manager& other) = delete;
  71. ~Dispatch_manager();
  72. public://API functions
  73. //调度管理 初始化
  74. Error_manager dispatch_manager_init(int dispatch_manager_id);
  75. Error_manager dispatch_manager_init();
  76. //初始化 调度管理 模块。从文件读取
  77. Error_manager dispatch_manager_init_from_protobuf(std::string prototxt_path);
  78. //初始化 调度管理 模块。从protobuf读取
  79. Error_manager dispatch_manager_init_from_protobuf(Dispatch_proto::Dispatch_device_parameter_all& dispatch_device_parameter_all);
  80. //调度管理 反初始化
  81. Error_manager dispatch_manager_uninit();
  82. //调度管理 设备复位
  83. Error_manager dispatch_manager_device_reset();
  84. //对外的接口函数,负责接受并处理任务单,
  85. Error_manager execute_task(Dispatch_manager::Dispatch_motion_direction dispatch_motion_direction);
  86. //检查能否执行消息指令
  87. Error_manager check_execute_msg(Communication_message* p_msg);
  88. //检查状态
  89. Error_manager check_status();
  90. //调度模块 //执行搬运请求(主控->调度管理)
  91. Error_manager execute_for_dispatch_request_msg(message::Dispatch_request_msg &dispatch_request_msg);
  92. //调度模块 答复数据异常
  93. Error_manager send_dispatch_response_msg_with_error(message::Dispatch_request_msg &dispatch_request_msg, Error_manager error);
  94. //调度模块 //调度总规划的答复(调度算法->调度管理)
  95. Error_manager execute_for_dispatch_plan_response_msg(message::Dispatch_plan_response_msg &dispatch_plan_response_msg);
  96. //调度模块 //调度控制的任务请求(调度算法->调度管理)
  97. Error_manager execute_for_dispatch_control_request_msg(message::Dispatch_control_request_msg &dispatch_control_request_msg);
  98. //定时发送 调度管理的状态
  99. Error_manager encapsulate_send_dispatch_manager_status();
  100. //在流程的map 里面释放指定的流程
  101. Error_manager release_dispatch_process(std::string command_key);
  102. //调度模块 ///地面雷达的状态消息(地面雷达->null)
  103. Error_manager execute_for_ground_status_msg(message::Ground_status_msg ground_status_msg);
  104. public://get or set member variable
  105. Dispatch_manager_status get_dispatch_manager_status();
  106. int get_dispatch_manager_id();
  107. void set_dispatch_manager_id(int dispatch_id);
  108. protected:
  109. //资源分配
  110. void resource_allocation();
  111. public://member variable
  112. Dispatch_manager_status m_dispatch_manager_status; //调度管理 的状态
  113. int m_dispatch_manager_id; //调度模块的id, (楚天项目就是单元号, 0~2)
  114. //流程控制
  115. std::mutex m_lock; //线程池的锁, 增删流程时要加锁.
  116. //调度plc
  117. Dispatch_plc m_dispatch_plc; //调度plc
  118. //请求指令的list, 按照创建顺序排序, 先来后到, 停车和停车不能插队, 但是停车和取车可以插队.
  119. std::list<message::Dispatch_request_msg> m_dispatch_request_store_list; //存车请求指令的list, 内存由线程池管理
  120. std::list<message::Dispatch_request_msg> m_dispatch_request_pickup_list; //取车请求指令的list, 内存由线程池管理
  121. Common_data::Dispatch_motion_direction m_dispatch_motion_direction_next; //下一次的调度方向, 保证存车取车交替进行
  122. //调度总管理的线程, 负责资源分配
  123. std::thread* m_dispatch_manager_thread; //调度总管理的线程, 总控全局, 控制每个流程的先后顺序, 并合理的分配资源.
  124. Thread_condition m_dispatch_manager_condition; //调度总管理的条件变量, 总控全局, 控制每个流程的先后顺序, 并合理的分配资源.
  125. private:
  126. };
  127. #endif //NNXX_TESTS_DISPATCH_MANAGER_H