vehicle_control.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 modeCMD = 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. };
  79. class VehicleUploadMapClient : public QThread{
  80. Q_OBJECT
  81. public:
  82. VehicleUploadMapClient(std::shared_ptr<Channel> channel);
  83. ~VehicleUploadMapClient(void);
  84. std::string uploadMap(void);
  85. void updateMapPOIData(void);
  86. protected:
  87. void run();
  88. private:
  89. std::unique_ptr<VehicleControl::Stub> stub_;
  90. bool isNeedMap = false;
  91. std::string patrolPathID;
  92. QVector<org::jeecg::defsControl::grpc::MapPoint> POIPoints;
  93. signals:
  94. void patrolPOI_Recieved(std::string pathID);
  95. public slots:
  96. void uploadPath_Finished_Slot(std::string pathID);
  97. };
  98. #endif // VEHICLE_CONTROL_H