Class: Rplidar::ScanDataResponse
Overview
Data response for one scan measurement
Instance Attribute Summary
Attributes inherited from Response
#raw_response
Instance Method Summary
collapse
Methods inherited from Response
#check_payload, #check_response, #initialize
Instance Method Details
#angle ⇒ Object
35
36
37
|
# File 'lib/rplidar/scan_data_response.rb', line 35
def angle
((raw_response[2] << 7) + (raw_response[1] >> 1)) / 64.0
end
|
4
5
6
7
8
9
10
11
12
|
# File 'lib/rplidar/scan_data_response.rb', line 4
def
unless correct_start_bit?
raise 'Inversed start bit of the data response ' \
'is not inverse of the start bit'
end
raise 'Check bit of the data response is not equal to 1' \
unless correct_check_bit?
end
|
#correct_check_bit? ⇒ Boolean
23
24
25
|
# File 'lib/rplidar/scan_data_response.rb', line 23
def correct_check_bit?
raw_response[1][0] == 1
end
|
#correct_start_bit? ⇒ Boolean
14
15
16
17
18
19
20
21
|
# File 'lib/rplidar/scan_data_response.rb', line 14
def correct_start_bit?
start = raw_response[0][0]
inversed = raw_response[0][1]
(start == 1 && inversed.zero?) || (start.zero? && inversed == 1)
end
|
#distance ⇒ Object
39
40
41
|
# File 'lib/rplidar/scan_data_response.rb', line 39
def distance
((raw_response[4] << 8) + raw_response[3]) / 4.0
end
|
#quality ⇒ Object
31
32
33
|
# File 'lib/rplidar/scan_data_response.rb', line 31
def quality
raw_response[0] >> 2
end
|
#response ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/rplidar/scan_data_response.rb', line 43
def response
{
start: start?,
quality: quality,
angle: angle,
distance: distance
}
end
|
#start? ⇒ Boolean
27
28
29
|
# File 'lib/rplidar/scan_data_response.rb', line 27
def start?
raw_response[0][0] == 1
end
|