vehicle_control.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #ifndef VEHICLE_CONTROL_H
  2. #define VEHICLE_CONTROL_H
  3. #include <QObject>
  4. #include <QTimer>
  5. #include <QDateTime>
  6. #include <QVector>
  7. #include <QThread>
  8. #include <iostream>
  9. #include <memory>
  10. #include <string>
  11. #include <yaml-cpp/yaml.h>
  12. #include <grpcpp/grpcpp.h>
  13. #include "VehicleControl_service.grpc.pb.h"
  14. #include "VehicleControl.grpc.pb.h"
  15. #ifndef IV_MSGUNIT
  16. #define IV_MSGUNIT
  17. namespace iv {
  18. struct msgunit
  19. {
  20. char mstrmsgname[256];
  21. int mnBufferSize = 10000;
  22. int mnBufferCount = 1;
  23. void * mpa = nullptr;
  24. std::shared_ptr<char> mpstrmsgdata;
  25. int mndatasize = 0;
  26. bool mbRefresh = false;
  27. bool mbImportant = false;
  28. int mnkeeptime = 100;
  29. };
  30. }
  31. #endif
  32. using grpc::Channel;
  33. using grpc::ClientContext;
  34. using grpc::Status;
  35. using org::jeecg::defsControl::grpc::VehicleControl; ///< service name
  36. using org::jeecg::defsControl::grpc::ControlReply; ///< rpc fuction parameter and return
  37. using org::jeecg::defsControl::grpc::UploadMapReply;
  38. using org::jeecg::defsControl::grpc::CtrlModeReply;
  39. class VehicleControlClient : public QThread{
  40. Q_OBJECT
  41. public:
  42. VehicleControlClient(std::shared_ptr<Channel> channel);
  43. ~VehicleControlClient(void);
  44. std::string vehicleControl(void);
  45. void updateControlData(void);
  46. void dec_yaml(const char * stryamlpath);
  47. protected:
  48. void run();
  49. private:
  50. std::unique_ptr<VehicleControl::Stub> stub_;
  51. iv::msgunit shmRemoteCtrl;
  52. org::jeecg::defsControl::grpc::ShiftStatus shiftCMD = org::jeecg::defsControl::grpc::ShiftStatus::SHIFT_PARKING;
  53. double steeringWheelAngleCMD = 0;
  54. double throttleCMD = 0;
  55. double brakeCMD = 0;
  56. org::jeecg::defsControl::grpc::CtrlMode modeCMD = org::jeecg::defsControl::grpc::CtrlMode::CMD_AUTO; ///< update by slot function
  57. public slots:
  58. void ctrlMode_Changed_Slot(org::jeecg::defsControl::grpc::CtrlMode ctrlMode);
  59. };
  60. class VehicleChangeCtrlModeClient : public QThread{
  61. Q_OBJECT
  62. public:
  63. VehicleChangeCtrlModeClient(std::shared_ptr<Channel> channel);
  64. ~VehicleChangeCtrlModeClient(void);
  65. std::string changeCtrlMode(void);
  66. void updateCtrolMode(void);
  67. protected:
  68. void run();
  69. private:
  70. std::unique_ptr<VehicleControl::Stub> stub_;
  71. org::jeecg::defsControl::grpc::CtrlMode modeChangeCMD = org::jeecg::defsControl::grpc::CtrlMode::CMD_AUTO;
  72. org::jeecg::defsControl::grpc::UseStatus useStatusCMD = org::jeecg::defsControl::grpc::UseStatus::ENABLING;//使用状态修改命令
  73. org::jeecg::defsControl::grpc::GPSPoint deactivatePosition; //停用站点
  74. double speedCMD = 0.0; //平台设定的期望运行速度
  75. org::jeecg::defsControl::grpc::NavSwitch navagationSwitch = org::jeecg::defsControl::grpc::NavSwitch::NAV_STOP; //开始-停止导航
  76. signals:
  77. void ctrlMode_Changed(org::jeecg::defsControl::grpc::CtrlMode ctrlMode);
  78. void remoteCtrlModeChanged(bool status);
  79. // void navagationSwitchChanged(bool status);
  80. void useStatusCMDChanged(bool status);
  81. };
  82. class VehicleUploadMapClient : public QThread{
  83. Q_OBJECT
  84. public:
  85. VehicleUploadMapClient(std::shared_ptr<Channel> channel);
  86. ~VehicleUploadMapClient(void);
  87. std::string uploadMap(void);
  88. void updateMapPOIData(void);
  89. protected:
  90. void run();
  91. private:
  92. std::unique_ptr<VehicleControl::Stub> stub_;
  93. bool isNeedMap = false;
  94. std::string patrolPathID;
  95. QVector<org::jeecg::defsControl::grpc::MapPoint> POIPoints;
  96. bool allowPlan = true;
  97. signals:
  98. void patrolPOI_Recieved(std::string pathID);
  99. void navagationSwitchChanged(bool status);
  100. public slots:
  101. void uploadPath_Finished_Slot(std::string pathID);
  102. void setAllowPlan_Slot(bool isAllow);
  103. };
  104. #endif // VEHICLE_CONTROL_H