rplidar_cmd.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * RPLIDAR SDK
  3. *
  4. * Copyright (c) 2009 - 2014 RoboPeak Team
  5. * http://www.robopeak.com
  6. * Copyright (c) 2014 - 2019 Shanghai Slamtec Co., Ltd.
  7. * http://www.slamtec.com
  8. *
  9. */
  10. /*
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. *
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  24. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  25. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  28. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  30. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  31. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. #pragma once
  35. #include "rplidar_protocol.h"
  36. // Commands
  37. //-----------------------------------------
  38. // Commands without payload and response
  39. #define RPLIDAR_CMD_STOP 0x25
  40. #define RPLIDAR_CMD_SCAN 0x20
  41. #define RPLIDAR_CMD_FORCE_SCAN 0x21
  42. #define RPLIDAR_CMD_RESET 0x40
  43. // Commands without payload but have response
  44. #define RPLIDAR_CMD_GET_DEVICE_INFO 0x50
  45. #define RPLIDAR_CMD_GET_DEVICE_HEALTH 0x52
  46. #define RPLIDAR_CMD_GET_SAMPLERATE 0x59 //added in fw 1.17
  47. #define RPLIDAR_CMD_HQ_MOTOR_SPEED_CTRL 0xA8
  48. // Commands with payload and have response
  49. #define RPLIDAR_CMD_EXPRESS_SCAN 0x82 //added in fw 1.17
  50. #define RPLIDAR_CMD_HQ_SCAN 0x83 //added in fw 1.24
  51. #define RPLIDAR_CMD_GET_LIDAR_CONF 0x84 //added in fw 1.24
  52. #define RPLIDAR_CMD_SET_LIDAR_CONF 0x85 //added in fw 1.24
  53. //add for A2 to set RPLIDAR motor pwm when using accessory board
  54. #define RPLIDAR_CMD_SET_MOTOR_PWM 0xF0
  55. #define RPLIDAR_CMD_GET_ACC_BOARD_FLAG 0xFF
  56. #if defined(_WIN32)
  57. #pragma pack(1)
  58. #endif
  59. // Payloads
  60. // ------------------------------------------
  61. #define RPLIDAR_EXPRESS_SCAN_MODE_NORMAL 0
  62. #define RPLIDAR_EXPRESS_SCAN_MODE_FIXANGLE 0 // won't been supported but keep to prevent build fail
  63. //for express working flag(extending express scan protocol)
  64. #define RPLIDAR_EXPRESS_SCAN_FLAG_BOOST 0x0001
  65. #define RPLIDAR_EXPRESS_SCAN_FLAG_SUNLIGHT_REJECTION 0x0002
  66. //for ultra express working flag
  67. #define RPLIDAR_ULTRAEXPRESS_SCAN_FLAG_STD 0x0001
  68. #define RPLIDAR_ULTRAEXPRESS_SCAN_FLAG_HIGH_SENSITIVITY 0x0002
  69. #define RPLIDAR_HQ_SCAN_FLAG_CCW (0x1<<0)
  70. #define RPLIDAR_HQ_SCAN_FLAG_RAW_ENCODER (0x1<<1)
  71. #define RPLIDAR_HQ_SCAN_FLAG_RAW_DISTANCE (0x1<<2)
  72. typedef struct _rplidar_payload_express_scan_t {
  73. _u8 working_mode;
  74. _u16 working_flags;
  75. _u16 param;
  76. } __attribute__((packed)) rplidar_payload_express_scan_t;
  77. typedef struct _rplidar_payload_hq_scan_t {
  78. _u8 flag;
  79. _u8 reserved[32];
  80. } __attribute__((packed)) rplidar_payload_hq_scan_t;
  81. typedef struct _rplidar_payload_get_scan_conf_t {
  82. _u32 type;
  83. _u8 reserved[32];
  84. } __attribute__((packed)) rplidar_payload_get_scan_conf_t;
  85. #define MAX_MOTOR_PWM 1023
  86. #define DEFAULT_MOTOR_PWM 660
  87. typedef struct _rplidar_payload_motor_pwm_t {
  88. _u16 pwm_value;
  89. } __attribute__((packed)) rplidar_payload_motor_pwm_t;
  90. typedef struct _rplidar_payload_acc_board_flag_t {
  91. _u32 reserved;
  92. } __attribute__((packed)) rplidar_payload_acc_board_flag_t;
  93. typedef struct _rplidar_payload_hq_spd_ctrl_t {
  94. _u16 rpm;
  95. } __attribute__((packed)) rplidar_payload_hq_spd_ctrl_t;
  96. // Response
  97. // ------------------------------------------
  98. #define RPLIDAR_ANS_TYPE_DEVINFO 0x4
  99. #define RPLIDAR_ANS_TYPE_DEVHEALTH 0x6
  100. #define RPLIDAR_ANS_TYPE_MEASUREMENT 0x81
  101. // Added in FW ver 1.17
  102. #define RPLIDAR_ANS_TYPE_MEASUREMENT_CAPSULED 0x82
  103. #define RPLIDAR_ANS_TYPE_MEASUREMENT_HQ 0x83
  104. // Added in FW ver 1.17
  105. #define RPLIDAR_ANS_TYPE_SAMPLE_RATE 0x15
  106. //added in FW ver 1.23alpha
  107. #define RPLIDAR_ANS_TYPE_MEASUREMENT_CAPSULED_ULTRA 0x84
  108. //added in FW ver 1.24
  109. #define RPLIDAR_ANS_TYPE_GET_LIDAR_CONF 0x20
  110. #define RPLIDAR_ANS_TYPE_SET_LIDAR_CONF 0x21
  111. #define RPLIDAR_ANS_TYPE_MEASUREMENT_DENSE_CAPSULED 0x85
  112. #define RPLIDAR_ANS_TYPE_ACC_BOARD_FLAG 0xFF
  113. #define RPLIDAR_RESP_ACC_BOARD_FLAG_MOTOR_CTRL_SUPPORT_MASK (0x1)
  114. typedef struct _rplidar_response_acc_board_flag_t {
  115. _u32 support_flag;
  116. } __attribute__((packed)) rplidar_response_acc_board_flag_t;
  117. #define RPLIDAR_STATUS_OK 0x0
  118. #define RPLIDAR_STATUS_WARNING 0x1
  119. #define RPLIDAR_STATUS_ERROR 0x2
  120. #define RPLIDAR_RESP_MEASUREMENT_SYNCBIT (0x1<<0)
  121. #define RPLIDAR_RESP_MEASUREMENT_QUALITY_SHIFT 2
  122. #define RPLIDAR_RESP_HQ_FLAG_SYNCBIT (0x1<<0)
  123. #define RPLIDAR_RESP_MEASUREMENT_CHECKBIT (0x1<<0)
  124. #define RPLIDAR_RESP_MEASUREMENT_ANGLE_SHIFT 1
  125. typedef struct _rplidar_response_sample_rate_t {
  126. _u16 std_sample_duration_us;
  127. _u16 express_sample_duration_us;
  128. } __attribute__((packed)) rplidar_response_sample_rate_t;
  129. typedef struct _rplidar_response_measurement_node_t {
  130. _u8 sync_quality; // syncbit:1;syncbit_inverse:1;quality:6;
  131. _u16 angle_q6_checkbit; // check_bit:1;angle_q6:15;
  132. _u16 distance_q2;
  133. } __attribute__((packed)) rplidar_response_measurement_node_t;
  134. //[distance_sync flags]
  135. #define RPLIDAR_RESP_MEASUREMENT_EXP_ANGLE_MASK (0x3)
  136. #define RPLIDAR_RESP_MEASUREMENT_EXP_DISTANCE_MASK (0xFC)
  137. typedef struct _rplidar_response_cabin_nodes_t {
  138. _u16 distance_angle_1; // see [distance_sync flags]
  139. _u16 distance_angle_2; // see [distance_sync flags]
  140. _u8 offset_angles_q3;
  141. } __attribute__((packed)) rplidar_response_cabin_nodes_t;
  142. #define RPLIDAR_RESP_MEASUREMENT_EXP_SYNC_1 0xA
  143. #define RPLIDAR_RESP_MEASUREMENT_EXP_SYNC_2 0x5
  144. #define RPLIDAR_RESP_MEASUREMENT_HQ_SYNC 0xA5
  145. #define RPLIDAR_RESP_MEASUREMENT_EXP_SYNCBIT (0x1<<15)
  146. typedef struct _rplidar_response_capsule_measurement_nodes_t {
  147. _u8 s_checksum_1; // see [s_checksum_1]
  148. _u8 s_checksum_2; // see [s_checksum_1]
  149. _u16 start_angle_sync_q6;
  150. rplidar_response_cabin_nodes_t cabins[16];
  151. } __attribute__((packed)) rplidar_response_capsule_measurement_nodes_t;
  152. typedef struct _rplidar_response_dense_cabin_nodes_t {
  153. _u16 distance;
  154. } __attribute__((packed)) rplidar_response_dense_cabin_nodes_t;
  155. typedef struct _rplidar_response_dense_capsule_measurement_nodes_t {
  156. _u8 s_checksum_1; // see [s_checksum_1]
  157. _u8 s_checksum_2; // see [s_checksum_1]
  158. _u16 start_angle_sync_q6;
  159. rplidar_response_dense_cabin_nodes_t cabins[40];
  160. } __attribute__((packed)) rplidar_response_dense_capsule_measurement_nodes_t;
  161. // ext1 : x2 boost mode
  162. #define RPLIDAR_RESP_MEASUREMENT_EXP_ULTRA_MAJOR_BITS 12
  163. #define RPLIDAR_RESP_MEASUREMENT_EXP_ULTRA_PREDICT_BITS 10
  164. typedef struct _rplidar_response_ultra_cabin_nodes_t {
  165. // 31 0
  166. // | predict2 10bit | predict1 10bit | major 12bit |
  167. _u32 combined_x3;
  168. } __attribute__((packed)) rplidar_response_ultra_cabin_nodes_t;
  169. typedef struct _rplidar_response_ultra_capsule_measurement_nodes_t {
  170. _u8 s_checksum_1; // see [s_checksum_1]
  171. _u8 s_checksum_2; // see [s_checksum_1]
  172. _u16 start_angle_sync_q6;
  173. rplidar_response_ultra_cabin_nodes_t ultra_cabins[32];
  174. } __attribute__((packed)) rplidar_response_ultra_capsule_measurement_nodes_t;
  175. typedef struct rplidar_response_measurement_node_hq_t {
  176. _u16 angle_z_q14;
  177. _u32 dist_mm_q2;
  178. _u8 quality;
  179. _u8 flag;
  180. } __attribute__((packed)) rplidar_response_measurement_node_hq_t;
  181. typedef struct _rplidar_response_hq_capsule_measurement_nodes_t{
  182. _u8 sync_byte;
  183. _u64 time_stamp;
  184. rplidar_response_measurement_node_hq_t node_hq[16];
  185. _u32 crc32;
  186. }__attribute__((packed)) rplidar_response_hq_capsule_measurement_nodes_t;
  187. # define RPLIDAR_CONF_SCAN_COMMAND_STD 0
  188. # define RPLIDAR_CONF_SCAN_COMMAND_EXPRESS 1
  189. # define RPLIDAR_CONF_SCAN_COMMAND_HQ 2
  190. # define RPLIDAR_CONF_SCAN_COMMAND_BOOST 3
  191. # define RPLIDAR_CONF_SCAN_COMMAND_STABILITY 4
  192. # define RPLIDAR_CONF_SCAN_COMMAND_SENSITIVITY 5
  193. #define RPLIDAR_CONF_ANGLE_RANGE 0x00000000
  194. #define RPLIDAR_CONF_DESIRED_ROT_FREQ 0x00000001
  195. #define RPLIDAR_CONF_SCAN_COMMAND_BITMAP 0x00000002
  196. #define RPLIDAR_CONF_MIN_ROT_FREQ 0x00000004
  197. #define RPLIDAR_CONF_MAX_ROT_FREQ 0x00000005
  198. #define RPLIDAR_CONF_MAX_DISTANCE 0x00000060
  199. #define RPLIDAR_CONF_SCAN_MODE_COUNT 0x00000070
  200. #define RPLIDAR_CONF_SCAN_MODE_US_PER_SAMPLE 0x00000071
  201. #define RPLIDAR_CONF_SCAN_MODE_MAX_DISTANCE 0x00000074
  202. #define RPLIDAR_CONF_SCAN_MODE_ANS_TYPE 0x00000075
  203. #define RPLIDAR_CONF_SCAN_MODE_TYPICAL 0x0000007C
  204. #define RPLIDAR_CONF_SCAN_MODE_NAME 0x0000007F
  205. #define RPLIDAR_EXPRESS_SCAN_STABILITY_BITMAP 4
  206. #define RPLIDAR_EXPRESS_SCAN_SENSITIVITY_BITMAP 5
  207. typedef struct _rplidar_response_get_lidar_conf{
  208. _u32 type;
  209. _u8 payload[0];
  210. }__attribute__((packed)) rplidar_response_get_lidar_conf_t;
  211. typedef struct _rplidar_response_set_lidar_conf{
  212. _u32 result;
  213. }__attribute__((packed)) rplidar_response_set_lidar_conf_t;
  214. typedef struct _rplidar_response_device_info_t {
  215. _u8 model;
  216. _u16 firmware_version;
  217. _u8 hardware_version;
  218. _u8 serialnum[16];
  219. } __attribute__((packed)) rplidar_response_device_info_t;
  220. typedef struct _rplidar_response_device_health_t {
  221. _u8 status;
  222. _u16 error_code;
  223. } __attribute__((packed)) rplidar_response_device_health_t;
  224. // Definition of the variable bit scale encoding mechanism
  225. #define RPLIDAR_VARBITSCALE_X2_SRC_BIT 9
  226. #define RPLIDAR_VARBITSCALE_X4_SRC_BIT 11
  227. #define RPLIDAR_VARBITSCALE_X8_SRC_BIT 12
  228. #define RPLIDAR_VARBITSCALE_X16_SRC_BIT 14
  229. #define RPLIDAR_VARBITSCALE_X2_DEST_VAL 512
  230. #define RPLIDAR_VARBITSCALE_X4_DEST_VAL 1280
  231. #define RPLIDAR_VARBITSCALE_X8_DEST_VAL 1792
  232. #define RPLIDAR_VARBITSCALE_X16_DEST_VAL 3328
  233. #define RPLIDAR_VARBITSCALE_GET_SRC_MAX_VAL_BY_BITS(_BITS_) \
  234. ( (((0x1<<(_BITS_)) - RPLIDAR_VARBITSCALE_X16_DEST_VAL)<<4) + \
  235. ((RPLIDAR_VARBITSCALE_X16_DEST_VAL - RPLIDAR_VARBITSCALE_X8_DEST_VAL)<<3) + \
  236. ((RPLIDAR_VARBITSCALE_X8_DEST_VAL - RPLIDAR_VARBITSCALE_X4_DEST_VAL)<<2) + \
  237. ((RPLIDAR_VARBITSCALE_X4_DEST_VAL - RPLIDAR_VARBITSCALE_X2_DEST_VAL)<<1) + \
  238. RPLIDAR_VARBITSCALE_X2_DEST_VAL - 1)
  239. #if defined(_WIN32)
  240. #pragma pack()
  241. #endif