Lidar program

Committer:
pymal
Date:
Wed Mar 03 21:49:13 2021 +0000
Revision:
0:1d10a6e6808c
Trying to publish Lidar program

Who changed what in which revision?

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