37 lines
1006 B
Python
37 lines
1006 B
Python
"""
|
|
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, measurements=100):
|
|
return 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()
|