monitor_emqx.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // Created by zx on 23-3-14.
  3. //
  4. #include "monitor_emqx.h"
  5. #include <math.h>
  6. #include <unistd.h>
  7. Monitor_emqx::Monitor_emqx(std::string nodeId)
  8. : Terminator_emqx(nodeId)
  9. {
  10. heat_=0;
  11. }
  12. Monitor_emqx::~Monitor_emqx()
  13. {
  14. }
  15. void Monitor_emqx::set_speedcmd_topic(std::string speedcmd)
  16. {
  17. speedcmd_topic_=speedcmd;
  18. }
  19. void Monitor_emqx::clamp_close(ActionMode mode)
  20. {
  21. MqttMsg msg;
  22. NavMessage::ToAgvCmd speed;
  23. heat_=(heat_+1)%255;
  24. speed.set_h(heat_);
  25. speed.set_t(eClampClode);
  26. speed.set_m(mode);
  27. speed.set_end(1);
  28. msg.fromProtoMessage(speed);
  29. Publish(speedcmd_topic_,msg);
  30. }
  31. void Monitor_emqx::clamp_open(ActionMode mode)
  32. {
  33. MqttMsg msg;
  34. NavMessage::ToAgvCmd speed;
  35. heat_=(heat_+1)%255;
  36. speed.set_h(heat_);
  37. speed.set_t(eClampOpen);
  38. speed.set_m(mode);
  39. speed.set_end(1);
  40. msg.fromProtoMessage(speed);
  41. Publish(speedcmd_topic_,msg);
  42. }
  43. void Monitor_emqx::set_speed(ActionMode mode,ActionType type,double v,double a,double L)
  44. {
  45. if(mode==eMain && type==eVertical &&fabs(L)<1e-3)
  46. {
  47. printf(" Main agv mpc must set wheelBase\n ");
  48. return;
  49. }
  50. double w=fabs(a)>0.001?a:0.0;
  51. double velocity=fabs(v)>0.001?v:0;
  52. MqttMsg msg;
  53. NavMessage::ToAgvCmd speed;
  54. heat_=(heat_+1)%255;
  55. speed.set_h(heat_);
  56. speed.set_t(type);
  57. speed.set_v(velocity);
  58. speed.set_w(w);
  59. speed.set_l(L);
  60. speed.set_m(mode);
  61. speed.set_end(1);
  62. msg.fromProtoMessage(speed);
  63. Publish(speedcmd_topic_,msg);
  64. }
  65. void Monitor_emqx::set_speed(ActionMode mode,ActionType type,double v,double a)
  66. {
  67. double w=fabs(a)>0.0001?a:0.0;
  68. MqttMsg msg;
  69. NavMessage::ToAgvCmd speed;
  70. heat_=(heat_+1)%255;
  71. speed.set_h(heat_);
  72. speed.set_t(type);
  73. speed.set_v(v);
  74. speed.set_w(w);
  75. speed.set_m(mode);
  76. speed.set_end(1);
  77. msg.fromProtoMessage(speed);
  78. Publish(speedcmd_topic_,msg);
  79. }
  80. void Monitor_emqx::stop()
  81. {
  82. MqttMsg msg;
  83. NavMessage::ToAgvCmd speed;
  84. heat_=(heat_+1)%255;
  85. speed.set_h(heat_);
  86. speed.set_t(eStop);
  87. speed.set_v(0);
  88. speed.set_w(0);
  89. speed.set_end(1);
  90. msg.fromProtoMessage(speed);
  91. Publish(speedcmd_topic_,msg);
  92. }