forked from TJMicroelectronicsLab/SpeedRacer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpLidarTypes.h
190 lines (162 loc) · 5.4 KB
/
rpLidarTypes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* @author KKest
* @created 19.01.2022
*
* Types for rpLidar library
*
*/
#ifndef rplidarTypes_h
#define rplidarTypes_h
#include "Arduino.h"
#define SL_RESULT_OK (sl_result)0
#define SL_RESULT_FAIL_BIT (sl_result)0x80000000
#define SL_RESULT_ALREADY_DONE (sl_result)0x20
#define SL_RESULT_INVALID_DATA (sl_result)(0x8000 | SL_RESULT_FAIL_BIT)
#define SL_RESULT_OPERATION_FAIL (sl_result)(0x8001 | SL_RESULT_FAIL_BIT)
#define SL_RESULT_OPERATION_TIMEOUT (sl_result)(0x8002 | SL_RESULT_FAIL_BIT)
#define SL_RESULT_OPERATION_STOP (sl_result)(0x8003 | SL_RESULT_FAIL_BIT)
#define SL_RESULT_OPERATION_NOT_SUPPORT (sl_result)(0x8004 | SL_RESULT_FAIL_BIT)
#define SL_RESULT_FORMAT_NOT_SUPPORT (sl_result)(0x8005 | SL_RESULT_FAIL_BIT)
#define SL_RESULT_INSUFFICIENT_MEMORY (sl_result)(0x8006 | SL_RESULT_FAIL_BIT)
#define DEFAULT_TIMEOUT 2000
#define MAX_SCAN_NODES (1024)
#define SL_LIDAR_STATUS_OK 0x0
#define SL_LIDAR_STATUS_WARNING 0x1
#define SL_LIDAR_STATUS_ERROR 0x2
#define SL_LIDAR_RESP_MEASUREMENT_SYNCBIT (0x1<<0)
#define SL_LIDAR_RESP_MEASUREMENT_QUALITY_SHIFT 2
#define SL_LIDAR_RESP_HQ_FLAG_SYNCBIT (0x1<<0)
#define SL_LIDAR_RESP_MEASUREMENT_CHECKBIT (0x1<<0)
#define SL_LIDAR_RESP_MEASUREMENT_ANGLE_SHIFT 1
// Definition of the variable bit scale encoding mechanism
#define SL_LIDAR_VARBITSCALE_X2_SRC_BIT 9
#define SL_LIDAR_VARBITSCALE_X4_SRC_BIT 11
#define SL_LIDAR_VARBITSCALE_X8_SRC_BIT 12
#define SL_LIDAR_VARBITSCALE_X16_SRC_BIT 14
#define SL_LIDAR_VARBITSCALE_X2_DEST_VAL 512
#define SL_LIDAR_VARBITSCALE_X4_DEST_VAL 1280
#define SL_LIDAR_VARBITSCALE_X8_DEST_VAL 1792
#define SL_LIDAR_VARBITSCALE_X16_DEST_VAL 3328
#define SL_LIDAR_RESP_MEASUREMENT_EXP_SYNC_1 0xA
#define SL_LIDAR_RESP_MEASUREMENT_EXP_SYNC_2 0x5
#define SL_LIDAR_RESP_MEASUREMENT_HQ_SYNC 0xA5
#define SL_LIDAR_RESP_MEASUREMENT_EXP_SYNCBIT (0x1<<15)
#define SL_LIDAR_VARBITSCALE_GET_SRC_MAX_VAL_BY_BITS(_BITS_) \
( (((0x1<<(_BITS_)) - SL_LIDAR_VARBITSCALE_X16_DEST_VAL)<<4) + \
((SL_LIDAR_VARBITSCALE_X16_DEST_VAL - SL_LIDAR_VARBITSCALE_X8_DEST_VAL)<<3) + \
((SL_LIDAR_VARBITSCALE_X8_DEST_VAL - SL_LIDAR_VARBITSCALE_X4_DEST_VAL)<<2) + \
((SL_LIDAR_VARBITSCALE_X4_DEST_VAL - SL_LIDAR_VARBITSCALE_X2_DEST_VAL)<<1) + \
SL_LIDAR_VARBITSCALE_X2_DEST_VAL - 1)
typedef uint8_t rp_descriptor_t[7];
typedef uint8_t rq_Packet_t[9];
typedef uint8_t rq_message_t[2];
typedef uint32_t sl_result;
typedef uint8_t sl_u8;
typedef uint16_t sl_u16;
typedef uint32_t sl_u32;
/// hold a measure point for standard scan mode
typedef struct scanDataPoint
{
uint8_t quality;
uint8_t angle_low;
uint8_t angle_high;
uint8_t distance_low;
uint8_t distance_high;
}stScanDataPoint_t;
typedef struct _sl_lidar_response_ultra_cabin_nodes_t
{
// 31 0
// | predict2 10bit | predict1 10bit | major 12bit |
sl_u32 combined_x3;
} __attribute__((packed)) sl_lidar_response_ultra_cabin_nodes_t;
typedef struct _sl_lidar_response_ultra_capsule_measurement_nodes_t
{
sl_u8 s_checksum_1; // see [s_checksum_1]
sl_u8 s_checksum_2; // see [s_checksum_1]
sl_u16 start_angle_sync_q6;
sl_lidar_response_ultra_cabin_nodes_t ultra_cabins[32];
} sl_lidar_response_ultra_capsule_measurement_nodes_t;
typedef struct _sl_lidar_response_measurement_node_hq_t
{
sl_u16 angle_z_q14;
sl_u32 dist_mm_q2;
sl_u8 quality;
sl_u8 flag;
} __attribute__((packed)) sl_lidar_response_measurement_node_hq_t;
struct scanDot {
sl_u8 quality;
float angle;
float dist;
};
typedef struct Point
{
double angle;
uint16_t distance;
}point_t;
typedef struct deviceHealtStatus
{
uint8_t status;
uint8_t errorCode_low;
uint8_t errorCode_high;
}stDeviceStatus_t;
typedef struct expressData
{
uint16_t angle;
uint16_t cabin[40];
}stExpressDataPacket_t;
typedef struct expressDataStorage
{
uint8_t angle_low;
uint8_t angle_high;
uint16_t distance;
}expressDataStorage_t;
typedef struct rp_stDeviceInfo
{
uint8_t model;
uint8_t firmware_minor;
uint8_t firmware_major;
uint8_t hardware;
uint8_t serialnumber[16];
}stDeviceInfo_t;
enum enDescriptor
{
legacyVersion, ///< Legacy scan version
extendedVersion, ///< Extendet scan version
denseVersion, ///< Dense scan version
startScan, ///< start scan
forceScan, ///< force to scan in idle mode
deviceInfo, ///< deviceInfo of the Lidar
healthInfo, ///< Error Codes and Status
sampleRate, ///< momentary sampleRate
deviceConf,
ultradense
};
typedef struct _sl_lidar_ans_header_t
{
sl_u8 syncByte1; // must be SL_LIDAR_ANS_SYNC_BYTE1
sl_u8 syncByte2; // must be SL_LIDAR_ANS_SYNC_BYTE2
sl_u32 size_q30_subtype; // see _u32 size:30; _u32 subType:2;
sl_u8 type;
} __attribute__((packed)) sl_lidar_ans_header_t;
enum enRequest
{
rq_stop,
rq_reset,
rq_scan,
rq_scanExpress,
rq_scanForce,
rq_info,
rq_health,
rq_sampleRate,
rq_deviceConf
};
enum enMode
{
stop,
standard,
express
};
extern rp_descriptor_t resp_descriptor[]; ///< List of Response descriptors
extern rq_message_t req_message[]; ///< List of Request Messages
extern rq_Packet_t req_Express[]; ///< Request Message for Express Scan Modes
#endif