def __init__(self, transceiver, transformers=None, publisher=None): self.transceiver = transceiver if transformers: self.transformers = transformers else: self.transformers = [Pickler()] if publisher: self.publisher = publisher else: self.publisher = ZMQPublisher() for i in range(len(self.transformers) - 1): self.transformers[i].set_callback(self.transformers[i + 1].push) self.transformers[-1].set_callback(self.publisher.send)
def run_reporter(): reporter = Reporter( transceiver=DummyTransceiver(dt=0.0005), transformers=[TimedCombiner(dt=0.1), Pickler(), Compressor()], publisher=ZMQPublisher()) reporter.run()
def __init__(self, transceiver, transformers=None, publisher=None): self.transceiver = transceiver if transformers: self.transformers = transformers else: self.transformers = [Pickler()] if publisher: self.publisher = publisher else: self.publisher = ZMQPublisher() for i in range(len(self.transformers) - 1): self.transformers[i].set_callback(self.transformers[i+1].push) self.transformers[-1].set_callback(self.publisher.send)
class Reporter(): """ A Reporter continuously reads data from a Transceiver, feeds it through a row of Transformers, and broadcasts the result using a Publisher. When creating a Reporter, you supply instances of a Transceiver, one or more Transformers, and a Publisher. If not specified, a pickling Transformer and the default Publisher are used. **Usage**:: reporter = Reporter( transceiver=MyTransceiver(), transformers=[MyDecoder(), MyCompressor(), ...], publisher=MyPublisher() ) A Reporter can be run as its own process:: reporter.run() Or stepped through by an external engine:: reporter.open() while not done: reporter.step() """ def __init__(self, transceiver, transformers=None, publisher=None): self.transceiver = transceiver if transformers: self.transformers = transformers else: self.transformers = [Pickler()] if publisher: self.publisher = publisher else: self.publisher = ZMQPublisher() for i in range(len(self.transformers) - 1): self.transformers[i].set_callback(self.transformers[i + 1].push) self.transformers[-1].set_callback(self.publisher.send) def open(self): """ Initialize the Transceiver and Publisher. """ success = self.transceiver.open() if not success: return False success = self.publisher.open() if not success: return False return True def step(self): """ Read data and feed it into the first Transformer. """ raw_data = self.transceiver.read() if raw_data is not None: self.transformers[0].push(raw_data) def run(self): """ Initialize components and start broadcasting. """ success = self.open() if not success: print('Failed to initialize!') return while True: self.step()
from zircon.transceivers.dummy_multiple import DummyMultipleTransceiver from zircon.publishers.zeromq import ZMQPublisher from zircon.reporters.base import Reporter from zircon.transformers.common import * from math import sin, pi from random import gauss reporter = Reporter( transceiver=DummyMultipleTransceiver( signals={ 'IMU_X': lambda x: 1.0 * sin(2*pi*(x/3.0 + 1)) + gauss(0, 0.2), 'IMU_Y': lambda x: 1.5 * sin(2*pi*x/2.5) + gauss(0, 0.2), 'IMU_Z': lambda x: 1.3 * sin(2*pi*x/2.8) + gauss(0, 0.3), 'IMU_X_FILTERED': lambda x: 1.0 * sin(2*pi*(x/3.0 + 1)), 'IMU_Y_FILTERED': lambda x: 1.5 * sin(2*pi*x/2.5), 'IMU_Z_FILTERED': lambda x: 1.3 * sin(2*pi*x/2.8), }, dt=0.01, ), transformers=[ Splitter(), TimedCombiner(dt=0.1), Pickler(), Compressor() ], publisher=ZMQPublisher() ) reporter.run()
class Reporter(): """ A Reporter continuously reads data from a Transceiver, feeds it through a row of Transformers, and broadcasts the result using a Publisher. When creating a Reporter, you supply instances of a Transceiver, one or more Transformers, and a Publisher. If not specified, a pickling Transformer and the default Publisher are used. **Usage**:: reporter = Reporter( transceiver=MyTransceiver(), transformers=[MyDecoder(), MyCompressor(), ...], publisher=MyPublisher() ) A Reporter can be run as its own process:: reporter.run() Or stepped through by an external engine:: reporter.open() while not done: reporter.step() """ def __init__(self, transceiver, transformers=None, publisher=None): self.transceiver = transceiver if transformers: self.transformers = transformers else: self.transformers = [Pickler()] if publisher: self.publisher = publisher else: self.publisher = ZMQPublisher() for i in range(len(self.transformers) - 1): self.transformers[i].set_callback(self.transformers[i+1].push) self.transformers[-1].set_callback(self.publisher.send) def open(self): """ Initialize the Transceiver and Publisher. """ success = self.transceiver.open() if not success: return False success = self.publisher.open() if not success: return False return True def step(self): """ Read data and feed it into the first Transformer. """ raw_data = self.transceiver.read() if raw_data is not None: self.transformers[0].push(raw_data) def run(self): """ Initialize components and start broadcasting. """ success = self.open() if not success: print('Failed to initialize!') return while True: self.step()