Add 'car/' from commit 'eee0e8dc445691e600680f4abc77f2814b20b054'
git-subtree-dir: car git-subtree-mainline:1d29a5526cgit-subtree-split:eee0e8dc44
This commit is contained in:
43
car/tracking/devices/mock_lidar.py
Normal file
43
car/tracking/devices/mock_lidar.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
This module contains a MockLidar class, for use in place of RPLidar.
|
||||
Importantly, it implements iter_scans, so it can be substituted for RPLidar
|
||||
in the lidar_cache for testing (or anywhere else the rplidar may be used)
|
||||
"""
|
||||
|
||||
import tracking.lidar_loader as loader
|
||||
|
||||
|
||||
class MockLidar:
|
||||
|
||||
def __init__(self, scan_iter=None):
|
||||
"""
|
||||
Create mock lidar with an iterator that can be used as fake (or reused) scan data.
|
||||
|
||||
Examples
|
||||
--------
|
||||
lidar = MockLidar(scans)
|
||||
first_scan = next(lidar.iter_scans(measurements=100))
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
scan_iter: Iterable
|
||||
An iterator that will generate/provide the fake/old scan data.
|
||||
|
||||
"""
|
||||
self._iter = scan_iter
|
||||
|
||||
def iter_scans(self, min_len=100):
|
||||
return iter(self._iter)
|
||||
|
||||
def get_health(self):
|
||||
return "Mock Lidar has scans" if self._iter is not None else "Mock lidar won't work properly!"
|
||||
|
||||
def get_info(self):
|
||||
return self.get_health()
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
def disconnect(self):
|
||||
pass
|
||||
Reference in New Issue
Block a user