rfbeam 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -4
- data/.streerc +2 -0
- data/.tool-versions +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +6 -1
- data/README.md +57 -33
- data/lib/rfbeam/cli.rb +35 -80
- data/lib/rfbeam/kld7/cli_formatter.rb +41 -0
- data/lib/rfbeam/kld7/cli_output.rb +127 -0
- data/lib/rfbeam/kld7/constants.rb +155 -31
- data/lib/rfbeam/kld7/radar_messages.rb +30 -23
- data/lib/rfbeam/kld7/radar_parameters.rb +97 -97
- data/lib/rfbeam/kld7/serial_connection.rb +1 -1
- data/lib/rfbeam/version.rb +1 -1
- data/lib/rfbeam.rb +2 -2
- data/rfbeam.gemspec +1 -1
- metadata +7 -5
- data/lib/rfbeam/kld7/streamer.rb +0 -75
@@ -14,52 +14,176 @@ module RfBeam
|
|
14
14
|
6 => 'Timeout error'
|
15
15
|
}.freeze
|
16
16
|
|
17
|
-
#
|
18
|
-
|
17
|
+
# Delays are determined empirically and may need adjusting with baude rate
|
18
|
+
RESPONSE_DELAY = 0.05
|
19
|
+
MEASUREMENT_DELAY = 0.15
|
19
20
|
|
20
21
|
# 'GNFD' command types
|
21
22
|
FRAME_DATA_TYPES = { disabled: 0x00, radc: 0x01, rfft: 0x02, pdat: 0x04, tdat: 0x08, ddat: 0x10, done: 0x20 }.freeze
|
22
23
|
|
23
24
|
# The angle, direction, range and speed flags are only valid if the detection flag is 1.
|
24
25
|
DETECTION_FLAGS = {
|
25
|
-
detection: [
|
26
|
-
micro_detection: [
|
26
|
+
detection: %w[No Yes],
|
27
|
+
micro_detection: %w[No Yes],
|
27
28
|
angle: %w[Left Right],
|
28
29
|
direction: %w[Receding Approaching],
|
29
30
|
range: %w[Far Near],
|
30
31
|
speed: %w[Low High]
|
31
32
|
}.freeze
|
32
33
|
|
33
|
-
Param =
|
34
|
-
|
35
|
-
|
34
|
+
Param =
|
35
|
+
Struct.new(:name, :grps_index, :description, :default, :units, :values) do
|
36
|
+
def initialize(name:, grps_index:, description: nil, default: nil, units: nil, values: [])
|
37
|
+
super(name, grps_index, description, default, units, values)
|
38
|
+
end
|
36
39
|
end
|
37
|
-
end
|
38
40
|
|
39
41
|
RADAR_PARAMETERS = {
|
40
42
|
sw_version: Param.new(name: 'Software Version', grps_index: 2, default: 'K-LD7_APP-RFB-XXXX'),
|
41
|
-
base_frequency:
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
43
|
+
base_frequency:
|
44
|
+
Param.new(
|
45
|
+
name: 'Base Frequency',
|
46
|
+
grps_index: 3,
|
47
|
+
description: '0 = Low, 1 = Middle, 2 = High',
|
48
|
+
default: 1,
|
49
|
+
values: %w[Low Middle High]
|
50
|
+
),
|
51
|
+
max_speed:
|
52
|
+
Param.new(
|
53
|
+
name: 'Maximum Speed',
|
54
|
+
grps_index: 4,
|
55
|
+
description: '0 = 12km/h, 1 = 25km/h, 2 = 50km/h, 3 = 100km/h',
|
56
|
+
default: 1,
|
57
|
+
units: 'km/h',
|
58
|
+
values: %w[12.5 25 50 100]
|
59
|
+
),
|
60
|
+
max_range:
|
61
|
+
Param.new(
|
62
|
+
name: 'Maximum Range',
|
63
|
+
grps_index: 5,
|
64
|
+
description: '0 = 5m, 1 = 10m, 2 = 30m, 3 = 100m',
|
65
|
+
default: 1,
|
66
|
+
values: %w[5m 10m 30m 100m]
|
67
|
+
),
|
68
|
+
threshold_offset:
|
69
|
+
Param.new(name: 'Threshold Offset', grps_index: 6, description: '10db - 60db', default: 30, units: 'db'),
|
70
|
+
tracking_filter:
|
71
|
+
Param.new(
|
72
|
+
name: 'Tracking Filter Type',
|
73
|
+
grps_index: 7,
|
74
|
+
description: '0 = Standard, 2 = Fast Detection, 3 = Long Visibility',
|
75
|
+
default: 0,
|
76
|
+
values: ['standard', 'Fast Detection', 'Long Visibility']
|
77
|
+
),
|
78
|
+
vibration_suppression:
|
79
|
+
Param.new(
|
80
|
+
name: 'Vibration Suppression',
|
81
|
+
grps_index: 8,
|
82
|
+
description: '0-16, 0 = No Suppression, 16 = High Suppression',
|
83
|
+
default: 2
|
84
|
+
),
|
85
|
+
min_detection_distance:
|
86
|
+
Param.new(
|
87
|
+
name: 'Minimum Detection Distance',
|
88
|
+
grps_index: 9,
|
89
|
+
description: '0 - 100% of range setting',
|
90
|
+
default: 0,
|
91
|
+
units: '%'
|
92
|
+
),
|
93
|
+
max_detection_distance:
|
94
|
+
Param.new(
|
95
|
+
name: 'Maximum Detection Distance',
|
96
|
+
grps_index: 10,
|
97
|
+
description: '0 - 100% of range setting',
|
98
|
+
default: 50,
|
99
|
+
units: '%'
|
100
|
+
),
|
101
|
+
min_detection_angle:
|
102
|
+
Param.new(name: 'Minimum Detection Angle', grps_index: 11, description: '-90° - 90°', default: -90, units: '°'),
|
103
|
+
max_detection_angle:
|
104
|
+
Param.new(name: 'Maximum Detection Angle', grps_index: 12, description: '-90° - 90°', default: 90, units: '°'),
|
105
|
+
min_detection_speed:
|
106
|
+
Param.new(
|
107
|
+
name: 'Minimum Detection Speed',
|
108
|
+
grps_index: 13,
|
109
|
+
description: '0 - 100% of speed setting',
|
110
|
+
default: 0,
|
111
|
+
units: '%'
|
112
|
+
),
|
113
|
+
max_detection_speed:
|
114
|
+
Param.new(
|
115
|
+
name: 'Maximum Detection Speed',
|
116
|
+
grps_index: 14,
|
117
|
+
description: '0 - 100% of speed setting',
|
118
|
+
default: 100,
|
119
|
+
units: '%'
|
120
|
+
),
|
121
|
+
detection_direction:
|
122
|
+
Param.new(
|
123
|
+
name: 'Detection Direction',
|
124
|
+
grps_index: 15,
|
125
|
+
description: '0 = Receding, 1 = Approaching, 2 = Both',
|
126
|
+
default: 2,
|
127
|
+
values: %w[Receding Approaching Both]
|
128
|
+
),
|
129
|
+
range_threshold:
|
130
|
+
Param.new(
|
131
|
+
name: 'Range Threshold',
|
132
|
+
grps_index: 16,
|
133
|
+
description: '0 - 100% of range setting',
|
134
|
+
default: 10,
|
135
|
+
units: '%'
|
136
|
+
),
|
137
|
+
angle_threshold:
|
138
|
+
Param.new(name: 'Angle Threshold', grps_index: 17, description: '-90° - 90°', default: 0, units: '°'),
|
139
|
+
speed_threshold:
|
140
|
+
Param.new(
|
141
|
+
name: 'Speed Threshold',
|
142
|
+
grps_index: 18,
|
143
|
+
description: '0 - 100% of speed setting',
|
144
|
+
default: 50,
|
145
|
+
units: '%'
|
146
|
+
),
|
147
|
+
digital_output1:
|
148
|
+
Param.new(
|
149
|
+
name: 'Digital Output 1',
|
150
|
+
grps_index: 19,
|
151
|
+
description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection',
|
152
|
+
default: 0,
|
153
|
+
values: %w[Direction Angle Range Speed Micro]
|
154
|
+
),
|
155
|
+
digital_output2:
|
156
|
+
Param.new(
|
157
|
+
name: 'Digital Output 2',
|
158
|
+
grps_index: 20,
|
159
|
+
description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection',
|
160
|
+
default: 1,
|
161
|
+
values: %w[Direction Angle Range Speed Micro]
|
162
|
+
),
|
163
|
+
digital_output3:
|
164
|
+
Param.new(
|
165
|
+
name: 'Digital Output 3',
|
166
|
+
grps_index: 21,
|
167
|
+
description: '0 = Direction, 1 = Angle, 2 = Range, 3 = Speed, 4 = Micro Detection',
|
168
|
+
default: 2,
|
169
|
+
values: %w[Direction Angle Range Speed Micro]
|
170
|
+
),
|
171
|
+
hold_time: Param.new(name: 'Hold Time', grps_index: 22, description: '1 - 7200s', default: 1, units: 's'),
|
172
|
+
micro_detection_retrigger:
|
173
|
+
Param.new(
|
174
|
+
name: 'Micro Detection Trigger',
|
175
|
+
grps_index: 23,
|
176
|
+
description: '0 = Off, 1 = Retrigger',
|
177
|
+
default: 0,
|
178
|
+
values: %w[Off Retrigger]
|
179
|
+
),
|
180
|
+
micro_detection_sensativity:
|
181
|
+
Param.new(
|
182
|
+
name: 'Micro Detection Sensativity',
|
183
|
+
grps_index: 24,
|
184
|
+
description: '0 - 9, 0 = Min, 9 = Max',
|
185
|
+
default: 4
|
186
|
+
)
|
187
|
+
}.freeze
|
64
188
|
end
|
65
189
|
end
|
@@ -9,15 +9,27 @@ module RfBeam
|
|
9
9
|
|
10
10
|
def rfft
|
11
11
|
request_frame_data(:rfft)
|
12
|
+
sleep MEASUREMENT_DELAY
|
13
|
+
data = read(1032).unpack('a4LS256S256')
|
14
|
+
header, length = data.shift(2)
|
15
|
+
raise Error, "RFFT header response, header=#{header}" unless header == 'RFFT'
|
16
|
+
raise Error, "RFFT payload length, length=#{length}" unless length == 1024
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
18
|
+
data
|
19
|
+
end
|
20
|
+
|
21
|
+
def reset
|
22
|
+
command = ['RFSE', 0]
|
23
|
+
write command.pack('a4L')
|
24
|
+
check_response
|
16
25
|
end
|
17
|
-
|
26
|
+
alias rfse reset
|
27
|
+
|
18
28
|
def pdat(formatted: false)
|
19
|
-
request_frame_data(:pdat)
|
29
|
+
request_frame_data(:pdat)
|
20
30
|
resp = read(102).unpack('a4LSssSSssSSssSSssSSssSSssSSssSSssSSssSSssS')
|
31
|
+
raise Error, "PDAT response = #{resp[0]}" unless resp[0] == 'PDAT'
|
32
|
+
|
21
33
|
return resp unless formatted
|
22
34
|
|
23
35
|
target_count = resp[1].to_i / 8
|
@@ -32,26 +44,23 @@ module RfBeam
|
|
32
44
|
|
33
45
|
def tdat
|
34
46
|
request_frame_data(:tdat)
|
47
|
+
sleep MEASUREMENT_DELAY
|
35
48
|
|
36
|
-
sleep 0.1
|
37
49
|
resp = read(16).unpack('a4LSssS')
|
38
|
-
|
50
|
+
raise Error, "TDAT response = #{resp[0]}" unless resp[0] == 'TDAT'
|
51
|
+
|
52
|
+
resp
|
39
53
|
end
|
40
54
|
|
41
55
|
def ddat
|
42
56
|
request_frame_data(:ddat)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
angle: DETECTION_FLAGS[:angle][array[4]],
|
49
|
-
direction: DETECTION_FLAGS[:direction][array[5]],
|
50
|
-
range: DETECTION_FLAGS[:range][array[6]],
|
51
|
-
speed: DETECTION_FLAGS[:speed][array[7]]
|
52
|
-
}
|
57
|
+
sleep MEASUREMENT_DELAY
|
58
|
+
|
59
|
+
resp = read(14).unpack('a4LC6')
|
60
|
+
raise Error, "DDAT response = #{resp[0]}" unless resp[0] == 'DDAT'
|
61
|
+
resp
|
53
62
|
end
|
54
|
-
|
63
|
+
|
55
64
|
# Get the radar parameter structure
|
56
65
|
def grps
|
57
66
|
command = ['GRPS', 0]
|
@@ -63,12 +72,10 @@ module RfBeam
|
|
63
72
|
def config
|
64
73
|
data = grps
|
65
74
|
output = "\n"
|
66
|
-
RADAR_PARAMETERS.keys.each
|
67
|
-
output << formatted_parameter(key, data[RADAR_PARAMETERS[key].grps_index])
|
68
|
-
end
|
75
|
+
RADAR_PARAMETERS.keys.each { |key| output << formatted_parameter(key, data[RADAR_PARAMETERS[key].grps_index]) }
|
69
76
|
output
|
70
77
|
end
|
71
|
-
|
78
|
+
|
72
79
|
def formatted_parameter(param, value = nil)
|
73
80
|
param = RADAR_PARAMETERS[param]
|
74
81
|
if value.nil?
|
@@ -82,7 +89,7 @@ module RfBeam
|
|
82
89
|
private
|
83
90
|
|
84
91
|
def format_raw_target_data(array)
|
85
|
-
|
92
|
+
{ dist: array.shift, speed: array.shift, angle: array.shift, mag: array.shift }
|
86
93
|
end
|
87
94
|
|
88
95
|
def request_frame_data(type)
|