00001 /* 00002 * RPLIDAR SDK 00003 * 00004 * Copyright (c) 2009 - 2014 RoboPeak Team 00005 * http://www.robopeak.com 00006 * Copyright (c) 2014 - 2019 Shanghai Slamtec Co., Ltd. 00007 * http://www.slamtec.com 00008 * 00009 */ 00010 /* 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions are met: 00013 * 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00022 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00023 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00024 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00025 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00026 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00027 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00028 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00029 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00030 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00031 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 */ 00034 00035 #pragma once 00036 00037 #include "rplidar_protocol.h" 00038 00039 // Commands 00040 //----------------------------------------- 00041 00042 // Commands without payload and response 00043 #define RPLIDAR_CMD_STOP 0x25 00044 #define RPLIDAR_CMD_SCAN 0x20 00045 #define RPLIDAR_CMD_FORCE_SCAN 0x21 00046 #define RPLIDAR_CMD_RESET 0x40 00047 00048 00049 // Commands without payload but have response 00050 #define RPLIDAR_CMD_GET_DEVICE_INFO 0x50 00051 #define RPLIDAR_CMD_GET_DEVICE_HEALTH 0x52 00052 00053 #define RPLIDAR_CMD_GET_SAMPLERATE 0x59 //added in fw 1.17 00054 00055 #define RPLIDAR_CMD_HQ_MOTOR_SPEED_CTRL 0xA8 00056 00057 // Commands with payload and have response 00058 #define RPLIDAR_CMD_EXPRESS_SCAN 0x82 //added in fw 1.17 00059 #define RPLIDAR_CMD_HQ_SCAN 0x83 //added in fw 1.24 00060 #define RPLIDAR_CMD_GET_LIDAR_CONF 0x84 //added in fw 1.24 00061 #define RPLIDAR_CMD_SET_LIDAR_CONF 0x85 //added in fw 1.24 00062 //add for A2 to set RPLIDAR motor pwm when using accessory board 00063 #define RPLIDAR_CMD_SET_MOTOR_PWM 0xF0 00064 #define RPLIDAR_CMD_GET_ACC_BOARD_FLAG 0xFF 00065 00066 #if defined(_WIN32) 00067 #pragma pack(1) 00068 #endif 00069 00070 00071 // Payloads 00072 // ------------------------------------------ 00073 #define RPLIDAR_EXPRESS_SCAN_MODE_NORMAL 0 00074 #define RPLIDAR_EXPRESS_SCAN_MODE_FIXANGLE 0 // won't been supported but keep to prevent build fail 00075 //for express working flag(extending express scan protocol) 00076 #define RPLIDAR_EXPRESS_SCAN_FLAG_BOOST 0x0001 00077 #define RPLIDAR_EXPRESS_SCAN_FLAG_SUNLIGHT_REJECTION 0x0002 00078 00079 //for ultra express working flag 00080 #define RPLIDAR_ULTRAEXPRESS_SCAN_FLAG_STD 0x0001 00081 #define RPLIDAR_ULTRAEXPRESS_SCAN_FLAG_HIGH_SENSITIVITY 0x0002 00082 00083 #define RPLIDAR_HQ_SCAN_FLAG_CCW (0x1<<0) 00084 #define RPLIDAR_HQ_SCAN_FLAG_RAW_ENCODER (0x1<<1) 00085 #define RPLIDAR_HQ_SCAN_FLAG_RAW_DISTANCE (0x1<<2) 00086 00087 typedef struct _rplidar_payload_express_scan_t { 00088 _u8 working_mode; 00089 _u16 working_flags; 00090 _u16 param; 00091 } __attribute__((packed)) rplidar_payload_express_scan_t; 00092 00093 typedef struct _rplidar_payload_hq_scan_t { 00094 _u8 flag; 00095 _u8 reserved[32]; 00096 } __attribute__((packed)) rplidar_payload_hq_scan_t; 00097 00098 typedef struct _rplidar_payload_get_scan_conf_t { 00099 _u32 type; 00100 _u8 reserved[32]; 00101 } __attribute__((packed)) rplidar_payload_get_scan_conf_t; 00102 #define MAX_MOTOR_PWM 1023 00103 #define DEFAULT_MOTOR_PWM 660 00104 typedef struct _rplidar_payload_motor_pwm_t { 00105 _u16 pwm_value; 00106 } __attribute__((packed)) rplidar_payload_motor_pwm_t; 00107 00108 typedef struct _rplidar_payload_acc_board_flag_t { 00109 _u32 reserved; 00110 } __attribute__((packed)) rplidar_payload_acc_board_flag_t; 00111 00112 // Response 00113 // ------------------------------------------ 00114 #define RPLIDAR_ANS_TYPE_DEVINFO 0x4 00115 #define RPLIDAR_ANS_TYPE_DEVHEALTH 0x6 00116 00117 #define RPLIDAR_ANS_TYPE_MEASUREMENT 0x81 00118 // Added in FW ver 1.17 00119 #define RPLIDAR_ANS_TYPE_MEASUREMENT_CAPSULED 0x82 00120 #define RPLIDAR_ANS_TYPE_MEASUREMENT_HQ 0x83 00121 00122 00123 // Added in FW ver 1.17 00124 #define RPLIDAR_ANS_TYPE_SAMPLE_RATE 0x15 00125 //added in FW ver 1.23alpha 00126 #define RPLIDAR_ANS_TYPE_MEASUREMENT_CAPSULED_ULTRA 0x84 00127 //added in FW ver 1.24 00128 #define RPLIDAR_ANS_TYPE_GET_LIDAR_CONF 0x20 00129 #define RPLIDAR_ANS_TYPE_SET_LIDAR_CONF 0x21 00130 #define RPLIDAR_ANS_TYPE_MEASUREMENT_DENSE_CAPSULED 0x85 00131 #define RPLIDAR_ANS_TYPE_ACC_BOARD_FLAG 0xFF 00132 00133 #define RPLIDAR_RESP_ACC_BOARD_FLAG_MOTOR_CTRL_SUPPORT_MASK (0x1) 00134 typedef struct _rplidar_response_acc_board_flag_t { 00135 _u32 support_flag; 00136 } __attribute__((packed)) rplidar_response_acc_board_flag_t; 00137 00138 00139 #define RPLIDAR_STATUS_OK 0x0 00140 #define RPLIDAR_STATUS_WARNING 0x1 00141 #define RPLIDAR_STATUS_ERROR 0x2 00142 00143 #define RPLIDAR_RESP_MEASUREMENT_SYNCBIT (0x1<<0) 00144 #define RPLIDAR_RESP_MEASUREMENT_QUALITY_SHIFT 2 00145 00146 #define RPLIDAR_RESP_HQ_FLAG_SYNCBIT (0x1<<0) 00147 00148 #define RPLIDAR_RESP_MEASUREMENT_CHECKBIT (0x1<<0) 00149 #define RPLIDAR_RESP_MEASUREMENT_ANGLE_SHIFT 1 00150 00151 typedef struct _rplidar_response_sample_rate_t { 00152 _u16 std_sample_duration_us; 00153 _u16 express_sample_duration_us; 00154 } __attribute__((packed)) rplidar_response_sample_rate_t; 00155 00156 typedef struct _rplidar_response_measurement_node_t { 00157 _u8 sync_quality; // syncbit:1;syncbit_inverse:1;quality:6; 00158 _u16 angle_q6_checkbit; // check_bit:1;angle_q6:15; 00159 _u16 distance_q2; 00160 } __attribute__((packed)) rplidar_response_measurement_node_t; 00161 00162 //[distance_sync flags] 00163 #define RPLIDAR_RESP_MEASUREMENT_EXP_ANGLE_MASK (0x3) 00164 #define RPLIDAR_RESP_MEASUREMENT_EXP_DISTANCE_MASK (0xFC) 00165 00166 typedef struct _rplidar_response_cabin_nodes_t { 00167 _u16 distance_angle_1; // see [distance_sync flags] 00168 _u16 distance_angle_2; // see [distance_sync flags] 00169 _u8 offset_angles_q3; 00170 } __attribute__((packed)) rplidar_response_cabin_nodes_t; 00171 00172 00173 #define RPLIDAR_RESP_MEASUREMENT_EXP_SYNC_1 0xA 00174 #define RPLIDAR_RESP_MEASUREMENT_EXP_SYNC_2 0x5 00175 00176 #define RPLIDAR_RESP_MEASUREMENT_HQ_SYNC 0xA5 00177 00178 #define RPLIDAR_RESP_MEASUREMENT_EXP_SYNCBIT (0x1<<15) 00179 00180 typedef struct _rplidar_response_capsule_measurement_nodes_t { 00181 _u8 s_checksum_1; // see [s_checksum_1] 00182 _u8 s_checksum_2; // see [s_checksum_1] 00183 _u16 start_angle_sync_q6; 00184 rplidar_response_cabin_nodes_t cabins[16]; 00185 } __attribute__((packed)) rplidar_response_capsule_measurement_nodes_t; 00186 00187 typedef struct _rplidar_response_dense_cabin_nodes_t { 00188 _u16 distance; 00189 } __attribute__((packed)) rplidar_response_dense_cabin_nodes_t; 00190 00191 typedef struct _rplidar_response_dense_capsule_measurement_nodes_t { 00192 _u8 s_checksum_1; // see [s_checksum_1] 00193 _u8 s_checksum_2; // see [s_checksum_1] 00194 _u16 start_angle_sync_q6; 00195 rplidar_response_dense_cabin_nodes_t cabins[40]; 00196 } __attribute__((packed)) rplidar_response_dense_capsule_measurement_nodes_t; 00197 00198 // ext1 : x2 boost mode 00199 00200 #define RPLIDAR_RESP_MEASUREMENT_EXP_ULTRA_MAJOR_BITS 12 00201 #define RPLIDAR_RESP_MEASUREMENT_EXP_ULTRA_PREDICT_BITS 10 00202 00203 typedef struct _rplidar_response_ultra_cabin_nodes_t { 00204 // 31 0 00205 // | predict2 10bit | predict1 10bit | major 12bit | 00206 _u32 combined_x3; 00207 } __attribute__((packed)) rplidar_response_ultra_cabin_nodes_t; 00208 00209 typedef struct _rplidar_response_ultra_capsule_measurement_nodes_t { 00210 _u8 s_checksum_1; // see [s_checksum_1] 00211 _u8 s_checksum_2; // see [s_checksum_1] 00212 _u16 start_angle_sync_q6; 00213 rplidar_response_ultra_cabin_nodes_t ultra_cabins[32]; 00214 } __attribute__((packed)) rplidar_response_ultra_capsule_measurement_nodes_t; 00215 00216 typedef struct rplidar_response_measurement_node_hq_t { 00217 _u16 angle_z_q14; 00218 _u32 dist_mm_q2; 00219 _u8 quality; 00220 _u8 flag; 00221 } __attribute__((packed)) rplidar_response_measurement_node_hq_t; 00222 00223 typedef struct _rplidar_response_hq_capsule_measurement_nodes_t{ 00224 _u8 sync_byte; 00225 _u64 time_stamp; 00226 rplidar_response_measurement_node_hq_t node_hq[16]; 00227 _u32 crc32; 00228 }__attribute__((packed)) rplidar_response_hq_capsule_measurement_nodes_t; 00229 00230 00231 # define RPLIDAR_CONF_SCAN_COMMAND_STD 0 00232 # define RPLIDAR_CONF_SCAN_COMMAND_EXPRESS 1 00233 # define RPLIDAR_CONF_SCAN_COMMAND_HQ 2 00234 # define RPLIDAR_CONF_SCAN_COMMAND_BOOST 3 00235 # define RPLIDAR_CONF_SCAN_COMMAND_STABILITY 4 00236 # define RPLIDAR_CONF_SCAN_COMMAND_SENSITIVITY 5 00237 00238 #define RPLIDAR_CONF_ANGLE_RANGE 0x00000000 00239 #define RPLIDAR_CONF_DESIRED_ROT_FREQ 0x00000001 00240 #define RPLIDAR_CONF_SCAN_COMMAND_BITMAP 0x00000002 00241 #define RPLIDAR_CONF_MIN_ROT_FREQ 0x00000004 00242 #define RPLIDAR_CONF_MAX_ROT_FREQ 0x00000005 00243 #define RPLIDAR_CONF_MAX_DISTANCE 0x00000060 00244 00245 #define RPLIDAR_CONF_SCAN_MODE_COUNT 0x00000070 00246 #define RPLIDAR_CONF_SCAN_MODE_US_PER_SAMPLE 0x00000071 00247 #define RPLIDAR_CONF_SCAN_MODE_MAX_DISTANCE 0x00000074 00248 #define RPLIDAR_CONF_SCAN_MODE_ANS_TYPE 0x00000075 00249 #define RPLIDAR_CONF_SCAN_MODE_TYPICAL 0x0000007C 00250 #define RPLIDAR_CONF_SCAN_MODE_NAME 0x0000007F 00251 #define RPLIDAR_EXPRESS_SCAN_STABILITY_BITMAP 4 00252 #define RPLIDAR_EXPRESS_SCAN_SENSITIVITY_BITMAP 5 00253 00254 typedef struct _rplidar_response_get_lidar_conf{ 00255 _u32 type; 00256 _u8 payload[0]; 00257 }__attribute__((packed)) rplidar_response_get_lidar_conf_t; 00258 00259 typedef struct _rplidar_response_set_lidar_conf{ 00260 _u32 result; 00261 }__attribute__((packed)) rplidar_response_set_lidar_conf_t; 00262 00263 00264 typedef struct _rplidar_response_device_info_t { 00265 _u8 model; 00266 _u16 firmware_version; 00267 _u8 hardware_version; 00268 _u8 serialnum[16]; 00269 } __attribute__((packed)) rplidar_response_device_info_t; 00270 00271 typedef struct _rplidar_response_device_health_t { 00272 _u8 status; 00273 _u16 error_code; 00274 } __attribute__((packed)) rplidar_response_device_health_t; 00275 00276 // Definition of the variable bit scale encoding mechanism 00277 #define RPLIDAR_VARBITSCALE_X2_SRC_BIT 9 00278 #define RPLIDAR_VARBITSCALE_X4_SRC_BIT 11 00279 #define RPLIDAR_VARBITSCALE_X8_SRC_BIT 12 00280 #define RPLIDAR_VARBITSCALE_X16_SRC_BIT 14 00281 00282 #define RPLIDAR_VARBITSCALE_X2_DEST_VAL 512 00283 #define RPLIDAR_VARBITSCALE_X4_DEST_VAL 1280 00284 #define RPLIDAR_VARBITSCALE_X8_DEST_VAL 1792 00285 #define RPLIDAR_VARBITSCALE_X16_DEST_VAL 3328 00286 00287 #define RPLIDAR_VARBITSCALE_GET_SRC_MAX_VAL_BY_BITS(_BITS_) \ 00288 ( (((0x1<<(_BITS_)) - RPLIDAR_VARBITSCALE_X16_DEST_VAL)<<4) + \ 00289 ((RPLIDAR_VARBITSCALE_X16_DEST_VAL - RPLIDAR_VARBITSCALE_X8_DEST_VAL)<<3) + \ 00290 ((RPLIDAR_VARBITSCALE_X8_DEST_VAL - RPLIDAR_VARBITSCALE_X4_DEST_VAL)<<2) + \ 00291 ((RPLIDAR_VARBITSCALE_X4_DEST_VAL - RPLIDAR_VARBITSCALE_X2_DEST_VAL)<<1) + \ 00292 RPLIDAR_VARBITSCALE_X2_DEST_VAL - 1) 00293 00294 00295 #if defined(_WIN32) 00296 #pragma pack() 00297 #endif