57
57
_CMD_DISTANCENOBIAS = const (0x03 )
58
58
_CMD_DISTANCEWITHBIAS = const (0x04 )
59
59
_CMD_DISTANCE_V3HP = const (0x03 )
60
- _NUM_DIST_BYTES = 2 # How many bytes is the returned distance measurement?
60
+ _NUM_DIST_BYTES = 2 # How many bytes is the returned distance measurement?
61
61
62
- TYPE_V3 = 'V3'
63
- TYPE_V3HP = ' V3HP'
62
+ TYPE_V3 = "V3"
63
+ TYPE_V3HP = " V3HP"
64
64
65
65
CONFIG_DEFAULT = 0
66
66
CONFIG_SHORTFAST = 1
@@ -145,16 +145,14 @@ def reset(self):
145
145
try :
146
146
self ._write_reg (_REG_ACQ_COMMAND , _CMD_RESET )
147
147
except OSError :
148
- print ('OSError' )
149
- pass # it doesnt respond well once reset
148
+ print ("OSError" )
150
149
time .sleep (1 )
151
150
# take 100 readings to 'flush' out sensor!
152
151
for _ in range (100 ):
153
152
try :
154
153
self .read_distance_v3 (True )
155
154
except RuntimeError :
156
- print ('RuntimeError' )
157
- pass
155
+ print ("RuntimeError" )
158
156
159
157
def configure (self , config ):
160
158
"""Set the LIDAR desired style of measurement. There are a few common
@@ -177,19 +175,18 @@ def read_distance_v3(self, bias=False):
177
175
if self ._status & (STATUS_NO_PEAK | STATUS_SECOND_RETURN ):
178
176
if self ._status & STATUS_NO_PEAK :
179
177
raise RuntimeError ("Measurement failure STATUS_NO_PEAK" )
180
- elif self ._status & STATUS_SECOND_RETURN :
178
+ if self ._status & STATUS_SECOND_RETURN :
181
179
raise RuntimeError ("Measurement failure STATUS_NO_PEAK" )
182
- else :
183
- raise RuntimeError ("Some other runtime error" )
180
+ raise RuntimeError ("Some other runtime error" )
184
181
185
182
if (self ._status & STATUS_SYS_ERROR ) or (not self ._status & STATUS_HEALTHY ):
186
183
raise RuntimeError ("System failure" )
187
184
return dist [0 ] << 8 | dist [1 ]
188
185
189
186
def read_distance_v3hp (self ):
190
- """Perform a distance measurement for the v3 HP sensor
191
- """
192
- # Any non-zero value written to _REG_ACQ_COMMAND will start a reading on v3HP, no bias vs. non-bias
187
+ """Perform a distance measurement for the v3 HP sensor"""
188
+ # Any non-zero value written to _REG_ACQ_COMMAND will start a reading on v3HP, no bias vs.
189
+ # non-bias
193
190
self ._write_reg (_REG_ACQ_COMMAND , _CMD_DISTANCEWITHBIAS )
194
191
dist = self ._read_reg (_REG_DIST_MEAS_V3HP , _NUM_DIST_BYTES )
195
192
return dist [0 ] << 8 | dist [1 ]
@@ -221,8 +218,8 @@ def health_status(self):
221
218
"""Reads health status for v3HP (not available on v3, will return -1)"""
222
219
if self ._sensor_type == TYPE_V3HP :
223
220
return self ._read_reg (_REG_HEALTH_STATUS_V3HP , 1 )[0 ]
224
- else :
225
- return - 1
221
+
222
+ return - 1
226
223
227
224
@property
228
225
def signal_strength (self ):
@@ -238,17 +235,20 @@ def unit_id(self):
238
235
return high_byte [0 ] << 8 | low_byte [0 ]
239
236
240
237
@property
241
- def distance (self ):
238
+ def distance (self ): # pylint: disable=R1710
242
239
"""The measured distance in cm. Will take a bias reading every 100 calls"""
243
240
self ._bias_count -= 1
244
241
245
242
if self ._bias_count < 0 :
246
243
self ._bias_count = 100 # every 100 reads, check bias
247
244
if self ._sensor_type == TYPE_V3 :
248
245
return self .read_distance_v3 (self ._bias_count <= 0 )
249
- elif self ._sensor_type == TYPE_V3HP :
246
+ if self ._sensor_type == TYPE_V3HP :
250
247
return self .read_distance_v3hp ()
251
248
249
+ # If no sensor type has been identified, return a negative distance as an error
250
+ return - 1.0
251
+
252
252
@property
253
253
def status (self ):
254
254
"""The status byte, check datasheet for bitmask"""
0 commit comments