-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLIDAR-utils.h
More file actions
35 lines (30 loc) · 826 Bytes
/
LIDAR-utils.h
File metadata and controls
35 lines (30 loc) · 826 Bytes
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
/*
* File: LIDAR-utils.h
* Author: robot
*
* Created on 9 June 2015, 3:04 PM
*/
#ifndef LIDARUTILS_H
#define LIDARUTILS_H
unsigned int LIDAR_decode_raw(const char* chars) {
/*
* LIDAR outputs 0x00 to 0x3F
* 0x30 is added to make ASCII printable
* We subtract 0x30
* Concat the 6 bits onto the integer
* Total 3 chars
* 3*6 is 18 bits, 2MSB discarded as will be 0 anyway
*
* returns 0 if error, else distance in mm
*/
int dist = 0;
int i = 0;
for (i=0; i<3; ++i) {
//shift left 6 bits to make room for next
dist <<= 6; //first iteration is zeros
char tmp = chars[0]-0x30; //subtract 0x30
if (tmp<0x00 || tmp>0x3F) { return 0; } //error handling
dist += tmp & 0x3F; //6 LSB mask
}
}
#endif /* LIDAR_UTILS_H */