def test_all(): event_manager = EventManager() for i in range(16): set_threshhold(i, 0) aggregation_update(i, 0) test_range = range(-32,32) + range(32,0, -1) for i in range(16): for j in test_range: set_threshhold(i, j) time.sleep(0.01) for k in test_range: aggregation_update(i, k) time.sleep(0.01) set_threshhold(i, 15.0) aggregation_update(i, 16.0) time.sleep(0.01) event_manager.publish_packet(i, 16.0) time.sleep(0.5) aggregation_update(i, 11.0) event_manager.publish_failure(i) time.sleep(0.5)
def ros_event_callback(self, data): """ The callback function called when a ros pressure event is received :param data: Pressure data :return: """ sensor, value = EventManager.decode_sensor_message(data.data) if sensor is not None: sensor = str(sensor) self.sensor_widgets[sensor].trigger() self.master.after(100, self.sensor_widgets[sensor].remove_trigger)
def __init__(self, num_sensors=16, aggregation_window=5, fail_floor=12.0, fail_ceil=20.0): """ Create a new controller object :param num_sensors: The number of connected sensors :param aggregation_window: The number of values to maintain in the aggregation system :param fail_floor: The lower bound on reasonable values :param fail_ceil: The upper bound on reasonable values """ self.eventManager = EventManager() self.num_sensors = num_sensors self.aggregation_buffers = [AggregationBuffer(aggregation_window) for i in range(num_sensors)] # Initialize all thresholds to zero by default for i in range(num_sensors): set_threshhold(i, 0) auto_fail_absolute(fail_floor, fail_ceil) aggregation_initialize(num_sensors) filtering_initialize()
class Controller(object): def __init__(self, num_sensors=16, aggregation_window=5, fail_floor=12.0, fail_ceil=20.0): """ Create a new controller object :param num_sensors: The number of connected sensors :param aggregation_window: The number of values to maintain in the aggregation system :param fail_floor: The lower bound on reasonable values :param fail_ceil: The upper bound on reasonable values """ self.eventManager = EventManager() self.num_sensors = num_sensors self.aggregation_buffers = [AggregationBuffer(aggregation_window) for i in range(num_sensors)] # Initialize all thresholds to zero by default for i in range(num_sensors): set_threshhold(i, 0) auto_fail_absolute(fail_floor, fail_ceil) aggregation_initialize(num_sensors) filtering_initialize() def valid_pin(self, number): """ Check if a pin number is valid :param number: The number to check :return: True if it's a valid pin id, False if it is not """ return (number >= 0) and (number < self.num_sensors) def run(self): """ Run the controller event loop :return: """ comm = Communication(SERIAL_PORT) print("Running MAPS controller on serial port: %s" % (SERIAL_PORT)) try: weights = np.ones(dtype=np.float32, shape=(5,1))/5 while True: val, pin_id = comm.read_packet() if not self.valid_pin(pin_id): continue aggregation_update(pin_id, val) floor_thresh = get_floor_threshold(pin_id) ceil_thresh = get_ceil_threshold(pin_id) if not self.eventManager.check_failures(pin_id, val, ceil_thresh, floor_thresh): # no failures vals = self.aggregation_buffers[pin_id].history.T if get_filter_mode() != FILTER_NONE: filtered_val = apply_filter(vals) else: filtered_val = val self.eventManager.publish_packet(pin_id, filtered_val) self.aggregation_buffers[pin_id].add(val) else: self.eventManager.publish_failure(pin_id) self.eventManager.sleep() except rospy.ROSInterruptException: pass