def transform(self, client, message): logging.info(f'Controller state: {State.name(self._state)}') if self.is_message_up_to_date(message): if message.belongs_to('processor_controller'): logging.info('Received message from Processor') state, current_time = message.data[-2:] time_elapsed = int(current_time - self._start_time) self.change_state(state) msg = gabby.Message( [*message.data[:-1], self._power_level, time_elapsed], topics=self.output_topics.filter_by( name='controller_transmitter' ) ) return [msg] elif message.belongs_to('kernel_controller'): logging.info('Received message from Kernel') data = (*message.data[:-1], self._state, message.data[-1]) return self.process_views(data) if message.belongs_to('kernelcontrol_controller'): logging.info('Received message from Kernel Control') return self.process_buttons(message.data) return []
def transform(self, client, message): logging.info(f'Received message from {message.topic}') if message.topic in ['ek', 'eq']: logging.debug( f"Data: {message.payload.decode('utf-8').split(';')}") *imu_data, imu_id = [ float(x) for x in message.payload.decode('utf-8').split(';') ] self.imus[int(imu_id)] = imu_data controller_data = [ *self.imus[0], *self.imus[1], self.weight_info, time.time() ] return [ gabby.Message( controller_data, self.output_topics.filter_by(name='kernel_controller')) ] elif message.topic == 'kernelcontrol_kernel': logging.debug("Received new force measure") decoded_msg = gabby.Message.decode( message.payload, self.input_topics.filter_by(name='kernelcontrol_kernel')) self.weight_info, = decoded_msg.data return []
def exec_buttons_reader(self): for new_state in self.get_buttons(): self.send( gabby.Message( new_state, self.output_topics.filter_by( name='kernelcontrol_controller')))
def transform(self, client, message): logging.info(f'Transforming data: {message.data}') logging.info(f'Processor state: {State.name(self._state)}') self.update_ahrs(message.data) self.calibrate_measures(*message.data[-2:]) v_data = self.euler_angles_visualizer_data(message.data) return [gabby.Message(v_data, self.output_topics)]
def process_views(self, data): return [ gabby.Message( data, topics=( self .output_topics .filter_by( name='controller_processor' ) ) ) ]
def process_buttons(self, buttons): button_up, button_down, button_reset = buttons old_power_level = self._power_level self.process_power_level(button_up, button_down) self.process_reset(button_reset) new_power_level = self._power_level if old_power_level != new_power_level: return [ gabby.Message( (new_power_level,), topics=( self .output_topics .filter_by( name='controller_kernelcontrol' ) ) ) ] return []
def transform(self, message): if message.belongs_to('esp_kernel'): logging.debug( f"Received message, data: {message.payload.decode('utf-8')}") imu_data = [float(x) for x in message.payload.decode('utf-8').split(';')] buttons_info = self.get_buttons() weight_info = self.get_weight() time_info = self.get_time() if message.belongs_to('transmitter_kernel'): logging.info(f'Received message from transmitter: {message.data}') button_data = message.data self.Controller_weigth(button_data) data = [*imu_data, time_info, *buttons_info, weight_info] return [gabby.Message(data, self.output_topics)]
def update_force_measure(self): for new_force_measure in self.get_force_measure(): self.send( gabby.Message( (new_force_measure, ), self.output_topics.filter_by(name='kernelcontrol_kernel')))