migrated sensor processing to stream
added agent doc and coding rules
This commit is contained in:
@@ -109,15 +109,42 @@ CREATED: list = []
|
||||
|
||||
|
||||
class _Sensor:
|
||||
"""A device the ``StreamPipeline`` can drive as well as the serial loop.
|
||||
|
||||
``Sensor`` is what the SDK pipeline calls: ``compute_flow`` then
|
||||
``compute_hhd`` then, with ``contact=True``, ``compute_contact``. The fake
|
||||
device has no optics, so the compute methods only have to leave the arrays the
|
||||
snapshot is built from in a shape the SDK's contract describes.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
import numpy as np
|
||||
|
||||
self.configured: dict = {}
|
||||
self.connected = True
|
||||
self.info = _Info()
|
||||
self.capture_source = _CaptureSource()
|
||||
self.frame = np.zeros((8, 8, 3), dtype=np.uint8)
|
||||
self.info = _Info()
|
||||
self.img = np.zeros((8, 8), dtype=np.uint8)
|
||||
self.flow = None
|
||||
self.vnormal = None
|
||||
self.vshear = None
|
||||
self.depth_map = None
|
||||
self.centroid = None
|
||||
self.centroid_found = False
|
||||
self.contour = None
|
||||
self.compute_contact_valid = False
|
||||
self.valid_mask = None
|
||||
self.img_size_raw = (1920, 1080)
|
||||
self.force_calibrated = True
|
||||
self.calibration = None
|
||||
self.fnormal = 1.5
|
||||
self.fshearx = 0.25
|
||||
self.fsheary = -0.25
|
||||
self.ftor = 0.0
|
||||
self.force_unit = "N"
|
||||
#: The unfiltered integrator pair a real sensor keeps after ``compute_hhd``.
|
||||
self._force_raw = (15.0, 2.5, -2.5)
|
||||
CREATED.append(self)
|
||||
|
||||
def configure(self, **kwargs):
|
||||
@@ -135,14 +162,42 @@ class _Sensor:
|
||||
}
|
||||
return tuple(values.get(str(name), 0.0) for name in names)
|
||||
|
||||
def get_img(self):
|
||||
def compute_flow(self, img=None):
|
||||
import numpy as np
|
||||
|
||||
self.flow = np.zeros((8, 8, 2), dtype=np.float32)
|
||||
|
||||
def compute_hhd(self, flow=None):
|
||||
# A real ``compute_hhd`` refreshes the unfiltered integrator pair; keeping
|
||||
# the values here is what makes a snapshot carry a force reading at all.
|
||||
self._force_raw = (15.0, 2.5, -2.5)
|
||||
|
||||
def compute_deformation(self, decompose=True, check_motion=False, **kwargs):
|
||||
self.compute_flow()
|
||||
if decompose:
|
||||
self.compute_hhd()
|
||||
return None
|
||||
|
||||
def compute_contact(self, vnormal=None):
|
||||
self.compute_contact_valid = True
|
||||
return {}
|
||||
|
||||
def read_latest(self, **kwargs):
|
||||
"""``CaptureSource.read_latest``: the newest frame, or nothing yet."""
|
||||
self.capture_source.take()
|
||||
return True, self.frame
|
||||
|
||||
def get_img(self, **kwargs):
|
||||
# ``read_latest``: hand back the newest frame immediately, the same one
|
||||
# again when nothing new has arrived. A test can make this cost time, so
|
||||
# the loop can be put under a pipeline slower than the camera.
|
||||
if PROCESS_COST_S > 0:
|
||||
time.sleep(PROCESS_COST_S)
|
||||
self.capture_source.take()
|
||||
return self.frame
|
||||
return self.img.copy()
|
||||
|
||||
def reset(self):
|
||||
return None
|
||||
|
||||
def disconnect(self):
|
||||
self.connected = False
|
||||
|
||||
Reference in New Issue
Block a user