robot.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /**
  2. * space_server 机器人管理。
  3. *
  4. * © 2020 成都河狸智能科技有限责任公司。保留所有权利。
  5. *
  6. * 作者: zhq1229
  7. */
  8. #ifndef __ROBOT_H__
  9. #define __ROBOT_H__
  10. #include <space_lib/space_lib.h>
  11. #include "task/task.h"
  12. using RobotId = unsigned int;
  13. namespace robot {
  14. enum RobotState {
  15. INIT = 0,
  16. PROTCET,
  17. IDLE,
  18. WORKING,
  19. FAULT,
  20. LOW_POWER,
  21. SCANNING,
  22. __ROBOT_STATE_SIZE,
  23. };
  24. enum LocateMode {
  25. QUIT = 0,
  26. FAST,
  27. EXACT,
  28. CALIBRATION
  29. };
  30. struct BatteryInfo {
  31. BatteryInfo():
  32. soc(0.0f),
  33. voltage(0.0f),
  34. current(0.0f),
  35. is_charging(false) {}
  36. float soc;
  37. float voltage;
  38. float current;
  39. bool is_charging;
  40. };
  41. struct PositionInfo {
  42. PositionInfo():
  43. map_id(0),
  44. locate_map_id(0),
  45. x(0.0f),
  46. y(0.0f),
  47. yaw(0.0f),
  48. is_located(false),
  49. p_ts(0) {}
  50. MapId map_id;
  51. MapId locate_map_id;
  52. float x;
  53. float y;
  54. float yaw;
  55. bool is_located;
  56. unsigned long long p_ts;
  57. };
  58. struct BasicInfo {
  59. BasicInfo():
  60. max_x(0.0f),
  61. max_y(0.0f),
  62. max_yaw(0.0f) {}
  63. float max_x;
  64. float max_y;
  65. float max_yaw;
  66. };
  67. struct ScanInfo {
  68. ScanInfo():
  69. map_id(0),
  70. is_scaning(false),
  71. name(""),
  72. floor(0),
  73. width(0),
  74. height(0),
  75. x_origin(0.0f),
  76. y_origin(0.0f),
  77. resolution(0.0f),
  78. occupied_thresh(0.65f),
  79. free_thresh(0.196f),
  80. map_resolution("0.05") {}
  81. MapId map_id;
  82. bool is_scaning;
  83. std::string name;
  84. int floor;
  85. int width;
  86. int height;
  87. float x_origin;
  88. float y_origin;
  89. float resolution;
  90. float occupied_thresh;
  91. float free_thresh;
  92. std::string map_resolution;
  93. };
  94. struct RobotInfo {
  95. RobotInfo():
  96. id(0),
  97. name("null"),
  98. addr("null"),
  99. info("null"),
  100. state(IDLE),
  101. emcy(0) {}
  102. RobotId id;
  103. std::string name;
  104. std::string addr;
  105. std::string info;
  106. RobotState state;
  107. unsigned int emcy; // [0:0]-急停 [1:1]-调度急停 [2:2]-通信中断急停 [8:15]-客户急停
  108. BatteryInfo battery;
  109. PositionInfo position;
  110. BasicInfo basic;
  111. ScanInfo scan;
  112. Json::Value additional;
  113. };
  114. struct Pose {
  115. Pose(float xi, float yi, float thetai) :
  116. x(xi),y(yi),theta(thetai) {}
  117. Pose() = default;
  118. float x;
  119. float y;
  120. float theta;
  121. };
  122. int setVel(float x, float y, float yaw);
  123. int setEmcy(unsigned int emcy);
  124. int quitEmcy(unsigned int emcy);
  125. int setLocate(MapId map_id, int mode, float x, float y, float yaw);
  126. int quitLocate();
  127. int setScan(std::string name, int floor);
  128. int quitScan();
  129. int setAdditional(std::string key, Json::Value &value);
  130. RobotInfo robotInfo();
  131. RobotId robotId();
  132. RobotState robotState();
  133. MapId robotMapId();
  134. MapId scanId();
  135. PositionInfo positionInfo();
  136. bool isCharging();
  137. Json::Value additionalInfo();
  138. int init(Json::Value &conf);
  139. int shutdown();
  140. Pose globalTransLocal(Pose a, Pose b);
  141. Pose localTransGlobal(Pose a, Pose b);
  142. Pose clcTrans(Pose a, Pose b);
  143. Pose trans();
  144. } // namespace robot
  145. #endif // __ROBOT_H__