Beispiel #1
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletSoundPressureLevel, *args)

        self.setupUi(self)

        self.sound_pressure_level = self.device
        self.cbe_get_decibel = CallbackEmulator(self,
                                                self.sound_pressure_level.get_decibel,
                                                None,
                                                self.cb_decibel,
                                                self.increase_error_count)

        self.qtcb_spectrum.connect(self.cb_spectrum)

        self.thermo = TuningThermo()

        plots_spectrum = [('Spectrum', Qt.red, None, '{} °C'.format)]
        self.plot_widget_spectrum = PlotWidget('Value [dB]', plots_spectrum, clear_button=None,
                                               x_diff=20480, x_scale_title_text='Frequency [Hz]',
                                               x_scale_skip_last_tick=False, key=None, y_resolution=0.1,
                                               y_scale_shrinkable=False)
        self.plot_widget_spectrum.set_x_scale(512*40//5, 1)

        self.combo_fft_size.currentIndexChanged.connect(self.config_changed)
        self.combo_weighting.currentIndexChanged.connect(self.config_changed)

        self.layout_graph.addWidget(self.plot_widget_spectrum)
        self.layout_decibel.insertWidget(3, self.thermo)

        self.last_spectrum_length = 512

        self.last_y_data = [0]*512
Beispiel #2
0
    def __init__(self, *args):
        super().__init__(BrickletCO2V2, *args)

        self.co2 = self.device

        self.cbe_all_values = CallbackEmulator(self,
                                               self.co2.get_all_values,
                                               None,
                                               self.cb_all_values,
                                               self.increase_error_count)

        self.current_co2 = CurveValueWrapper() # int, ppm
        self.current_temperature = CurveValueWrapper() # float, °C
        self.current_humidity = CurveValueWrapper() # float, %RH

        plots_co2 = [('CO2', Qt.red, self.current_co2, '{} PPM'.format)]
        self.plot_widget_co2 = PlotWidget('CO2 [PPM]', plots_co2, y_resolution=1.0)

        plots_temperature = [('Temperature', Qt.red, self.current_temperature, '{} °C'.format)]
        self.plot_widget_temperature = PlotWidget('Temperature [°C]', plots_temperature, y_resolution=0.01)

        plots_humidity = [('Relative Humidity', Qt.red, self.current_humidity, '{} %RH'.format)]
        self.plot_widget_humidity = PlotWidget('Relative Humidity [%RH]', plots_humidity, y_resolution=0.01)

        layout_plot1 = QHBoxLayout()
        layout_plot1.addWidget(self.plot_widget_co2)

        layout_plot2 = QHBoxLayout()
        layout_plot2.addWidget(self.plot_widget_temperature)
        layout_plot2.addWidget(self.plot_widget_humidity)

        layout_main = QVBoxLayout(self)
        layout_main.addLayout(layout_plot1)
        layout_main.addLayout(layout_plot2)
Beispiel #3
0
    def __init__(self, *args):
        super().__init__(BrickletHallEffect, *args)

        self.hf = self.device

        self.cbe_edge_count = CallbackEmulator(
            self,
            self.get_edge_count,
            False,
            self.cb_edge_count,
            self.increase_error_count,
            expand_result_tuple_for_callback=True)

        self.current_value = CurveValueWrapper()

        self.label_count = CountLabel('Count')

        plots = [('Value', Qt.red, self.current_value, str)]
        self.plot_widget = PlotWidget('Value',
                                      plots,
                                      extra_key_widgets=[self.label_count],
                                      update_interval=0.05)
        self.plot_widget.set_fixed_y_scale(0, 1, 1, 1)

        self.combo_edge_type = QComboBox()
        self.combo_edge_type.addItem('Rising')
        self.combo_edge_type.addItem('Falling')
        self.combo_edge_type.addItem('Both')
        self.combo_edge_type.currentIndexChanged.connect(self.edge_changed)

        self.spin_debounce = QSpinBox()
        self.spin_debounce.setMinimum(0)
        self.spin_debounce.setMaximum(255)
        self.spin_debounce.setValue(100)
        self.spin_debounce.editingFinished.connect(self.debounce_changed)

        self.button_reset = QPushButton('Reset Count')
        self.button_reset.clicked.connect(self.reset_count)

        hlayout = QHBoxLayout()
        hlayout.addWidget(QLabel('Edge Type:'))
        hlayout.addWidget(self.combo_edge_type)
        hlayout.addStretch()
        hlayout.addWidget(QLabel('Debounce Period [ms]:'))
        hlayout.addWidget(self.spin_debounce)
        hlayout.addStretch()
        hlayout.addWidget(self.button_reset)

        line = QFrame()
        line.setObjectName("line")
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)
Beispiel #4
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletEnergyMonitor, *args)

        self.setupUi(self)

        self.energy_monitor = self.device
        self.cbe_get_energy_data = CallbackEmulator(
            self.energy_monitor.get_energy_data, None, self.cb_energy_data,
            self.increase_error_count)
        self.cbe_get_transformer_status = CallbackEmulator(
            self.energy_monitor.get_transformer_status, None,
            self.cb_transformer_status, self.increase_error_count)

        plots_waveform_v = [('Waveform V', Qt.red, None, None)]
        self.plot_widget_waveform_v = PlotWidget(
            'Voltage [V]',
            plots_waveform_v,
            clear_button=None,
            x_diff=768 * ENERGY_MONITOR_MS_PER_TICK,
            x_scale_title_text='Time [ms]',
            key=None,
            x_scale_visible=False)

        plots_waveform_a = [('Waveform A', Qt.red, None, None)]
        self.plot_widget_waveform_a = PlotWidget(
            'Current [A]',
            plots_waveform_a,
            clear_button=None,
            x_diff=768 * ENERGY_MONITOR_MS_PER_TICK,
            x_scale_title_text='Time [ms]',
            key=None)

        self.plot_widget_waveform_v.add_y_scale_sibling(
            self.plot_widget_waveform_a)
        self.plot_widget_waveform_a.add_y_scale_sibling(
            self.plot_widget_waveform_v)

        # try to make the actual curve area equal in height by fiddling with the
        # minimum-height and the stretch factors
        self.plot_widget_waveform_v.setMinimumHeight(194)
        self.plot_widget_waveform_a.setMinimumHeight(250)
        self.layout_graph.insertWidget(0, self.plot_widget_waveform_v, 86)
        self.layout_graph.addWidget(self.plot_widget_waveform_a, 100)

        self.x_data = [
            x * ENERGY_MONITOR_MS_PER_TICK for x in list(range(768))
        ]

        self.button_energy.clicked.connect(self.button_energy_clicked)
        self.button_transformer_settings.clicked.connect(
            self.button_transformer_settings_clicked)

        self.voltage_connected = True
        self.current_connected = True

        self.running = False
Beispiel #5
0
    def __init__(self, *args):
        super().__init__(BrickletAirQuality, *args)

        self.air_quality = self.device

        self.cbe_all_values = CallbackEmulator(self,
                                               self.air_quality.get_all_values,
                                               None, self.cb_all_values,
                                               self.increase_error_count)

        self.current_iaq_index = CurveValueWrapper()  # float
        self.current_temperature = CurveValueWrapper()  # float, °C
        self.current_humidity = CurveValueWrapper()  # float, %RH
        self.current_air_pressure = CurveValueWrapper()  # float, hPa

        self.iaq_accuracy_label = QLabel("(Accuracy: TBD)")

        plots_iaq_index = [('IAQ Index', Qt.red, self.current_iaq_index,
                            '{}'.format)]
        self.plot_widget_iaq_index = PlotWidget(
            'IAQ Index',
            plots_iaq_index,
            extra_key_widgets=(self.iaq_accuracy_label, ),
            y_resolution=1.0)

        plots_temperature = [('Temperature', Qt.red, self.current_temperature,
                              '{} °C'.format)]
        self.plot_widget_temperature = PlotWidget('Temperature [°C]',
                                                  plots_temperature,
                                                  y_resolution=0.01)

        plots_humidity = [('Relative Humidity', Qt.red, self.current_humidity,
                           '{} %RH'.format)]
        self.plot_widget_humidity = PlotWidget('Relative Humidity [%RH]',
                                               plots_humidity,
                                               y_resolution=0.01)

        plots_air_pressure = [
            ('Air Pressure', Qt.red, self.current_air_pressure,
             '{} hPa (QFE)'.format)
        ]
        self.plot_widget_air_pressure = PlotWidget('Air Pressure [hPa]',
                                                   plots_air_pressure,
                                                   y_resolution=0.01)

        layout_plot1 = QHBoxLayout()
        layout_plot1.addWidget(self.plot_widget_iaq_index)
        layout_plot1.addWidget(self.plot_widget_temperature)

        layout_plot2 = QHBoxLayout()
        layout_plot2.addWidget(self.plot_widget_humidity)
        layout_plot2.addWidget(self.plot_widget_air_pressure)

        layout_main = QVBoxLayout(self)
        layout_main.addLayout(layout_plot1)
        layout_main.addLayout(layout_plot2)
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletVoltageCurrentV2, *args)

        self.setupUi(self)

        self.vc = self.device

        self.cbe_voltage = CallbackEmulator(self.vc.get_voltage, None,
                                            self.cb_voltage,
                                            self.increase_error_count)
        self.cbe_current = CallbackEmulator(self.vc.get_current, None,
                                            self.cb_current,
                                            self.increase_error_count)
        self.cbe_power = CallbackEmulator(self.vc.get_power, None,
                                          self.cb_power,
                                          self.increase_error_count)

        self.current_voltage = CurveValueWrapper()  # float, V
        self.current_current = CurveValueWrapper()  # float, A
        self.current_power = CurveValueWrapper()  # float, W

        plots_voltage = [('Voltage', Qt.red, self.current_voltage,
                          format_voltage)]
        plots_current = [('Current', Qt.blue, self.current_current,
                          format_current)]
        plots_power = [('Power', Qt.darkGreen, self.current_power,
                        format_power)]
        self.plot_widget_voltage = PlotWidget(
            'Voltage [V]',
            plots_voltage,
            clear_button=self.button_clear_graphs,
            y_resolution=0.001)
        self.plot_widget_current = PlotWidget(
            'Current [A]',
            plots_current,
            clear_button=self.button_clear_graphs,
            y_resolution=0.001)
        self.plot_widget_power = PlotWidget(
            'Power [W]',
            plots_power,
            clear_button=self.button_clear_graphs,
            y_resolution=0.001)

        self.save_conf_button.clicked.connect(self.save_conf_clicked)

        self.calibration = None
        self.button_calibration.clicked.connect(self.calibration_clicked)

        hlayout = QHBoxLayout()
        hlayout.addWidget(self.plot_widget_voltage)
        hlayout.addWidget(self.plot_widget_current)
        hlayout.addWidget(self.plot_widget_power)

        self.main_layout.insertLayout(0, hlayout)
Beispiel #7
0
    def __init__(self, *args):
        super().__init__(BrickletHumidityV2, *args)

        self.hum = self.device

        self.cbe_humidity = CallbackEmulator(self.hum.get_humidity, None,
                                             self.cb_humidity,
                                             self.increase_error_count)

        self.cbe_temperature = CallbackEmulator(self.hum.get_temperature, None,
                                                self.cb_temperature,
                                                self.increase_error_count)

        self.current_humidity = CurveValueWrapper()  # float, %RH
        self.current_temperature = CurveValueWrapper()  # float, °C

        moving_average_humidity = MovingAverageConfig(
            1, 1000, self.new_moving_average_humidity)
        plots_humidity = [('Relative Humidity', Qt.red, self.current_humidity,
                           '{} %RH'.format)]
        self.plot_widget_humidity = PlotWidget(
            'Relative Humidity [%RH]',
            plots_humidity,
            moving_average_config=moving_average_humidity,
            y_resolution=0.01)

        moving_average_temperature = MovingAverageConfig(
            1, 1000, self.new_moving_average_temperature)
        plots_temperature = [('Temperature', Qt.red, self.current_temperature,
                              '{} °C'.format)]
        self.plot_widget_temperature = PlotWidget(
            'Temperature [°C]',
            plots_temperature,
            moving_average_config=moving_average_temperature,
            y_resolution=0.01)

        self.enable_heater = QCheckBox("Enable Heater")
        self.enable_heater.stateChanged.connect(self.enable_heater_changed)

        layout_plot = QHBoxLayout()
        layout_plot.addWidget(self.plot_widget_humidity)
        layout_plot.addWidget(self.plot_widget_temperature)

        layout_config = QHBoxLayout()
        layout_config.addStretch()
        layout_config.addWidget(self.enable_heater)
        layout_config.addStretch()

        layout_main = QVBoxLayout(self)
        layout_main.addLayout(layout_plot)
        layout_main.addLayout(layout_config)
Beispiel #8
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletHumidityV2, *args)

        self.hum = self.device

        self.cbe_humidity = CallbackEmulator(self.hum.get_humidity,
                                             self.cb_humidity,
                                             self.increase_error_count)

        self.cbe_temperature = CallbackEmulator(self.hum.get_temperature,
                                                self.cb_temperature,
                                                self.increase_error_count)

        self.current_humidity = None  # float, %RH
        self.current_temperature = None  # float, °C

        moving_average_humidity = MovingAverageConfig(
            1, 1000, self.new_moving_average_humidity)
        plots_humidity = [(u'Relative Humidity', Qt.red,
                           lambda: self.current_humidity, u'{} %RH'.format)]
        self.plot_widget_humidity = PlotWidget(
            u'Relative Humidity [%RH]',
            plots_humidity,
            moving_average_config=moving_average_humidity)

        moving_average_temperature = MovingAverageConfig(
            1, 1000, self.new_moving_average_temperature)
        plots_temperature = [
            (u'Temperature', Qt.red, lambda: self.current_temperature,
             u'{} °C'.format)
        ]
        self.plot_widget_temperature = PlotWidget(
            u'Temperature [°C]',
            plots_temperature,
            moving_average_config=moving_average_temperature)

        self.enable_heater = QCheckBox("Enable Heater")
        self.enable_heater.stateChanged.connect(self.enable_heater_changed)

        layout_plot = QHBoxLayout()
        layout_plot.addWidget(self.plot_widget_humidity)
        layout_plot.addWidget(self.plot_widget_temperature)

        layout_config = QHBoxLayout()
        layout_config.addStretch()
        layout_config.addWidget(self.enable_heater)
        layout_config.addStretch()

        layout_main = QVBoxLayout(self)
        layout_main.addLayout(layout_plot)
        layout_main.addLayout(layout_config)
Beispiel #9
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletAmbientLight, *args)

        self.al = self.device

        self.cbe_illuminance = CallbackEmulator(self.al.get_illuminance,
                                                self.cb_illuminance,
                                                self.increase_error_count)

        self.illuminance_label = IlluminanceLabel('Illuminance: ')
        self.alf = AmbientLightFrame()

        self.current_value = None

        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Illuminance [lx]', plot_list)

        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.illuminance_label)
        layout_h.addWidget(self.alf)
        layout_h.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h)
        layout.addWidget(self.plot_widget)
Beispiel #10
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletLine, *args)

        self.line = self.device

        self.cbe_reflectivity = CallbackEmulator(self.line.get_reflectivity,
                                                 self.cb_reflectivity,
                                                 self.increase_error_count)

        self.reflectivity_label = ReflectivityLabel()
        self.rf = ReflectivityFrame()

        self.current_value = None

        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Reflectivity', plot_list)

        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.reflectivity_label)
        layout_h.addStretch()

        layout_h2 = QHBoxLayout()
        layout_h2.addStretch()
        layout_h2.addWidget(self.rf)
        layout_h2.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h)
        layout.addLayout(layout_h2)
        layout.addWidget(self.plot_widget)
Beispiel #11
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletCO2, *args)

        self.co2 = self.device

        self.cbe_co2_concentration = CallbackEmulator(
            self.co2.get_co2_concentration, self.cb_co2_concentration,
            self.increase_error_count)

        self.co2_concentration_label = CO2ConcentrationLabel(
            'CO2 Concentration: ')

        self.current_value = None

        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('CO2 Concentration [ppm]', plot_list)

        layout_h2 = QHBoxLayout()
        layout_h2.addStretch()
        layout_h2.addWidget(self.co2_concentration_label)
        layout_h2.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h2)
        layout.addWidget(self.plot_widget)
Beispiel #12
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletRotaryPoti, *args)

        self.rp = self.device

        self.cbe_position = CallbackEmulator(self.rp.get_position,
                                             self.cb_position,
                                             self.increase_error_count)

        self.position_knob = KnobWidget(self)
        self.position_knob.setFocusPolicy(Qt.NoFocus)
        self.position_knob.set_total_angle(300)
        self.position_knob.set_range(-150, 150)
        self.position_knob.set_scale(30, 3)
        self.position_knob.set_knob_radius(25)

        self.current_position = None

        plots = [('Position', Qt.red, lambda: self.current_position, str)]
        self.plot_widget = PlotWidget('Position',
                                      plots,
                                      curve_motion_granularity=40,
                                      update_interval=0.025)

        layout = QHBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(self.position_knob)
Beispiel #13
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletHallEffectV2, *args)

        self.setupUi(self)

        self.hf = self.device

        self.cbe_magnetic_flux_density = CallbackEmulator(
            self.hf.get_magnetic_flux_density, None,
            self.cb_magnetic_flux_density, self.increase_error_count)
        self.cbe_counter = CallbackEmulator(self.get_counter, False,
                                            self.cb_counter,
                                            self.increase_error_count)

        self.current_magnetic_flux_density = CurveValueWrapper()
        plots = [('Magnetic Flux Density', Qt.red,
                  self.current_magnetic_flux_density, '{} µT'.format)]
        self.plot_widget = PlotWidget('Magnetic Flux Density [µT]',
                                      plots,
                                      y_resolution=1.0)

        self.button_reset.clicked.connect(self.button_reset_clicked)
        self.spinbox_low.editingFinished.connect(self.new_config)
        self.spinbox_high.editingFinished.connect(self.new_config)
        self.spinbox_debounce.editingFinished.connect(self.new_config)

        self.main_vert_layout.insertWidget(0, self.plot_widget)
Beispiel #14
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletLoadCell, *args)

        self.lc = self.device

        self.cbe_weight = CallbackEmulator(self.lc.get_weight, self.cb_weight,
                                           self.increase_error_count)

        self.weight_label = WeightLabel()

        self.gain = 0  # 128x
        self.current_value = None
        self.calibration = None

        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Weight [g]', plot_list)

        self.button_calibration = QPushButton("Calibration")
        self.button_calibration.clicked.connect(
            self.button_calibration_clicked)

        self.button_tare = QPushButton("Tare")
        self.button_tare.clicked.connect(self.button_tare_clicked)

        self.enable_led = QCheckBox("LED On")
        self.enable_led.stateChanged.connect(self.enable_led_changed)

        self.spin_average = QSpinBox()
        self.spin_average.setMinimum(0)
        self.spin_average.setMaximum(40)
        self.spin_average.setSingleStep(1)
        self.spin_average.setValue(5)
        self.spin_average.editingFinished.connect(self.spin_average_finished)
        self.label_average = QLabel('Length of moving average:')

        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.weight_label)
        layout_h.addStretch()

        self.rate_label = QLabel('Rate: ')
        self.rate_combo = QComboBox()
        self.rate_combo.addItem("10Hz")
        self.rate_combo.addItem("80Hz")
        self.rate_combo.currentIndexChanged.connect(self.new_config)

        layout_avg = QHBoxLayout()
        layout_avg.addWidget(self.label_average)
        layout_avg.addWidget(self.spin_average)
        layout_avg.addWidget(self.rate_label)
        layout_avg.addWidget(self.rate_combo)
        layout_avg.addStretch()
        layout_avg.addWidget(self.button_calibration)
        layout_avg.addWidget(self.button_tare)
        layout_avg.addWidget(self.enable_led)

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h)
        layout.addWidget(self.plot_widget)
        layout.addLayout(layout_avg)
Beispiel #15
0
    def __init__(self, *args):
        super().__init__(BrickletTemperatureV2, *args)

        self.tem = self.device

        self.cbe_temperature = CallbackEmulator(self.tem.get_temperature, None,
                                                self.cb_temperature,
                                                self.increase_error_count)

        self.current_temperature = CurveValueWrapper()  # float, °C

        plots_temperature = [('Temperature', Qt.red, self.current_temperature,
                              '{} °C'.format)]
        self.plot_widget_temperature = PlotWidget('Temperature [°C]',
                                                  plots_temperature,
                                                  y_resolution=0.01)

        self.enable_heater = QCheckBox("Enable Heater")
        self.enable_heater.stateChanged.connect(self.enable_heater_changed)

        layout_plot = QHBoxLayout()
        layout_plot.addWidget(self.plot_widget_temperature)

        layout_config = QHBoxLayout()
        layout_config.addStretch()
        layout_config.addWidget(self.enable_heater)
        layout_config.addStretch()

        layout_main = QVBoxLayout(self)
        layout_main.addLayout(layout_plot)
        layout_main.addLayout(layout_config)
Beispiel #16
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletLinearPoti, *args)
        
        self.lp = self.device

        self.cbe_position = CallbackEmulator(self.lp.get_position,
                                             self.cb_position,
                                             self.increase_error_count)

        self.slider = QSlider(Qt.Horizontal)
        self.slider.setRange(0, 100)
        
        self.position_label = PositionLabel('Position: ')
        
        self.current_value = None

        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Position', plot_list)
        
        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.position_label)
        layout_h.addWidget(self.slider)
        layout_h.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h)
        layout.addWidget(self.plot_widget)
Beispiel #17
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletOzone, *args)

        self.ozone = self.device

        self.cbe_ozone_concentration = CallbackEmulator(
            self.ozone.get_ozone_concentration, self.cb_ozone_concentration,
            self.increase_error_count)

        self.current_ozone_concentration = None

        plots = [('Ozone Concentration', Qt.red,
                  lambda: self.current_ozone_concentration, '{} ppb'.format)]
        self.plot_widget = PlotWidget('Ozone Concentration [ppb]', plots)

        self.spin_average = QSpinBox()
        self.spin_average.setMinimum(1)
        self.spin_average.setMaximum(50)
        self.spin_average.setSingleStep(1)
        self.spin_average.setValue(50)
        self.spin_average.editingFinished.connect(self.spin_average_finished)

        hlayout = QHBoxLayout()
        hlayout.addWidget(QLabel('Moving Average Length:'))
        hlayout.addWidget(self.spin_average)
        hlayout.addStretch()

        line = QFrame()
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)
Beispiel #18
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletDistanceUS, *args)

        self.dist = self.device

        self.cbe_distance = CallbackEmulator(self.dist.get_distance_value,
                                             self.cb_distance,
                                             self.increase_error_count)

        self.current_distance = None

        plots = [('Distance Value', Qt.red, lambda: self.current_distance, str)
                 ]
        self.plot_widget = PlotWidget('Distance Value', plots)

        self.spin_average = QSpinBox()
        self.spin_average.setMinimum(0)
        self.spin_average.setMaximum(100)
        self.spin_average.setSingleStep(1)
        self.spin_average.setValue(20)
        self.spin_average.editingFinished.connect(self.spin_average_finished)

        hlayout = QHBoxLayout()
        hlayout.addWidget(QLabel('Moving Average Length:'))
        hlayout.addWidget(self.spin_average)
        hlayout.addStretch()

        line = QFrame()
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)
Beispiel #19
0
    def __init__(self, *args):
        super().__init__(BrickletCurrent12, *args)

        self.cur = self.device

        self.cbe_current = CallbackEmulator(self.cur.get_current, None,
                                            self.cb_current,
                                            self.increase_error_count)

        self.qtcb_over.connect(self.cb_over)
        self.cur.register_callback(self.cur.CALLBACK_OVER_CURRENT,
                                   self.qtcb_over.emit)

        self.over_label = QLabel('Over Current: No')
        self.calibrate_button = QPushButton('Calibrate Zero')
        self.calibrate_button.clicked.connect(self.calibrate_clicked)

        self.current_current = CurveValueWrapper()  # float, A

        plots = [('Current', Qt.red, self.current_current, format_current)]
        self.plot_widget = PlotWidget('Current [A]',
                                      plots,
                                      extra_key_widgets=[self.over_label],
                                      y_resolution=0.001)

        line = QFrame()
        line.setObjectName("line")
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addWidget(self.calibrate_button)
Beispiel #20
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletTemperatureV2, *args)

        self.tem = self.device

        self.cbe_temperature = CallbackEmulator(self.tem.get_temperature,
                                                self.cb_temperature,
                                                self.increase_error_count)

        self.current_temperature = None # float, °C
        
        plots_temperature = [(u'Temperature', Qt.red, lambda: self.current_temperature, u'{} °C'.format)]
        self.plot_widget_temperature = PlotWidget(u'Temperature [°C]', plots_temperature)

        self.enable_heater = QCheckBox("Enable Heater")
        self.enable_heater.stateChanged.connect(self.enable_heater_changed)

        layout_plot = QHBoxLayout()
        layout_plot.addWidget(self.plot_widget_temperature)
        
        layout_config = QHBoxLayout()
        layout_config.addStretch()
        layout_config.addWidget(self.enable_heater)
        layout_config.addStretch()
        
        layout_main = QVBoxLayout(self)
        layout_main.addLayout(layout_plot)
        layout_main.addLayout(layout_config)
Beispiel #21
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletHeartRate, *args)

        self.hr = self.device

        self.cbe_heart_rate = CallbackEmulator(self.hr.get_heart_rate,
                                               self.cb_heart_rate,
                                               self.increase_error_count)

        # FIXME: add beat state getter to Heart Rate Bricklet API
        self.qtcb_beat_state_changed.connect(self.cb_beat_state_changed)
        self.hr.register_callback(self.hr.CALLBACK_BEAT_STATE_CHANGED,
                                  self.qtcb_beat_state_changed.emit)

        self.heart_white_bitmap = load_masked_pixmap('plugin_system/plugins/heart_rate/heart_white_small.bmp')
        self.heart_red_bitmap = load_masked_pixmap('plugin_system/plugins/heart_rate/heart_red_small.bmp')
        self.heart_icon = QLabel()
        self.heart_icon.setPixmap(self.heart_white_bitmap)

        self.current_heart_rate = None

        plots = [('Heart Rate', Qt.red, lambda: self.current_heart_rate, '{} BPM'.format)]
        self.plot_widget = PlotWidget('Heart Rate [BPM]', plots, extra_key_widgets=[self.heart_icon])

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
Beispiel #22
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletAnalogInV2, *args)

        self.ai = self.device

        self.cbe_voltage = CallbackEmulator(self.ai.get_voltage,
                                            self.cb_voltage,
                                            self.increase_error_count)

        self.current_voltage = None  # float, V

        plots = [('Voltage', Qt.red, lambda: self.current_voltage,
                  format_voltage)]
        self.plot_widget = PlotWidget('Voltage [V]', plots)

        self.spin_average = QSpinBox()
        self.spin_average.setMinimum(1)
        self.spin_average.setMaximum(50)
        self.spin_average.setSingleStep(1)
        self.spin_average.setValue(50)
        self.spin_average.editingFinished.connect(self.spin_average_finished)

        layout_h1 = QHBoxLayout()
        layout_h1.addWidget(QLabel('Moving Average Length:'))
        layout_h1.addWidget(self.spin_average)
        layout_h1.addStretch()

        line = QFrame()
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(layout_h1)
Beispiel #23
0
    def __init__(self, *args):
        super().__init__(BrickletMotorizedLinearPoti, *args)

        self.mp = self.device

        self.cbe_position = CallbackEmulator(self.mp.get_position, None,
                                             self.cb_position,
                                             self.increase_error_count)

        self.current_position = CurveValueWrapper()

        self.slider = QSlider(Qt.Horizontal)
        self.slider.setRange(0, 100)
        self.slider.setMinimumWidth(200)
        self.slider.setEnabled(False)

        plots = [('Potentiometer Position', Qt.red, self.current_position, str)
                 ]
        self.plot_widget = PlotWidget('Position',
                                      plots,
                                      extra_key_widgets=[self.slider],
                                      update_interval=0.025,
                                      y_resolution=1.0)

        self.motor_slider = QSlider(Qt.Horizontal)
        self.motor_slider.setRange(0, 100)
        self.motor_slider.valueChanged.connect(self.motor_slider_value_changed)
        self.motor_hold_position = QCheckBox("Hold Position")
        self.motor_drive_mode = QComboBox()
        self.motor_drive_mode.addItem('Fast')
        self.motor_drive_mode.addItem('Smooth')

        def get_motor_slider_value():
            return self.motor_slider.value()

        self.motor_hold_position.stateChanged.connect(
            lambda x: self.motor_slider_value_changed(get_motor_slider_value()
                                                      ))
        self.motor_drive_mode.currentIndexChanged.connect(
            lambda x: self.motor_slider_value_changed(get_motor_slider_value()
                                                      ))

        self.motor_position_label = MotorPositionLabel(
            'Motor Target Position:')

        hlayout = QHBoxLayout()
        hlayout.addWidget(self.motor_position_label)
        hlayout.addWidget(self.motor_slider)
        hlayout.addWidget(self.motor_drive_mode)
        hlayout.addWidget(self.motor_hold_position)

        line = QFrame()
        line.setObjectName("line")
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)
Beispiel #24
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletUVLight, *args)

        self.uv_light = self.device

        self.cbe_uv_light = CallbackEmulator(self.uv_light.get_uv_light,
                                             self.cb_uv_light,
                                             self.increase_error_count)

        self.uv_label = UVLabel(u'UV Light: ')
        self.index_label = IndexLabel(u'UV Index: ')

        self.current_uv_light = None
        
        plot_list = [['', Qt.red, self.get_current_uv_light]]
        self.plot_widget_uv = PlotWidget(u'UV Light [µW/cm²]', plot_list)
        
        layout_h1 = QHBoxLayout()
        layout_h1.addStretch()
        layout_h1.addWidget(self.uv_label)
        layout_h1.addStretch()
        
        layout_h2 = QHBoxLayout()
        layout_h2.addStretch()
        layout_h2.addWidget(self.index_label)
        layout_h2.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h1)
        layout.addLayout(layout_h2)
        layout.addWidget(self.plot_widget_uv)
Beispiel #25
0
    def __init__(self, *args):
        super().__init__(BrickletDistanceUSV2, *args)

        self.dist = self.device

        self.cbe_distance = CallbackEmulator(self, self.dist.get_distance,
                                             None, self.cb_distance,
                                             self.increase_error_count)

        self.current_distance = CurveValueWrapper()

        plots = [('Distance', Qt.red, self.current_distance,
                  '{:.1f} cm'.format)]
        self.plot_widget = PlotWidget('Distance [cm]', plots, y_resolution=1.0)

        self.update_rate_label = QLabel('Update Rate:')
        self.update_rate_combo = QComboBox()
        self.update_rate_combo.addItem(" 2 Hz")
        self.update_rate_combo.addItem("10 Hz")

        self.update_rate_combo.currentIndexChanged.connect(
            self.new_update_rate)

        hlayout = QHBoxLayout()
        hlayout.addWidget(self.update_rate_label)
        hlayout.addWidget(self.update_rate_combo)
        hlayout.addStretch()

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addLayout(hlayout)
Beispiel #26
0
    def __init__(self, *args):
        super().__init__(BrickletRotaryPoti, *args)

        self.rp = self.device

        self.cbe_position = CallbackEmulator(self.rp.get_position, None,
                                             self.cb_position,
                                             self.increase_error_count)

        self.position_knob = KnobWidget(self)
        self.position_knob.setFocusPolicy(Qt.NoFocus)
        self.position_knob.set_total_angle(300)
        self.position_knob.set_range(-150, 150)
        self.position_knob.set_scale(30, 3)
        self.position_knob.set_knob_radius(25)

        self.current_position = CurveValueWrapper()

        plots = [('Position', Qt.red, self.current_position, str)]
        self.plot_widget = PlotWidget('Position',
                                      plots,
                                      update_interval=0.025,
                                      y_resolution=1.0)

        layout = QHBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(self.position_knob)
Beispiel #27
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletCurrent25, *args)

        self.cur = self.device

        self.cbe_current = CallbackEmulator(self.cur.get_current,
                                            self.cb_current,
                                            self.increase_error_count)

        self.qtcb_over.connect(self.cb_over)
        self.cur.register_callback(self.cur.CALLBACK_OVER_CURRENT,
                                   self.qtcb_over.emit)

        self.over_label = QLabel('Over Current: No')
        self.calibrate_button = QPushButton('Calibrate Zero')
        self.calibrate_button.clicked.connect(self.calibrate_clicked)

        self.current_current = None # float, A

        plots = [('Current', Qt.red, lambda: self.current_current, format_current)]
        self.plot_widget = PlotWidget('Current [A]', plots, extra_key_widgets=[self.over_label])

        line = QFrame()
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addWidget(self.calibrate_button)
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletSoundPressureLevel, *args)

        self.setupUi(self)

        self.sound_pressure_level = self.device
        self.cbe_get_decibel = CallbackEmulator(self.sound_pressure_level.get_decibel,
                                                None,
                                                self.cb_decibel,
                                                self.increase_error_count)

        self.qtcb_spectrum.connect(self.cb_spectrum)

        self.thermo = TuningThermo()

        plots_spectrum = [('Spectrum', Qt.red, None, '{} °C'.format)]
        self.plot_widget_spectrum = PlotWidget('Value [dB]', plots_spectrum, clear_button=None,
                                               x_diff=20480, x_scale_title_text='Frequency [Hz]',
                                               x_scale_skip_last_tick=False, key=None, y_resolution=0.1,
                                               y_scale_shrinkable=False)
        self.plot_widget_spectrum.set_x_scale(512*40//5, 1)

        self.combo_fft_size.currentIndexChanged.connect(self.config_changed)
        self.combo_weighting.currentIndexChanged.connect(self.config_changed)

        self.layout_graph.addWidget(self.plot_widget_spectrum)
        self.layout_decibel.insertWidget(3, self.thermo)

        self.last_spectrum_length = 512

        self.last_y_data = [0]*512
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletIndustrialDual020mA, *args)

        self.dual020 = self.device
        
        self.str_connected = 'Sensor {0} is currently <font color="green">connected</font>'
        self.str_not_connected = 'Sensor {0} is currently <font color="red">not connected</font>'

        self.cbe_current0 = CallbackEmulator(functools.partial(self.dual020.get_current, 0),
                                             functools.partial(self.cb_current, 0),
                                             self.increase_error_count)
        self.cbe_current1 = CallbackEmulator(functools.partial(self.dual020.get_current, 1),
                                             functools.partial(self.cb_current, 1),
                                             self.increase_error_count)

        self.current_label = [CurrentLabel(), CurrentLabel()]
        
        self.sample_rate_label1 = QLabel('Sample Rate:')
        self.sample_rate_combo = QComboBox()
        self.sample_rate_combo.addItem('240')
        self.sample_rate_combo.addItem('60')
        self.sample_rate_combo.addItem('15')
        self.sample_rate_combo.addItem('4')
        self.sample_rate_label2 = QLabel('Samples per second')
        
        self.connected_label = [QLabel(self.str_not_connected.format(0)),
                                QLabel(self.str_not_connected.format(1))]
        
        self.current_value = [None, None]
        
        self.sample_rate_combo.currentIndexChanged.connect(self.sample_rate_combo_index_changed)
        
        plot_list = [['Sensor 0', Qt.red, self.get_current_value0],
                     ['Sensor 1', Qt.blue, self.get_current_value1]]
        self.plot_widget = PlotWidget('Current [mA]', plot_list)
        
        layout_h = QHBoxLayout()
        layout_h.addWidget(QLabel("Sensor 0: "))
        layout_h.addWidget(self.current_label[0])
        layout_h.addStretch()
        layout_h.addWidget(self.connected_label[0])
        
        layout_h2 = QHBoxLayout()
        layout_h2.addWidget(QLabel("Sensor 1: "))
        layout_h2.addWidget(self.current_label[1])
        layout_h2.addStretch()
        layout_h2.addWidget(self.connected_label[1])
        
        layout_h3 = QHBoxLayout()
        layout_h3.addWidget(self.sample_rate_label1)
        layout_h3.addWidget(self.sample_rate_combo)
        layout_h3.addWidget(self.sample_rate_label2)
        layout_h3.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h)
        layout.addLayout(layout_h2)
        layout.addWidget(self.plot_widget)
        layout.addLayout(layout_h3)
Beispiel #30
0
    def __init__(self, *args):
        super().__init__(BrickletPTC, *args)

        self.ptc = self.device

        self.str_connected = 'Sensor is <font color="green">connected</font>'
        self.str_not_connected = 'Sensor is <font color="red">not connected</font>'

        self.cbe_temperature = CallbackEmulator(self, self.ptc.get_temperature,
                                                None, self.cb_temperature,
                                                self.increase_error_count)

        self.wire_label = QLabel('Wire Type:')
        self.wire_combo = QComboBox()
        self.wire_combo.addItem('2-Wire')
        self.wire_combo.addItem('3-Wire')
        self.wire_combo.addItem('4-Wire')

        self.noise_label = QLabel('Noise Rejection Filter:')
        self.noise_combo = QComboBox()
        self.noise_combo.addItem('50 Hz')
        self.noise_combo.addItem('60 Hz')

        self.connected_label = QLabel(self.str_connected)

        self.current_temperature = CurveValueWrapper()  # float, °C

        self.wire_combo.currentIndexChanged.connect(
            self.wire_combo_index_changed)
        self.noise_combo.currentIndexChanged.connect(
            self.noise_combo_index_changed)

        plots = [('Temperature', Qt.red, self.current_temperature,
                  '{} °C'.format)]
        self.plot_widget = PlotWidget('Temperature [°C]',
                                      plots,
                                      extra_key_widgets=[self.connected_label],
                                      y_resolution=0.01)

        hlayout = QHBoxLayout()
        hlayout.addWidget(self.wire_label)
        hlayout.addWidget(self.wire_combo)
        hlayout.addStretch()
        hlayout.addWidget(self.noise_label)
        hlayout.addWidget(self.noise_combo)

        line = QFrame()
        line.setObjectName("line")
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)

        self.connected_timer = QTimer(self)
        self.connected_timer.timeout.connect(self.update_connected)
        self.connected_timer.setInterval(1000)
Beispiel #31
0
    def __init__(self, *args):
        super().__init__(BrickletLoadCell, *args)

        self.lc = self.device

        self.cbe_weight = CallbackEmulator(self.lc.get_weight, None,
                                           self.cb_weight,
                                           self.increase_error_count)

        self.gain = 0  # 128x
        self.current_weight = CurveValueWrapper()  # int, g
        self.calibration = None

        plots = [('Weight', Qt.red, self.current_weight, format_weight)]
        self.plot_widget = PlotWidget('Weight [g]', plots, y_resolution=1.0)

        self.button_calibration = QPushButton("Calibration...")
        self.button_calibration.clicked.connect(
            self.button_calibration_clicked)

        self.button_tare = QPushButton("Tare")
        self.button_tare.clicked.connect(self.button_tare_clicked)

        self.enable_led = QCheckBox("Enable LED")
        self.enable_led.stateChanged.connect(self.enable_led_changed)

        self.spin_average = QSpinBox()
        self.spin_average.setMinimum(0)
        self.spin_average.setMaximum(40)
        self.spin_average.setSingleStep(1)
        self.spin_average.setValue(5)
        self.spin_average.editingFinished.connect(self.spin_average_finished)
        self.label_average = QLabel('Moving Average Length:')

        self.rate_label = QLabel('Rate:')
        self.rate_combo = QComboBox()
        self.rate_combo.addItem("10 Hz")
        self.rate_combo.addItem("80 Hz")
        self.rate_combo.currentIndexChanged.connect(self.new_config)

        hlayout = QHBoxLayout()
        hlayout.addWidget(self.label_average)
        hlayout.addWidget(self.spin_average)
        hlayout.addWidget(self.rate_label)
        hlayout.addWidget(self.rate_combo)
        hlayout.addStretch()
        hlayout.addWidget(self.button_calibration)
        hlayout.addWidget(self.button_tare)
        hlayout.addWidget(self.enable_led)

        line = QFrame()
        line.setObjectName("line")
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)
Beispiel #32
0
    def __init__(self, *args):
        super().__init__(BrickletHumidityV2, *args)

        self.hum = self.device

        self.cbe_humidity = CallbackEmulator(self.hum.get_humidity,
                                             None,
                                             self.cb_humidity,
                                             self.increase_error_count)

        self.cbe_temperature = CallbackEmulator(self.hum.get_temperature,
                                                None,
                                                self.cb_temperature,
                                                self.increase_error_count)

        self.current_humidity = CurveValueWrapper() # float, %RH
        self.current_temperature = CurveValueWrapper() # float, °C

        moving_average_humidity = MovingAverageConfig(1, 1000, self.new_moving_average_humidity)
        plots_humidity = [('Relative Humidity', Qt.red, self.current_humidity, '{} %RH'.format)]
        self.plot_widget_humidity = PlotWidget('Relative Humidity [%RH]', plots_humidity,
                                               moving_average_config=moving_average_humidity, y_resolution=0.01)

        moving_average_temperature = MovingAverageConfig(1, 1000, self.new_moving_average_temperature)
        plots_temperature = [('Temperature', Qt.red, self.current_temperature, '{} °C'.format)]
        self.plot_widget_temperature = PlotWidget('Temperature [°C]', plots_temperature,
                                                  moving_average_config=moving_average_temperature, y_resolution=0.01)

        self.enable_heater = QCheckBox("Enable Heater")
        self.enable_heater.stateChanged.connect(self.enable_heater_changed)

        layout_plot = QHBoxLayout()
        layout_plot.addWidget(self.plot_widget_humidity)
        layout_plot.addWidget(self.plot_widget_temperature)

        layout_config = QHBoxLayout()
        layout_config.addStretch()
        layout_config.addWidget(self.enable_heater)
        layout_config.addStretch()

        layout_main = QVBoxLayout(self)
        layout_main.addLayout(layout_plot)
        layout_main.addLayout(layout_config)
Beispiel #33
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletEnergyMonitor, *args)

        self.setupUi(self)

        self.energy_monitor = self.device
        self.cbe_get_energy_data = CallbackEmulator(self.energy_monitor.get_energy_data,
                                                    None,
                                                    self.cb_energy_data,
                                                    self.increase_error_count)
        self.cbe_get_transformer_status = CallbackEmulator(self.energy_monitor.get_transformer_status,
                                                           None,
                                                           self.cb_transformer_status,
                                                           self.increase_error_count)

        plots_waveform_v = [('Waveform V', Qt.red, None, None)]
        self.plot_widget_waveform_v = PlotWidget('Voltage [V]', plots_waveform_v, clear_button=None, x_diff=768*ENERGY_MONITOR_MS_PER_TICK, x_scale_title_text='Time [ms]', key=None, x_scale_visible=False)

        plots_waveform_a = [('Waveform A', Qt.red, None, None)]
        self.plot_widget_waveform_a = PlotWidget('Current [A]', plots_waveform_a, clear_button=None, x_diff=768*ENERGY_MONITOR_MS_PER_TICK, x_scale_title_text='Time [ms]', key=None)

        self.plot_widget_waveform_v.add_y_scale_sibling(self.plot_widget_waveform_a)
        self.plot_widget_waveform_a.add_y_scale_sibling(self.plot_widget_waveform_v)

        # try to make the actual curve area equal in height by fiddling with the
        # minimum-height and the stretch factors
        self.plot_widget_waveform_v.setMinimumHeight(194)
        self.plot_widget_waveform_a.setMinimumHeight(250)
        self.layout_graph.insertWidget(0, self.plot_widget_waveform_v, 86)
        self.layout_graph.addWidget(self.plot_widget_waveform_a, 100)

        self.x_data = [x * ENERGY_MONITOR_MS_PER_TICK for x in list(range(768))]

        self.button_energy.clicked.connect(self.button_energy_clicked)
        self.button_transformer_settings.clicked.connect(self.button_transformer_settings_clicked)

        self.voltage_connected = True
        self.current_connected = True

        self.running = False
Beispiel #34
0
    def __init__(self, *args):
        super().__init__(BrickletHallEffect, *args)

        self.hf = self.device

        self.cbe_edge_count = CallbackEmulator(self.get_edge_count,
                                               False,
                                               self.cb_edge_count,
                                               self.increase_error_count,
                                               expand_result_tuple_for_callback=True)

        self.current_value = CurveValueWrapper()

        self.label_count = CountLabel('Count')

        plots = [('Value', Qt.red, self.current_value, str)]
        self.plot_widget = PlotWidget('Value', plots, extra_key_widgets=[self.label_count], update_interval=0.05)
        self.plot_widget.set_fixed_y_scale(0, 1, 1, 1)

        self.combo_edge_type = QComboBox()
        self.combo_edge_type.addItem('Rising')
        self.combo_edge_type.addItem('Falling')
        self.combo_edge_type.addItem('Both')
        self.combo_edge_type.currentIndexChanged.connect(self.edge_changed)

        self.spin_debounce = QSpinBox()
        self.spin_debounce.setMinimum(0)
        self.spin_debounce.setMaximum(255)
        self.spin_debounce.setValue(100)
        self.spin_debounce.editingFinished.connect(self.debounce_changed)

        self.button_reset = QPushButton('Reset Count')
        self.button_reset.clicked.connect(self.reset_count)

        hlayout = QHBoxLayout()
        hlayout.addWidget(QLabel('Edge Type:'))
        hlayout.addWidget(self.combo_edge_type)
        hlayout.addStretch()
        hlayout.addWidget(QLabel('Debounce Period [ms]:'))
        hlayout.addWidget(self.spin_debounce)
        hlayout.addStretch()
        hlayout.addWidget(self.button_reset)

        line = QFrame()
        line.setObjectName("line")
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)
Beispiel #35
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletHallEffect, *args)

        self.setupUi(self)

        self.hf = self.device

        self.cbe_edge_count = CallbackEmulator(self.get_edge_count,
                                               self.cb_edge_count,
                                               self.increase_error_count)

        self.current_value = None

        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Value', plot_list)
        self.plot_widget.set_fixed_y_scale(0, 1, 1, 1)

        self.combo_edge_type.currentIndexChanged.connect(self.edge_changed)
        self.spin_debounce.editingFinished.connect(self.debounce_changed)

        self.main_layout.insertWidget(1, self.plot_widget)
Beispiel #36
0
class HallEffect(PluginBase):
    def __init__(self, *args):
        super().__init__(BrickletHallEffect, *args)

        self.hf = self.device

        self.cbe_edge_count = CallbackEmulator(self.get_edge_count,
                                               False,
                                               self.cb_edge_count,
                                               self.increase_error_count,
                                               expand_result_tuple_for_callback=True)

        self.current_value = CurveValueWrapper()

        self.label_count = CountLabel('Count')

        plots = [('Value', Qt.red, self.current_value, str)]
        self.plot_widget = PlotWidget('Value', plots, extra_key_widgets=[self.label_count], update_interval=0.05)
        self.plot_widget.set_fixed_y_scale(0, 1, 1, 1)

        self.combo_edge_type = QComboBox()
        self.combo_edge_type.addItem('Rising')
        self.combo_edge_type.addItem('Falling')
        self.combo_edge_type.addItem('Both')
        self.combo_edge_type.currentIndexChanged.connect(self.edge_changed)

        self.spin_debounce = QSpinBox()
        self.spin_debounce.setMinimum(0)
        self.spin_debounce.setMaximum(255)
        self.spin_debounce.setValue(100)
        self.spin_debounce.editingFinished.connect(self.debounce_changed)

        self.button_reset = QPushButton('Reset Count')
        self.button_reset.clicked.connect(self.reset_count)

        hlayout = QHBoxLayout()
        hlayout.addWidget(QLabel('Edge Type:'))
        hlayout.addWidget(self.combo_edge_type)
        hlayout.addStretch()
        hlayout.addWidget(QLabel('Debounce Period [ms]:'))
        hlayout.addWidget(self.spin_debounce)
        hlayout.addStretch()
        hlayout.addWidget(self.button_reset)

        line = QFrame()
        line.setObjectName("line")
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)

    def debounce_changed(self):
        self.hf.set_edge_count_config(self.combo_edge_type.currentIndex(), self.spin_debounce.value())

    def edge_changed(self, _value):
        self.hf.set_edge_count_config(self.combo_edge_type.currentIndex(), self.spin_debounce.value())

    def get_edge_count(self, reset):
        edge_count = self.hf.get_edge_count(reset)
        value = self.hf.get_value()

        if reset:
            edge_count = 0

        return edge_count, value

    def cb_edge_count(self, edge_count, value):
        if value:
            self.current_value.value = 1
        else:
            self.current_value.value = 0

        self.label_count.setText(edge_count)

    def get_edge_count_config_async(self, edge_type, debounce):
        self.combo_edge_type.setCurrentIndex(edge_type)
        self.spin_debounce.setValue(debounce)

    def reset_count(self):
        async_call(self.get_edge_count, True, self.cb_edge_count, self.increase_error_count,
                   expand_result_tuple_for_callback=True)

    def start(self):
        async_call(self.hf.get_edge_count_config, None, self.get_edge_count_config_async, self.increase_error_count,
                   expand_result_tuple_for_callback=True)

        self.cbe_edge_count.set_period(50)

        self.plot_widget.stop = False

    def stop(self):
        self.cbe_edge_count.set_period(0)

        self.plot_widget.stop = True

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletHallEffect.DEVICE_IDENTIFIER
Beispiel #37
0
class HallEffect(PluginBase, Ui_HallEffect):
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletHallEffect, *args)

        self.setupUi(self)

        self.hf = self.device

        self.cbe_edge_count = CallbackEmulator(self.get_edge_count,
                                               self.cb_edge_count,
                                               self.increase_error_count)

        self.current_value = None

        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Value', plot_list)
        self.plot_widget.set_fixed_y_scale(0, 1, 1, 1)

        self.combo_edge_type.currentIndexChanged.connect(self.edge_changed)
        self.spin_debounce.editingFinished.connect(self.debounce_changed)

        self.main_layout.insertWidget(1, self.plot_widget)

    def debounce_changed(self):
        self.hf.set_edge_count_config(self.combo_edge_type.currentIndex(), self.spin_debounce.value())

    def edge_changed(self, value):
        self.hf.set_edge_count_config(self.combo_edge_type.currentIndex(), self.spin_debounce.value())

    def get_edge_count(self):
        return self.hf.get_edge_count(False), self.hf.get_value()

    def cb_edge_count(self, data):
        count, value = data
        self.label_edge_count.setText(str(count))
        if value:
            self.current_value = 1
        else:
            self.current_value = 0

    def get_current_value(self):
        return self.current_value

    def cb_edge_count_config(self, conf):
        edge_type, debounce = conf
        self.combo_edge_type.setCurrentIndex(edge_type)
        self.spin_debounce.setValue(debounce)

    def get_edge_count_async(self, count):
        self.label_edge_count.setText(str(count))

    def get_value_async(self, value):
        if value:
            self.current_value = 1
        else:
            self.current_value = 0

    def start(self):
        async_call(self.hf.get_edge_count_config, None, self.cb_edge_count_config, self.increase_error_count)
        async_call(self.hf.get_edge_count, False, self.get_edge_count_async, self.increase_error_count)
        async_call(self.hf.get_value, None, self.get_value_async, self.increase_error_count)
        self.cbe_edge_count.set_period(50)

        self.plot_widget.stop = False

    def stop(self):
        self.cbe_edge_count.set_period(0)

        self.plot_widget.stop = True

    def destroy(self):
        pass

    def get_url_part(self):
        return 'hall_effect'

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletHallEffect.DEVICE_IDENTIFIER
Beispiel #38
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickIMU, *args)

        self.setupUi(self)

        self.imu = self.device

        self.acc_x = 0
        self.acc_y = 0
        self.acc_z = 0
        self.mag_x = 0
        self.mag_y = 0
        self.mag_z = 0
        self.gyr_x = 0
        self.gyr_y = 0
        self.gyr_z = 0
        self.tem   = 0
        self.roll  = 0
        self.pitch = 0
        self.yaw   = 0
        self.qua_x = 0
        self.qua_y = 0
        self.qua_z = 0
        self.qua_w = 0

        self.old_time = 0

        self.update_timer = QTimer()
        self.update_timer.timeout.connect(self.update_data)

        self.cbe_all_data = CallbackEmulator(self.imu.get_all_data,
                                             self.all_data_callback,
                                             self.increase_error_count,
                                             use_data_signal=False)
        self.cbe_orientation = CallbackEmulator(self.imu.get_orientation,
                                                self.orientation_callback,
                                                self.increase_error_count,
                                                use_data_signal=False)
        self.cbe_quaternion = CallbackEmulator(self.imu.get_quaternion,
                                               self.quaternion_callback,
                                               self.increase_error_count,
                                               use_data_signal=False)

        # Import IMUGLWidget here, not global. If globally included we get
        # 'No OpenGL_accelerate module loaded: No module named OpenGL_accelerate'
        # as soon as IMU is set as device_class in __init__.
        # No idea why this happens, doesn't make sense.
        try:
            from .imu_gl_widget import IMUGLWidget
        except:
            from imu_gl_widget import IMUGLWidget

        self.imu_gl = IMUGLWidget(self)
        self.imu_gl.setMinimumSize(150, 150)
        self.imu_gl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.min_x = 0
        self.min_y = 0
        self.min_z = 0
        self.max_x = 0
        self.max_y = 0
        self.max_z = 0

        self.update_counter = 0

        self.mag_plot_widget = PlotWidget("Magnetic Field [mG]",
                                          [["X", Qt.red, self.get_mag_x],
                                           ["Y", Qt.darkGreen, self.get_mag_y],
                                           ["Z", Qt.blue, self.get_mag_z]],
                                          self.clear_graphs)
        self.acc_plot_widget = PlotWidget("Acceleration [mG]",
                                          [["X", Qt.red, self.get_acc_x],
                                           ["Y", Qt.darkGreen, self.get_acc_y],
                                           ["Z", Qt.blue, self.get_acc_z]],
                                          self.clear_graphs)
        self.gyr_plot_widget = PlotWidget("Angular Velocity [%c/s]" % 0xB0,
                                          [["X", Qt.red, self.get_gyr_x],
                                           ["Y", Qt.darkGreen, self.get_gyr_y],
                                           ["Z", Qt.blue, self.get_gyr_z]],
                                          self.clear_graphs)
        self.tem_plot_widget = PlotWidget("Temperature [%cC]" % 0xB0,
                                          [["t", Qt.red, self.get_tem]],
                                          self.clear_graphs)

        self.mag_plot_widget.setMinimumSize(250, 200)
        self.acc_plot_widget.setMinimumSize(250, 200)
        self.gyr_plot_widget.setMinimumSize(250, 200)
        self.tem_plot_widget.setMinimumSize(250, 200)

        self.orientation_label = QLabel("""Position your IMU Brick as shown \
in the image above, then press "Save Orientation".""")
        self.orientation_label.setWordWrap(True)
        self.orientation_label.setAlignment(Qt.AlignHCenter)
        self.gl_layout = QVBoxLayout()
        self.gl_layout.addWidget(self.imu_gl)
        self.gl_layout.addWidget(self.orientation_label)

        self.layout_top.addWidget(self.gyr_plot_widget)
        self.layout_top.addWidget(self.acc_plot_widget)
        self.layout_top.addWidget(self.mag_plot_widget)
        self.layout_bottom.addLayout(self.gl_layout)
        self.layout_bottom.addWidget(self.tem_plot_widget)

        self.save_orientation.clicked.connect(self.imu_gl.save_orientation)
        self.calibrate.clicked.connect(self.calibrate_clicked)
        self.led_button.clicked.connect(self.led_clicked)
        self.speed_spinbox.editingFinished.connect(self.speed_finished)

        self.calibrate = None
        self.alive = True

        if self.firmware_version >= (1, 0, 7):
            reset = QAction('Reset', self)
            reset.triggered.connect(lambda: self.imu.reset())
            self.set_actions(reset)
Beispiel #39
0
class EnergyMonitor(COMCUPluginBase, Ui_EnergyMonitor):
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletEnergyMonitor, *args)

        self.setupUi(self)

        self.energy_monitor = self.device
        self.cbe_get_energy_data = CallbackEmulator(self.energy_monitor.get_energy_data,
                                                    None,
                                                    self.cb_energy_data,
                                                    self.increase_error_count)
        self.cbe_get_transformer_status = CallbackEmulator(self.energy_monitor.get_transformer_status,
                                                           None,
                                                           self.cb_transformer_status,
                                                           self.increase_error_count)

        plots_waveform_v = [('Waveform V', Qt.red, None, None)]
        self.plot_widget_waveform_v = PlotWidget('Voltage [V]', plots_waveform_v, clear_button=None, x_diff=768*ENERGY_MONITOR_MS_PER_TICK, x_scale_title_text='Time [ms]', key=None, x_scale_visible=False)

        plots_waveform_a = [('Waveform A', Qt.red, None, None)]
        self.plot_widget_waveform_a = PlotWidget('Current [A]', plots_waveform_a, clear_button=None, x_diff=768*ENERGY_MONITOR_MS_PER_TICK, x_scale_title_text='Time [ms]', key=None)

        self.plot_widget_waveform_v.add_y_scale_sibling(self.plot_widget_waveform_a)
        self.plot_widget_waveform_a.add_y_scale_sibling(self.plot_widget_waveform_v)

        # try to make the actual curve area equal in height by fiddling with the
        # minimum-height and the stretch factors
        self.plot_widget_waveform_v.setMinimumHeight(194)
        self.plot_widget_waveform_a.setMinimumHeight(250)
        self.layout_graph.insertWidget(0, self.plot_widget_waveform_v, 86)
        self.layout_graph.addWidget(self.plot_widget_waveform_a, 100)

        self.x_data = [x * ENERGY_MONITOR_MS_PER_TICK for x in list(range(768))]

        self.button_energy.clicked.connect(self.button_energy_clicked)
        self.button_transformer_settings.clicked.connect(self.button_transformer_settings_clicked)

        self.voltage_connected = True
        self.current_connected = True

        self.running = False

    def button_energy_clicked(self):
        self.energy_monitor.reset_energy()

    def button_transformer_settings_clicked(self):
        voltage_ratio = int(self.spinbox_voltage_ratio.value()*100)
        current_ratio = int(self.spinbox_current_ratio.value()*100)
        self.energy_monitor.set_transformer_calibration(voltage_ratio, current_ratio, 0)

    def cb_waveform_error(self):
        self.increase_error_count()

        if self.running:
            async_call(self.energy_monitor.get_waveform, None, self.cb_waveform, self.cb_waveform_error, delay=0.5)

    def cb_waveform(self, waveform):
        y_data_v = [x*0.1 for x in waveform[::2]]
        y_data_a = [x*0.01 for x in waveform[1::2]]
        self.plot_widget_waveform_v.set_data(0, self.x_data, y_data_v)
        self.plot_widget_waveform_a.set_data(0, self.x_data, y_data_a)

        if self.running:
            async_call(self.energy_monitor.get_waveform, None, self.cb_waveform, self.cb_waveform_error, delay=0.5)

    def cb_energy_data(self, data):
        if self.voltage_connected:
            self.label_voltage.setText('{0:.2f}'.format(data.voltage / 100))
        else:
            self.label_voltage.setText('NC')
        if self.current_connected:
            self.label_current.setText('{0:.2f}'.format(data.current / 100))
        else:
            self.label_current.setText('NC')

        self.label_energy.setText('{0:.2f}'.format(data.energy / 100))
        self.label_real_power.setText('{0:.2f}'.format(data.real_power / 100))
        self.label_apparent_power.setText('{0:.2f}'.format(data.apparent_power / 100))
        self.label_reactive_power.setText('{0:.2f}'.format(data.reactive_power / 100))
        self.label_power_factor.setText('{0:.2f}'.format((data.power_factor // 10) / 100))
        self.label_frequency.setText('{0:.2f}'.format(data.frequency / 100))

    def cb_transformer_status(self, status):
        self.voltage_connected = status.voltage_transformer_connected
        self.current_connected = status.current_transformer_connected

        if not self.voltage_connected:
            self.label_voltage.setText('NC')

        if not self.current_connected:
            self.label_current.setText('NC')

    def cb_transformer_calibration(self, cal):
        self.spinbox_voltage_ratio.setValue(cal.voltage_ratio/100.0)
        self.spinbox_current_ratio.setValue(cal.current_ratio/100.0)

    def start(self):
        self.running = True

        async_call(self.energy_monitor.get_transformer_calibration, None, self.cb_transformer_calibration, self.increase_error_count)
        async_call(self.energy_monitor.get_waveform, None, self.cb_waveform, self.cb_waveform_error)

        self.cbe_get_energy_data.set_period(200)
        self.cbe_get_transformer_status.set_period(200)

    def stop(self):
        self.running = False
        self.cbe_get_energy_data.set_period(0)
        self.cbe_get_transformer_status.set_period(0)

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletEnergyMonitor.DEVICE_IDENTIFIER
Beispiel #40
0
class ColorV2(COMCUPluginBase):
    def __init__(self, *args):
        super().__init__(BrickletColorV2, *args)

        self.color = self.device

        self.cbe_color = CallbackEmulator(self.color.get_color,
                                          None,
                                          self.cb_color,
                                          self.increase_error_count,
                                          expand_result_tuple_for_callback=True)
        self.cbe_illuminance = CallbackEmulator(self.color.get_illuminance,
                                                None,
                                                self.cb_illuminance,
                                                self.increase_error_count)
        self.cbe_color_temperature = CallbackEmulator(self.color.get_color_temperature,
                                                      None,
                                                      self.cb_color_temperature,
                                                      self.increase_error_count)

        self.color_frame = ColorFrame()
        self.illuminance_frame = ColorFrame()
        self.color_temperature_frame = ColorFrame()

        self.current_color_r = CurveValueWrapper() # int
        self.current_color_g = CurveValueWrapper() # int
        self.current_color_b = CurveValueWrapper() # int
        self.current_color_c = CurveValueWrapper() # int
        self.current_illuminance = CurveValueWrapper() # float, lx
        self.current_color_temperature = CurveValueWrapper() # int, K

        self.clear_graphs_button = QPushButton("Clear Graphs")

        plots = [('R', Qt.red, self.current_color_r, lambda value: self.format_color(0, value)),
                 ('G', Qt.darkGreen, self.current_color_g, lambda value: self.format_color(1, value)),
                 ('B', Qt.blue, self.current_color_b, lambda value: self.format_color(2, value)),
                 ('C', Qt.black, self.current_color_c, str)]
        self.plot_widget = PlotWidget('Color', plots, clear_button=self.clear_graphs_button,
                                      extra_key_widgets=[self.color_frame], y_resolution=1.0)
        self.plot_widget.setMinimumSize(250, 200)

        plots_illuminance = [('Illuminance', Qt.red, self.current_illuminance, '{} lx (Lux)'.format)]
        self.plot_widget_illuminance = PlotWidget('Illuminance [lx]', plots_illuminance,
                                                  clear_button=self.clear_graphs_button,
                                                  extra_key_widgets=[self.illuminance_frame],
                                                  y_resolution=0.1)
        self.plot_widget_illuminance.setMinimumSize(250, 200)

        plots_color_temperature = [('Color Temperature', Qt.red, self.current_color_temperature, '{} K'.format)]
        self.plot_widget_color_temperature = PlotWidget('Color Temperature [K]', plots_color_temperature,
                                                        clear_button=self.clear_graphs_button,
                                                        extra_key_widgets=[self.color_temperature_frame],
                                                        y_resolution=1.0)
        self.plot_widget_color_temperature.setMinimumSize(250, 200)

        self.gain_label = QLabel('Gain:')
        self.gain_combo = QComboBox()
        self.gain_combo.addItem("1x")
        self.gain_combo.addItem("4x")
        self.gain_combo.addItem("16x")
        self.gain_combo.addItem("60x")

        self.gain_combo.currentIndexChanged.connect(self.gain_changed)

        self.current_gain_factor = 60

        self.conversion_label = QLabel('Integration Time:')
        self.conversion_combo = QComboBox()
        self.conversion_combo.addItem("2.4 ms")
        self.conversion_combo.addItem("24 ms")
        self.conversion_combo.addItem("101 ms")
        self.conversion_combo.addItem("154 ms")
        self.conversion_combo.addItem("700 ms")

        self.current_conversion_time = 154

        self.conversion_combo.currentIndexChanged.connect(self.conversion_changed)

        self.light_checkbox = QCheckBox("Enable Light")

        self.light_checkbox.stateChanged.connect(self.light_state_changed)

        layout_h1 = QHBoxLayout()
        layout_h1.addWidget(self.plot_widget_illuminance)
        layout_h1.addWidget(self.plot_widget_color_temperature)

        layout_h2 = QHBoxLayout()
        layout_h2.addWidget(self.gain_label)
        layout_h2.addWidget(self.gain_combo)
        layout_h2.addWidget(self.conversion_label)
        layout_h2.addWidget(self.conversion_combo)
        layout_h2.addWidget(self.light_checkbox)
        layout_h2.addStretch()
        layout_h2.addWidget(self.clear_graphs_button)

        line1 = QFrame()
        line1.setObjectName("line1")
        line1.setFrameShape(QFrame.HLine)
        line1.setFrameShadow(QFrame.Sunken)

        line2 = QFrame()
        line2.setObjectName("line2")
        line2.setFrameShape(QFrame.HLine)
        line2.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line1)
        layout.addLayout(layout_h1)
        layout.addWidget(line2)
        layout.addLayout(layout_h2)

        self.k_to_rgb = {1000:(255, 56, 0), 1100:(255, 71, 0), 1200:(255, 83, 0), 1300:(255, 93, 0), 1400:(255, 101, 0), 1500:(255, 109, 0), 1600:(255, 115, 0), 1700:(255, 121, 0), 1800:(255, 126, 0), 1900:(255, 131, 0), 2000:(255, 137, 18), 2100:(255, 142, 33), 2200:(255, 147, 44), 2300:(255, 152, 54), 2400:(255, 157, 63), 2500:(255, 161, 72), 2600:(255, 165, 79), 2700:(255, 169, 87), 2800:(255, 173, 94), 2900:(255, 177, 101), 3000:(255, 180, 107), 3100:(255, 184, 114), 3200:(255, 187, 120), 3300:(255, 190, 126), 3400:(255, 193, 132), 3500:(255, 196, 137), 3600:(255, 199, 143), 3700:(255, 201, 148), 3800:(255, 204, 153), 3900:(255, 206, 159), 4000:(255, 209, 163), 4100:(255, 211, 168), 4200:(255, 213, 173), 4300:(255, 215, 177), 4400:(255, 217, 182), 4500:(255, 219, 186), 4600:(255, 221, 190), 4700:(255, 223, 194), 4800:(255, 225, 198), 4900:(255, 227, 202), 5000:(255, 228, 206), 5100:(255, 230, 210), 5200:(255, 232, 213), 5300:(255, 233, 217), 5400:(255, 235, 220), 5500:(255, 236, 224), 5600:(255, 238, 227), 5700:(255, 239, 230), 5800:(255, 240, 233), 5900:(255, 242, 236), 6000:(255, 243, 239), 6100:(255, 244, 242), 6200:(255, 245, 245), 6300:(255, 246, 248), 6400:(255, 248, 251), 6500:(255, 249, 253), 6600:(254, 249, 255), 6700:(252, 247, 255), 6800:(249, 246, 255), 6900:(247, 245, 255), 7000:(245, 243, 255), 7100:(243, 242, 255), 7200:(240, 241, 255), 7300:(239, 240, 255), 7400:(237, 239, 255), 7500:(235, 238, 255), 7600:(233, 237, 255), 7700:(231, 236, 255), 7800:(230, 235, 255), 7900:(228, 234, 255), 8000:(227, 233, 255), 8100:(225, 232, 255), 8200:(224, 231, 255), 8300:(222, 230, 255), 8400:(221, 230, 255), 8500:(220, 229, 255), 8600:(218, 228, 255), 8700:(217, 227, 255), 8800:(216, 227, 255), 8900:(215, 226, 255), 9000:(214, 225, 255), 9100:(212, 225, 255), 9200:(211, 224, 255), 9300:(210, 223, 255), 9400:(209, 223, 255), 9500:(208, 222, 255), 9600:(207, 221, 255), 9700:(207, 221, 255), 9800:(206, 220, 255), 9900:(205, 220, 255), 10000:(204, 219, 255), 10100:(203, 219, 255), 10200:(202, 218, 255), 10300:(201, 218, 255), 10400:(201, 217, 255), 10500:(200, 217, 255), 10600:(199, 216, 255), 10700:(199, 216, 255), 10800:(198, 216, 255), 10900:(197, 215, 255), 11000:(196, 215, 255), 11100:(196, 214, 255), 11200:(195, 214, 255), 11300:(195, 214, 255), 11400:(194, 213, 255), 11500:(193, 213, 255), 11600:(193, 212, 255), 11700:(192, 212, 255), 11800:(192, 212, 255), 11900:(191, 211, 255), 12000:(191, 211, 255), 12100:(190, 211, 255), 12200:(190, 210, 255), 12300:(189, 210, 255), 12400:(189, 210, 255), 12500:(188, 210, 255), 12600:(188, 209, 255), 12700:(187, 209, 255), 12800:(187, 209, 255), 12900:(186, 208, 255), 13000:(186, 208, 255), 13100:(185, 208, 255), 13200:(185, 208, 255), 13300:(185, 207, 255), 13400:(184, 207, 255), 13500:(184, 207, 255), 13600:(183, 207, 255), 13700:(183, 206, 255), 13800:(183, 206, 255), 13900:(182, 206, 255), 14000:(182, 206, 255), 14100:(182, 205, 255), 14200:(181, 205, 255), 14300:(181, 205, 255), 14400:(181, 205, 255), 14500:(180, 205, 255), 14600:(180, 204, 255), 14700:(180, 204, 255), 14800:(179, 204, 255), 14900:(179, 204, 255), 15000:(179, 204, 255), 15100:(178, 203, 255), 15200:(178, 203, 255), 15300:(178, 203, 255), 15400:(178, 203, 255), 15500:(177, 203, 255), 15600:(177, 202, 255), 15700:(177, 202, 255), 15800:(177, 202, 255), 15900:(176, 202, 255), 16000:(176, 202, 255), 16100:(176, 202, 255), 16200:(175, 201, 255), 16300:(175, 201, 255), 16400:(175, 201, 255), 16500:(175, 201, 255), 16600:(175, 201, 255), 16700:(174, 201, 255), 16800:(174, 201, 255), 16900:(174, 200, 255), 17000:(174, 200, 255), 17100:(173, 200, 255), 17200:(173, 200, 255), 17300:(173, 200, 255), 17400:(173, 200, 255), 17500:(173, 200, 255), 17600:(172, 199, 255), 17700:(172, 199, 255), 17800:(172, 199, 255), 17900:(172, 199, 255), 18000:(172, 199, 255), 18100:(171, 199, 255), 18200:(171, 199, 255), 18300:(171, 199, 255), 18400:(171, 198, 255), 18500:(171, 198, 255), 18600:(170, 198, 255), 18700:(170, 198, 255), 18800:(170, 198, 255), 18900:(170, 198, 255), 19000:(170, 198, 255), 19100:(170, 198, 255), 19200:(169, 198, 255), 19300:(169, 197, 255), 19400:(169, 197, 255), 19500:(169, 197, 255), 19600:(169, 197, 255), 19700:(169, 197, 255), 19800:(169, 197, 255), 19900:(168, 197, 255), 20000:(168, 197, 255), 20100:(168, 197, 255), 20200:(168, 197, 255), 20300:(168, 196, 255), 20400:(168, 196, 255), 20500:(168, 196, 255), 20600:(167, 196, 255), 20700:(167, 196, 255), 20800:(167, 196, 255), 20900:(167, 196, 255), 21000:(167, 196, 255), 21100:(167, 196, 255), 21200:(167, 196, 255), 21300:(166, 196, 255), 21400:(166, 195, 255), 21500:(166, 195, 255), 21600:(166, 195, 255), 21700:(166, 195, 255), 21800:(166, 195, 255), 21900:(166, 195, 255), 22000:(166, 195, 255), 22100:(165, 195, 255), 22200:(165, 195, 255), 22300:(165, 195, 255), 22400:(165, 195, 255), 22500:(165, 195, 255), 22600:(165, 195, 255), 22700:(165, 194, 255), 22800:(165, 194, 255), 22900:(165, 194, 255), 23000:(164, 194, 255), 23100:(164, 194, 255), 23200:(164, 194, 255), 23300:(164, 194, 255), 23400:(164, 194, 255), 23500:(164, 194, 255), 23600:(164, 194, 255), 23700:(164, 194, 255), 23800:(164, 194, 255), 23900:(164, 194, 255), 24000:(163, 194, 255), 24100:(163, 194, 255), 24200:(163, 193, 255), 24300:(163, 193, 255), 24400:(163, 193, 255), 24500:(163, 193, 255), 24600:(163, 193, 255), 24700:(163, 193, 255), 24800:(163, 193, 255), 24900:(163, 193, 255), 25000:(163, 193, 255), 25100:(162, 193, 255), 25200:(162, 193, 255), 25300:(162, 193, 255), 25400:(162, 193, 255), 25500:(162, 193, 255), 25600:(162, 193, 255), 25700:(162, 193, 255), 25800:(162, 193, 255), 25900:(162, 192, 255), 26000:(162, 192, 255), 26100:(162, 192, 255), 26200:(162, 192, 255), 26300:(162, 192, 255), 26400:(161, 192, 255), 26500:(161, 192, 255), 26600:(161, 192, 255), 26700:(161, 192, 255), 26800:(161, 192, 255), 26900:(161, 192, 255), 27000:(161, 192, 255), 27100:(161, 192, 255), 27200:(161, 192, 255), 27300:(161, 192, 255), 27400:(161, 192, 255), 27500:(161, 192, 255), 27600:(161, 192, 255), 27700:(161, 192, 255), 27800:(160, 192, 255), 27900:(160, 192, 255), 28000:(160, 191, 255), 28100:(160, 191, 255), 28200:(160, 191, 255), 28300:(160, 191, 255), 28400:(160, 191, 255), 28500:(160, 191, 255), 28600:(160, 191, 255), 28700:(160, 191, 255), 28800:(160, 191, 255), 28900:(160, 191, 255), 29000:(160, 191, 255), 29100:(160, 191, 255), 29200:(160, 191, 255), 29300:(159, 191, 255), 29400:(159, 191, 255), 29500:(159, 191, 255), 29600:(159, 191, 255), 29700:(159, 191, 255), 29800:(159, 191, 255), 29900:(159, 191, 255), 30000:(159, 191, 255), 30100:(159, 191, 255), 30200:(159, 191, 255), 30300:(159, 191, 255), 30400:(159, 190, 255), 30500:(159, 190, 255), 30600:(159, 190, 255), 30700:(159, 190, 255), 30800:(159, 190, 255), 30900:(159, 190, 255), 31000:(159, 190, 255), 31100:(158, 190, 255), 31200:(158, 190, 255), 31300:(158, 190, 255), 31400:(158, 190, 255), 31500:(158, 190, 255), 31600:(158, 190, 255), 31700:(158, 190, 255), 31800:(158, 190, 255), 31900:(158, 190, 255), 32000:(158, 190, 255), 32100:(158, 190, 255), 32200:(158, 190, 255), 32300:(158, 190, 255), 32400:(158, 190, 255), 32500:(158, 190, 255), 32600:(158, 190, 255), 32700:(158, 190, 255), 32800:(158, 190, 255), 32900:(158, 190, 255), 33000:(158, 190, 255), 33100:(158, 190, 255), 33200:(157, 190, 255), 33300:(157, 190, 255), 33400:(157, 189, 255), 33500:(157, 189, 255), 33600:(157, 189, 255), 33700:(157, 189, 255), 33800:(157, 189, 255), 33900:(157, 189, 255), 34000:(157, 189, 255), 34100:(157, 189, 255), 34200:(157, 189, 255), 34300:(157, 189, 255), 34400:(157, 189, 255), 34500:(157, 189, 255), 34600:(157, 189, 255), 34700:(157, 189, 255), 34800:(157, 189, 255), 34900:(157, 189, 255), 35000:(157, 189, 255), 35100:(157, 189, 255), 35200:(157, 189, 255), 35300:(157, 189, 255), 35400:(157, 189, 255), 35500:(157, 189, 255), 35600:(156, 189, 255), 35700:(156, 189, 255), 35800:(156, 189, 255), 35900:(156, 189, 255), 36000:(156, 189, 255), 36100:(156, 189, 255), 36200:(156, 189, 255), 36300:(156, 189, 255), 36400:(156, 189, 255), 36500:(156, 189, 255), 36600:(156, 189, 255), 36700:(156, 189, 255), 36800:(156, 189, 255), 36900:(156, 189, 255), 37000:(156, 189, 255), 37100:(156, 189, 255), 37200:(156, 188, 255), 37300:(156, 188, 255), 37400:(156, 188, 255), 37500:(156, 188, 255), 37600:(156, 188, 255), 37700:(156, 188, 255), 37800:(156, 188, 255), 37900:(156, 188, 255), 38000:(156, 188, 255), 38100:(156, 188, 255), 38200:(156, 188, 255), 38300:(156, 188, 255), 38400:(155, 188, 255), 38500:(155, 188, 255), 38600:(155, 188, 255), 38700:(155, 188, 255), 38800:(155, 188, 255), 38900:(155, 188, 255), 39000:(155, 188, 255), 39100:(155, 188, 255), 39200:(155, 188, 255), 39300:(155, 188, 255), 39400:(155, 188, 255), 39500:(155, 188, 255), 39600:(155, 188, 255), 39700:(155, 188, 255), 39800:(155, 188, 255), 39900:(155, 188, 255), 40000:(155, 188, 255)}

    def start(self):
        async_call(self.color.get_config, None, self.get_config_async, self.increase_error_count)
        async_call(self.color.get_light, None, self.get_light_async, self.increase_error_count)

        self.cbe_color.set_period(50)
        self.cbe_illuminance.set_period(100)
        self.cbe_color_temperature.set_period(100)

        self.plot_widget.stop = False
        self.plot_widget_illuminance.stop = False
        self.plot_widget_color_temperature.stop = False

    def stop(self):
        self.cbe_color.set_period(0)
        self.cbe_illuminance.set_period(0)
        self.cbe_color_temperature.set_period(0)

        self.plot_widget.stop = True
        self.plot_widget_illuminance.stop = True
        self.plot_widget_color_temperature.stop = True

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletColorV2.DEVICE_IDENTIFIER

    def format_color(self, i, value):
        if value >= 65535:
            self.plot_widget.get_key_item(i).setStyleSheet('QToolButton { color: red }')
        else:
            self.plot_widget.get_key_item(i).setStyleSheet('')

        return str(value)

    def cb_color(self, r, g, b, c):
        self.current_color_r.value = r
        self.current_color_g.value = g
        self.current_color_b.value = b
        self.current_color_c.value = c

        if r >= 65535 or g >= 65535 or b >= 65535:
            self.plot_widget_illuminance.get_key_item(0).setStyleSheet('QLabel { color: red }')
            self.plot_widget_color_temperature.get_key_item(0).setStyleSheet('QLabel { color: red }')
        else:
            self.plot_widget_illuminance.get_key_item(0).setStyleSheet('')
            self.plot_widget_color_temperature.get_key_item(0).setStyleSheet('')

        normalize = 0xFFFF
        self.color_frame.set_color(r * 255 // normalize, g * 255 // normalize, b * 255 // normalize)

    def cb_illuminance(self, illuminance):
        self.current_illuminance.value = round(illuminance * 700.0 / self.current_gain_factor / self.current_conversion_time, 1)

        i = int(self.current_illuminance.value) * 255 // 20000

        if i > 255:
            i = 255

        self.illuminance_frame.set_color(i, i, i)

    def cb_color_temperature(self, color_temperature):
        self.current_color_temperature.value = color_temperature

        m = color_temperature % 100
        color_temperature -= m

        if m > 50:
            color_temperature += 100

        if color_temperature < 1000:
            color_temperature = 1000

        if color_temperature > 40000:
            color_temperature = 40000

        r, g, b = self.k_to_rgb[color_temperature]

        self.color_temperature_frame.set_color(r, g, b)

    def get_light_async(self, enable):
        self.light_checkbox.setChecked(enable)

    def light_state_changed(self, state):
        self.color.set_light(state == Qt.Checked)

    def get_config_async(self, config):
        gain, gain_factor, conv, conv_time = self.gain_conv_to_combo(config.gain, config.integration_time)

        self.gain_combo.setCurrentIndex(gain)
        self.conversion_combo.setCurrentIndex(conv)

        self.current_gain_factor = gain_factor
        self.current_conversion_time = conv_time

    def gain_conv_to_combo(self, gain, conv):
        if gain == BrickletColorV2.GAIN_1X:
            gain = 0
            gain_factor = 1
        elif gain == BrickletColorV2.GAIN_4X:
            gain = 1
            gain_factor = 4
        elif gain == BrickletColorV2.GAIN_16X:
            gain = 2
            gain_factor = 16
        elif gain == BrickletColorV2.GAIN_60X:
            gain = 3
            gain_factor = 60

        if conv == BrickletColorV2.INTEGRATION_TIME_2MS:
            conv = 0
            conv_time = 2.4
        elif conv == BrickletColorV2.INTEGRATION_TIME_24MS:
            conv = 1
            conv_time = 24
        elif conv == BrickletColorV2.INTEGRATION_TIME_101MS:
            conv = 2
            conv_time = 101
        elif conv == BrickletColorV2.INTEGRATION_TIME_154MS:
            conv = 3
            conv_time = 154
        elif conv == BrickletColorV2.INTEGRATION_TIME_700MS:
            conv = 4
            conv_time = 700

        return gain, gain_factor, conv, conv_time

    def combo_to_gain_conv(self, gain, conv):
        if gain == 0:
            gain = BrickletColorV2.GAIN_1X
            gain_factor = 1
        elif gain == 1:
            gain = BrickletColorV2.GAIN_4X
            gain_factor = 4
        elif gain == 2:
            gain = BrickletColorV2.GAIN_16X
            gain_factor = 16
        elif gain == 3:
            gain = BrickletColorV2.GAIN_60X
            gain_factor = 60

        if conv == 0:
            conv = BrickletColorV2.INTEGRATION_TIME_2MS
            conv_time = 2.4
        elif conv == 1:
            conv = BrickletColorV2.INTEGRATION_TIME_24MS
            conv_time = 24
        elif conv == 2:
            conv = BrickletColorV2.INTEGRATION_TIME_101MS
            conv_time = 101
        elif conv == 3:
            conv = BrickletColorV2.INTEGRATION_TIME_154MS
            conv_time = 154
        elif conv == 4:
            conv = BrickletColorV2.INTEGRATION_TIME_700MS
            conv_time = 700

        return gain, gain_factor, conv, conv_time

    def gain_changed(self, gain):
        conversion = self.conversion_combo.currentIndex()

        g, gf, c, ct = self.combo_to_gain_conv(gain, conversion)

        self.current_gain_factor = gf
        self.current_conversion_time = ct

        self.color.set_config(g, c)

    def conversion_changed(self, conversion):
        gain = self.gain_combo.currentIndex()

        g, gf, c, ct = self.combo_to_gain_conv(gain, conversion)

        self.current_gain_factor = gf
        self.current_conversion_time = ct

        self.color.set_config(g, c)
Beispiel #41
0
class AmbientLightV2(PluginBase):
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletAmbientLightV2, *args)

        self.al = self.device

        self.has_clamped_output = self.firmware_version >= (2, 0, 2)

        self.cbe_illuminance = CallbackEmulator(self.al.get_illuminance, self.cb_illuminance, self.increase_error_count)

        self.alf = AmbientLightFrame()
        self.out_of_range_label = QLabel("Illuminance is out-of-range")
        self.saturated_label = QLabel("Sensor is saturated")

        self.out_of_range_label.hide()
        self.out_of_range_label.setStyleSheet("QLabel { color: red }")
        self.saturated_label.hide()
        self.saturated_label.setStyleSheet("QLabel { color: magenta }")

        self.current_illuminance = None  # float, lx

        plots = [("Illuminance", Qt.red, lambda: self.current_illuminance, "{:.2f} lx (Lux)".format)]
        self.plot_widget = PlotWidget(
            "Illuminance [lx]", plots, extra_key_widgets=[self.out_of_range_label, self.saturated_label, self.alf]
        )

        self.range_label = QLabel("Illuminance Range: ")
        self.range_combo = QComboBox()
        if self.has_clamped_output:  # Also means that the unlimited range is available
            self.range_combo.addItem("Unlimited", BrickletAmbientLightV2.ILLUMINANCE_RANGE_UNLIMITED)
        self.range_combo.addItem("0 - 64000 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_64000LUX)
        self.range_combo.addItem("0 - 32000 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_32000LUX)
        self.range_combo.addItem("0 - 16000 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_16000LUX)
        self.range_combo.addItem("0 - 8000 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_8000LUX)
        self.range_combo.addItem("0 - 1300 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_1300LUX)
        self.range_combo.addItem("0 - 600 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_600LUX)
        self.range_combo.currentIndexChanged.connect(self.new_config)

        self.time_label = QLabel("Integration Time: ")
        self.time_combo = QComboBox()
        self.time_combo.addItem("50 ms", BrickletAmbientLightV2.INTEGRATION_TIME_50MS)
        self.time_combo.addItem("100 ms", BrickletAmbientLightV2.INTEGRATION_TIME_100MS)
        self.time_combo.addItem("150 ms", BrickletAmbientLightV2.INTEGRATION_TIME_150MS)
        self.time_combo.addItem("200 ms", BrickletAmbientLightV2.INTEGRATION_TIME_200MS)
        self.time_combo.addItem("250 ms", BrickletAmbientLightV2.INTEGRATION_TIME_250MS)
        self.time_combo.addItem("300 ms", BrickletAmbientLightV2.INTEGRATION_TIME_300MS)
        self.time_combo.addItem("350 ms", BrickletAmbientLightV2.INTEGRATION_TIME_350MS)
        self.time_combo.addItem("400 ms", BrickletAmbientLightV2.INTEGRATION_TIME_400MS)
        self.time_combo.currentIndexChanged.connect(self.new_config)

        hlayout = QHBoxLayout()
        hlayout.addWidget(self.range_label)
        hlayout.addWidget(self.range_combo)
        hlayout.addStretch()
        hlayout.addWidget(self.time_label)
        hlayout.addWidget(self.time_combo)

        line = QFrame()
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)

    def start(self):
        async_call(self.al.get_configuration, None, self.get_configucation_async, self.increase_error_count)
        async_call(self.al.get_illuminance, None, self.cb_illuminance, self.increase_error_count)
        self.cbe_illuminance.set_period(100)

        self.plot_widget.stop = False

    def stop(self):
        self.cbe_illuminance.set_period(0)

        self.plot_widget.stop = True

    def destroy(self):
        pass

    def get_url_part(self):
        return "ambient_light_v2"

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletAmbientLightV2.DEVICE_IDENTIFIER

    def get_configucation_async(self, conf):
        self.range_combo.setCurrentIndex(self.range_combo.findData(conf.illuminance_range))
        self.time_combo.setCurrentIndex(self.time_combo.findData(conf.integration_time))

    def new_config(self, value):
        try:
            self.al.set_configuration(
                self.range_combo.itemData(self.range_combo.currentIndex()),
                self.time_combo.itemData(self.time_combo.currentIndex()),
            )
        except:
            pass

    def cb_illuminance(self, illuminance):
        self.current_illuminance = illuminance / 100.0

        max_illuminance = 12000000  # Approximation for unlimited range
        current_range = self.range_combo.itemData(self.range_combo.currentIndex())
        if current_range == BrickletAmbientLightV2.ILLUMINANCE_RANGE_64000LUX:
            max_illuminance = 6400001
        elif current_range == BrickletAmbientLightV2.ILLUMINANCE_RANGE_32000LUX:
            max_illuminance = 3200001
        elif current_range == BrickletAmbientLightV2.ILLUMINANCE_RANGE_16000LUX:
            max_illuminance = 1600001
        elif current_range == BrickletAmbientLightV2.ILLUMINANCE_RANGE_8000LUX:
            max_illuminance = 800001
        elif current_range == BrickletAmbientLightV2.ILLUMINANCE_RANGE_1300LUX:
            max_illuminance = 130001
        elif current_range == BrickletAmbientLightV2.ILLUMINANCE_RANGE_600LUX:
            max_illuminance = 60001

        if self.has_clamped_output:  # Also means that the unlimited range is available
            if illuminance == 0:
                self.plot_widget.get_key_item(0).setStyleSheet("QLabel { color: magenta }")
                self.out_of_range_label.hide()
                self.saturated_label.show()
            elif illuminance >= max_illuminance:
                self.plot_widget.get_key_item(0).setStyleSheet("QLabel { color: red }")
                self.out_of_range_label.show()
                self.saturated_label.hide()
            else:
                self.plot_widget.get_key_item(0).setStyleSheet("")
                self.out_of_range_label.hide()
                self.saturated_label.hide()

        value = min(max(illuminance * 255 / max_illuminance, 0), 255)
        self.alf.set_color(value, value, value)
Beispiel #42
0
class IMU(PluginBase, Ui_IMU):
    def __init__(self, *args):
        PluginBase.__init__(self, BrickIMU, *args)

        self.setupUi(self)

        self.imu = self.device

        # the firmware version of a Brick can (under common circumstances) not
        # change during the lifetime of a Brick plugin. therefore, it's okay to
        # make final decisions based on it here
        self.has_status_led = self.firmware_version >= (2, 3, 1)

        self.acc_x = CurveValueWrapper()
        self.acc_y = CurveValueWrapper()
        self.acc_z = CurveValueWrapper()
        self.mag_x = CurveValueWrapper()
        self.mag_y = CurveValueWrapper()
        self.mag_z = CurveValueWrapper()
        self.gyr_x = CurveValueWrapper()
        self.gyr_y = CurveValueWrapper()
        self.gyr_z = CurveValueWrapper()
        self.temp  = CurveValueWrapper()
        self.roll  = None
        self.pitch = None
        self.yaw   = None
        self.qua_x = None
        self.qua_y = None
        self.qua_z = None
        self.qua_w = None

        self.all_data_valid = False
        self.quaternion_valid = False
        self.orientation_valid = False

        self.update_timer = QTimer(self)
        self.update_timer.timeout.connect(self.update_data)

        self.cbe_all_data = CallbackEmulator(self.imu.get_all_data,
                                             None,
                                             self.cb_all_data,
                                             self.increase_error_count,
                                             expand_result_tuple_for_callback=True,
                                             use_result_signal=False)
        self.cbe_orientation = CallbackEmulator(self.imu.get_orientation,
                                                None,
                                                self.cb_orientation,
                                                self.increase_error_count,
                                                expand_result_tuple_for_callback=True,
                                                use_result_signal=False)
        self.cbe_quaternion = CallbackEmulator(self.imu.get_quaternion,
                                               None,
                                               self.cb_quaternion,
                                               self.increase_error_count,
                                               expand_result_tuple_for_callback=True,
                                               use_result_signal=False)

        self.imu_gl = IMU3DWidget(self)
        self.imu_gl.setMinimumSize(150, 150)
        self.imu_gl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.update_counter = 0

        self.mag_plot_widget = PlotWidget("Magnetic Field [mG]",
                                          [("X", Qt.red, self.mag_x, str),
                                           ("Y", Qt.darkGreen, self.mag_y, str),
                                           ("Z", Qt.blue, self.mag_z, str)],
                                          clear_button=self.clear_graphs,
                                          key='right-no-icon', y_resolution=5)
        self.acc_plot_widget = PlotWidget("Acceleration [mg]",
                                          [("X", Qt.red, self.acc_x, str),
                                           ("Y", Qt.darkGreen, self.acc_y, str),
                                           ("Z", Qt.blue, self.acc_z, str)],
                                          clear_button=self.clear_graphs,
                                          key='right-no-icon', y_resolution=5)
        self.gyr_plot_widget = PlotWidget("Angular Velocity [°/s]",
                                          [("X", Qt.red, self.gyr_x, str),
                                           ("Y", Qt.darkGreen, self.gyr_y, str),
                                           ("Z", Qt.blue, self.gyr_z, str)],
                                          clear_button=self.clear_graphs,
                                          key='right-no-icon', y_resolution=0.05)
        self.temp_plot_widget = PlotWidget("Temperature [°C]",
                                           [("t", Qt.red, self.temp, str)],
                                           clear_button=self.clear_graphs,
                                           key=None, y_resolution=0.01)

        self.mag_plot_widget.setMinimumSize(250, 250)
        self.acc_plot_widget.setMinimumSize(250, 250)
        self.gyr_plot_widget.setMinimumSize(250, 250)
        self.temp_plot_widget.setMinimumSize(250, 250)

        self.orientation_label = QLabel('Position your IMU Brick as shown in the image above, then press "Save Orientation".')
        self.orientation_label.setWordWrap(True)
        self.orientation_label.setAlignment(Qt.AlignHCenter)
        self.gl_layout = QVBoxLayout()
        self.gl_layout.addWidget(self.imu_gl)
        self.gl_layout.addWidget(self.orientation_label)

        self.layout_top.addWidget(self.gyr_plot_widget)
        self.layout_top.addWidget(self.acc_plot_widget)
        self.layout_top.addWidget(self.mag_plot_widget)
        self.layout_bottom.addLayout(self.gl_layout)
        self.layout_bottom.addWidget(self.temp_plot_widget)

        self.save_orientation.clicked.connect(self.save_orientation_clicked)
        self.calibrate.clicked.connect(self.calibrate_clicked)
        self.led_button.clicked.connect(self.led_clicked)
        self.speed_spinbox.editingFinished.connect(self.speed_finished)

        width = QFontMetrics(self.gyr_x_label.font()).boundingRect('-XXXX.X').width()

        self.gyr_x_label.setMinimumWidth(width)
        self.gyr_y_label.setMinimumWidth(width)
        self.gyr_z_label.setMinimumWidth(width)

        self.calibrate = None
        self.alive = True

        if self.has_status_led:
            self.status_led_action = QAction('Status LED', self)
            self.status_led_action.setCheckable(True)
            self.status_led_action.toggled.connect(lambda checked: self.imu.enable_status_led() if checked else self.imu.disable_status_led())
            self.set_configs([(0, None, [self.status_led_action])])
        else:
            self.status_led_action = None

        reset = QAction('Reset', self)
        reset.triggered.connect(self.imu.reset)
        self.set_actions([(0, None, [reset])])

    def save_orientation_clicked(self):
        self.imu_gl.save_orientation()
        self.orientation_label.hide()

    def cleanup_gl(self):
        self.state = self.imu_gl.get_state()
        self.imu_gl.hide()
        self.imu_gl.cleanup()

    def restart_gl(self):
        self.imu_gl = IMU3DWidget()

        self.imu_gl.setMinimumSize(150, 150)
        self.imu_gl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.gl_layout.addWidget(self.imu_gl)
        self.imu_gl.show()

        self.save_orientation.clicked.connect(self.save_orientation_clicked)
        self.imu_gl.set_state(self.state)

    def start(self):
        if not self.alive:
            return

        if self.has_status_led:
            async_call(self.imu.is_status_led_enabled, None, self.status_led_action.setChecked, self.increase_error_count)

        self.parent().add_callback_on_untab(lambda x: self.cleanup_gl(), 'imu_cleanup_on_untab')
        self.parent().add_callback_post_untab(lambda x: self.restart_gl(), 'imu_restart_post_untab')
        self.parent().add_callback_on_tab(lambda x: self.cleanup_gl(), 'imu_cleanup_on_tab')
        self.parent().add_callback_post_tab(lambda x: self.restart_gl(), 'imu_restart_post_tab')

        self.gl_layout.activate()
        self.cbe_all_data.set_period(100)
        self.cbe_orientation.set_period(100)
        self.cbe_quaternion.set_period(50)
        self.update_timer.start(50)

        async_call(self.imu.get_convergence_speed, None, self.speed_spinbox.setValue, self.increase_error_count)

        self.mag_plot_widget.stop = False
        self.acc_plot_widget.stop = False
        self.gyr_plot_widget.stop = False
        self.temp_plot_widget.stop = False

    def stop(self):
        self.mag_plot_widget.stop = True
        self.acc_plot_widget.stop = True
        self.gyr_plot_widget.stop = True
        self.temp_plot_widget.stop = True

        self.update_timer.stop()
        self.cbe_all_data.set_period(0)
        self.cbe_orientation.set_period(0)
        self.cbe_quaternion.set_period(0)

    def destroy(self):
        self.alive = False
        self.cleanup_gl()
        if self.calibrate:
            self.calibrate.close()

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickIMU.DEVICE_IDENTIFIER

    def cb_all_data(self, acc_x, acc_y, acc_z, mag_x, mag_y, mag_z, gyr_x, gyr_y, gyr_z, temp):
        self.acc_x.value = acc_x
        self.acc_y.value = acc_y
        self.acc_z.value = acc_z
        self.mag_x.value = mag_x
        self.mag_y.value = mag_y
        self.mag_z.value = mag_z
        self.gyr_x.value = gyr_x / 14.375
        self.gyr_y.value = gyr_y / 14.375
        self.gyr_z.value = gyr_z / 14.375
        self.temp.value  = temp / 100.0

        self.all_data_valid = True

    def cb_quaternion(self, x, y, z, w):
        self.qua_x = x
        self.qua_y = y
        self.qua_z = z
        self.qua_w = w

        self.quaternion_valid = True

    def cb_orientation(self, roll, pitch, yaw):
        self.roll = roll / 100.0
        self.pitch = pitch / 100.0
        self.yaw = yaw / 100.0

        self.orientation_valid = True

    def led_clicked(self):
        if 'On' in self.led_button.text().replace('&', ''):
            self.led_button.setText('Turn LEDs Off')
            self.imu.leds_on()
        elif 'Off' in self.led_button.text().replace('&', ''):
            self.led_button.setText('Turn LEDs On')
            self.imu.leds_off()

    def update_data(self):
        self.update_counter += 1

        if self.quaternion_valid:
            self.imu_gl.update_orientation(self.qua_w, self.qua_x, self.qua_y, self.qua_z)

        if self.update_counter == 2:
            self.update_counter = 0

            if self.all_data_valid and self.orientation_valid:
                self.acceleration_update(self.acc_x.value, self.acc_y.value, self.acc_z.value)
                self.magnetometer_update(self.mag_x.value, self.mag_y.value, self.mag_z.value)
                self.gyroscope_update(self.gyr_x.value, self.gyr_y.value, self.gyr_z.value)
                self.orientation_update(self.roll, self.pitch, self.yaw)
                self.temperature_update(self.temp.value)

    def acceleration_update(self, x, y, z):
        self.acc_y_label.setText(format(x, '.1f'))
        self.acc_x_label.setText(format(y, '.1f'))
        self.acc_z_label.setText(format(z, '.1f'))

    def magnetometer_update(self, x, y, z):
        # Earth magnetic field: 0.5 Gauss
        self.mag_x_label.setText(format(x, '.1f'))
        self.mag_y_label.setText(format(y, '.1f'))
        self.mag_z_label.setText(format(z, '.1f'))

    def gyroscope_update(self, x, y, z):
        self.gyr_x_label.setText(format(x, '.1f'))
        self.gyr_y_label.setText(format(y, '.1f'))
        self.gyr_z_label.setText(format(z, '.1f'))

    def orientation_update(self, r, p, y):
        self.roll_label.setText(format(r, '.1f'))
        self.pitch_label.setText(format(p, '.1f'))
        self.yaw_label.setText(format(y, '.1f'))

    def temperature_update(self, t):
        self.tem_label.setText(format(t, '.1f'))

    def calibrate_clicked(self):
        self.stop()

        if self.calibrate is None:
            self.calibrate = CalibrateWindow(self)

        self.calibrate.refresh_values()
        self.calibrate.show()

    def speed_finished(self):
        speed = self.speed_spinbox.value()
        self.imu.set_convergence_speed(speed)
Beispiel #43
0
class HumidityV2(COMCUPluginBase):
    def __init__(self, *args):
        super().__init__(BrickletHumidityV2, *args)

        self.hum = self.device

        self.cbe_humidity = CallbackEmulator(self.hum.get_humidity,
                                             None,
                                             self.cb_humidity,
                                             self.increase_error_count)

        self.cbe_temperature = CallbackEmulator(self.hum.get_temperature,
                                                None,
                                                self.cb_temperature,
                                                self.increase_error_count)

        self.current_humidity = CurveValueWrapper() # float, %RH
        self.current_temperature = CurveValueWrapper() # float, °C

        moving_average_humidity = MovingAverageConfig(1, 1000, self.new_moving_average_humidity)
        plots_humidity = [('Relative Humidity', Qt.red, self.current_humidity, '{} %RH'.format)]
        self.plot_widget_humidity = PlotWidget('Relative Humidity [%RH]', plots_humidity,
                                               moving_average_config=moving_average_humidity, y_resolution=0.01)

        moving_average_temperature = MovingAverageConfig(1, 1000, self.new_moving_average_temperature)
        plots_temperature = [('Temperature', Qt.red, self.current_temperature, '{} °C'.format)]
        self.plot_widget_temperature = PlotWidget('Temperature [°C]', plots_temperature,
                                                  moving_average_config=moving_average_temperature, y_resolution=0.01)

        self.enable_heater = QCheckBox("Enable Heater")
        self.enable_heater.stateChanged.connect(self.enable_heater_changed)

        layout_plot = QHBoxLayout()
        layout_plot.addWidget(self.plot_widget_humidity)
        layout_plot.addWidget(self.plot_widget_temperature)

        layout_config = QHBoxLayout()
        layout_config.addStretch()
        layout_config.addWidget(self.enable_heater)
        layout_config.addStretch()

        layout_main = QVBoxLayout(self)
        layout_main.addLayout(layout_plot)
        layout_main.addLayout(layout_config)

    def new_moving_average_humidity(self, value):
        self.hum.set_moving_average_configuration(value, self.plot_widget_temperature.get_moving_average_value())

    def new_moving_average_temperature(self, value):
        self.hum.set_moving_average_configuration(self.plot_widget_humidity.get_moving_average_value(), value)

    def enable_heater_changed(self, state):
        if state == Qt.Checked:
            self.hum.set_heater_configuration(self.hum.HEATER_CONFIG_ENABLED)
        else:
            self.hum.set_heater_configuration(self.hum.HEATER_CONFIG_DISABLED)

    def start(self):
        async_call(self.hum.get_heater_configuration, None, self.get_heater_configuration_async, self.increase_error_count)
        async_call(self.hum.get_moving_average_configuration, None, self.get_moving_average_configuration_async, self.increase_error_count)

        self.cbe_humidity.set_period(100)
        self.cbe_temperature.set_period(100)

        self.plot_widget_humidity.stop = False
        self.plot_widget_temperature.stop = False

    def stop(self):
        self.cbe_humidity.set_period(0)
        self.cbe_temperature.set_period(0)

        self.plot_widget_humidity.stop = True
        self.plot_widget_temperature.stop = True

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletHumidityV2.DEVICE_IDENTIFIER

    def cb_humidity(self, humidity):
        self.current_humidity.value = humidity / 100.0

    def cb_temperature(self, temperature):
        self.current_temperature.value = temperature / 100.0

    def get_heater_configuration_async(self, heater_config):
        if heater_config == 0:
            self.enable_heater.setChecked(False)
        else:
            self.enable_heater.setChecked(True)

    def get_moving_average_configuration_async(self, average):
        self.plot_widget_humidity.set_moving_average_value(average.moving_average_length_humidity)
        self.plot_widget_temperature.set_moving_average_value(average.moving_average_length_temperature)
Beispiel #44
0
    def __init__(self, *args):
        super().__init__(BrickletAmbientLightV3, *args)

        self.al = self.device

        self.cbe_illuminance = CallbackEmulator(self.al.get_illuminance,
                                                None,
                                                self.cb_illuminance,
                                                self.increase_error_count)

        self.alf = AmbientLightFrame()
        self.out_of_range_label = QLabel('Illuminance is out-of-range')
        self.saturated_label = QLabel('Sensor is saturated')

        self.out_of_range_label.hide()
        self.out_of_range_label.setStyleSheet('QLabel { color: red }')
        self.saturated_label.hide()
        self.saturated_label.setStyleSheet('QLabel { color: magenta }')

        self.current_illuminance = CurveValueWrapper() # float, lx

        plots = [('Illuminance', Qt.red, self.current_illuminance, '{:.2f} lx (Lux)'.format)]
        self.plot_widget = PlotWidget('Illuminance [lx]', plots,
                                      extra_key_widgets=[self.out_of_range_label, self.saturated_label, self.alf],
                                      y_resolution=0.001)

        self.range_label = QLabel('Illuminance Range:')
        self.range_combo = QComboBox()

        self.range_combo.addItem("Unlimited", BrickletAmbientLightV3.ILLUMINANCE_RANGE_UNLIMITED)
        self.range_combo.addItem("0 - 64000 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_64000LUX)
        self.range_combo.addItem("0 - 32000 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_32000LUX)
        self.range_combo.addItem("0 - 16000 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_16000LUX)
        self.range_combo.addItem("0 - 8000 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_8000LUX)
        self.range_combo.addItem("0 - 1300 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_1300LUX)
        self.range_combo.addItem("0 - 600 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_600LUX)
        self.range_combo.currentIndexChanged.connect(self.new_config)

        self.time_label = QLabel('Integration Time:')
        self.time_combo = QComboBox()
        self.time_combo.addItem("50 ms", BrickletAmbientLightV3.INTEGRATION_TIME_50MS)
        self.time_combo.addItem("100 ms", BrickletAmbientLightV3.INTEGRATION_TIME_100MS)
        self.time_combo.addItem("150 ms", BrickletAmbientLightV3.INTEGRATION_TIME_150MS)
        self.time_combo.addItem("200 ms", BrickletAmbientLightV3.INTEGRATION_TIME_200MS)
        self.time_combo.addItem("250 ms", BrickletAmbientLightV3.INTEGRATION_TIME_250MS)
        self.time_combo.addItem("300 ms", BrickletAmbientLightV3.INTEGRATION_TIME_300MS)
        self.time_combo.addItem("350 ms", BrickletAmbientLightV3.INTEGRATION_TIME_350MS)
        self.time_combo.addItem("400 ms", BrickletAmbientLightV3.INTEGRATION_TIME_400MS)
        self.time_combo.currentIndexChanged.connect(self.new_config)

        hlayout = QHBoxLayout()
        hlayout.addWidget(self.range_label)
        hlayout.addWidget(self.range_combo)
        hlayout.addStretch()
        hlayout.addWidget(self.time_label)
        hlayout.addWidget(self.time_combo)

        line = QFrame()
        line.setObjectName("line")
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)
Beispiel #45
0
class AmbientLightV3(COMCUPluginBase):
    def __init__(self, *args):
        super().__init__(BrickletAmbientLightV3, *args)

        self.al = self.device

        self.cbe_illuminance = CallbackEmulator(self.al.get_illuminance,
                                                None,
                                                self.cb_illuminance,
                                                self.increase_error_count)

        self.alf = AmbientLightFrame()
        self.out_of_range_label = QLabel('Illuminance is out-of-range')
        self.saturated_label = QLabel('Sensor is saturated')

        self.out_of_range_label.hide()
        self.out_of_range_label.setStyleSheet('QLabel { color: red }')
        self.saturated_label.hide()
        self.saturated_label.setStyleSheet('QLabel { color: magenta }')

        self.current_illuminance = CurveValueWrapper() # float, lx

        plots = [('Illuminance', Qt.red, self.current_illuminance, '{:.2f} lx (Lux)'.format)]
        self.plot_widget = PlotWidget('Illuminance [lx]', plots,
                                      extra_key_widgets=[self.out_of_range_label, self.saturated_label, self.alf],
                                      y_resolution=0.001)

        self.range_label = QLabel('Illuminance Range:')
        self.range_combo = QComboBox()

        self.range_combo.addItem("Unlimited", BrickletAmbientLightV3.ILLUMINANCE_RANGE_UNLIMITED)
        self.range_combo.addItem("0 - 64000 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_64000LUX)
        self.range_combo.addItem("0 - 32000 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_32000LUX)
        self.range_combo.addItem("0 - 16000 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_16000LUX)
        self.range_combo.addItem("0 - 8000 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_8000LUX)
        self.range_combo.addItem("0 - 1300 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_1300LUX)
        self.range_combo.addItem("0 - 600 lx", BrickletAmbientLightV3.ILLUMINANCE_RANGE_600LUX)
        self.range_combo.currentIndexChanged.connect(self.new_config)

        self.time_label = QLabel('Integration Time:')
        self.time_combo = QComboBox()
        self.time_combo.addItem("50 ms", BrickletAmbientLightV3.INTEGRATION_TIME_50MS)
        self.time_combo.addItem("100 ms", BrickletAmbientLightV3.INTEGRATION_TIME_100MS)
        self.time_combo.addItem("150 ms", BrickletAmbientLightV3.INTEGRATION_TIME_150MS)
        self.time_combo.addItem("200 ms", BrickletAmbientLightV3.INTEGRATION_TIME_200MS)
        self.time_combo.addItem("250 ms", BrickletAmbientLightV3.INTEGRATION_TIME_250MS)
        self.time_combo.addItem("300 ms", BrickletAmbientLightV3.INTEGRATION_TIME_300MS)
        self.time_combo.addItem("350 ms", BrickletAmbientLightV3.INTEGRATION_TIME_350MS)
        self.time_combo.addItem("400 ms", BrickletAmbientLightV3.INTEGRATION_TIME_400MS)
        self.time_combo.currentIndexChanged.connect(self.new_config)

        hlayout = QHBoxLayout()
        hlayout.addWidget(self.range_label)
        hlayout.addWidget(self.range_combo)
        hlayout.addStretch()
        hlayout.addWidget(self.time_label)
        hlayout.addWidget(self.time_combo)

        line = QFrame()
        line.setObjectName("line")
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)

    def start(self):
        async_call(self.al.get_configuration, None, self.get_configucation_async, self.increase_error_count)

        self.cbe_illuminance.set_period(100)

        self.plot_widget.stop = False

    def stop(self):
        self.cbe_illuminance.set_period(0)

        self.plot_widget.stop = True

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletAmbientLightV3.DEVICE_IDENTIFIER

    def get_configucation_async(self, conf):
        self.range_combo.setCurrentIndex(self.range_combo.findData(conf.illuminance_range))
        self.time_combo.setCurrentIndex(self.time_combo.findData(conf.integration_time))

    def new_config(self, _value):
        try:
            self.al.set_configuration(self.range_combo.itemData(self.range_combo.currentIndex()),
                                      self.time_combo.itemData(self.time_combo.currentIndex()))
        except ip_connection.Error:
            pass

    def cb_illuminance(self, illuminance):
        self.current_illuminance.value = illuminance / 100.0

        max_illuminance = 12000000 # Approximation for unlimited range
        current_range = self.range_combo.itemData(self.range_combo.currentIndex())

        if current_range == BrickletAmbientLightV3.ILLUMINANCE_RANGE_64000LUX:
            max_illuminance = 6400001
        elif current_range == BrickletAmbientLightV3.ILLUMINANCE_RANGE_32000LUX:
            max_illuminance = 3200001
        elif current_range == BrickletAmbientLightV3.ILLUMINANCE_RANGE_16000LUX:
            max_illuminance = 1600001
        elif current_range == BrickletAmbientLightV3.ILLUMINANCE_RANGE_8000LUX:
            max_illuminance = 800001
        elif current_range == BrickletAmbientLightV3.ILLUMINANCE_RANGE_1300LUX:
            max_illuminance = 130001
        elif current_range == BrickletAmbientLightV3.ILLUMINANCE_RANGE_600LUX:
            max_illuminance = 60001

        if illuminance == 0:
            self.plot_widget.get_key_item(0).setStyleSheet('QLabel { color: magenta }')
            self.out_of_range_label.hide()
            self.saturated_label.show()
        elif illuminance >= max_illuminance:
            self.plot_widget.get_key_item(0).setStyleSheet('QLabel { color: red }')
            self.out_of_range_label.show()
            self.saturated_label.hide()
        else:
            self.plot_widget.get_key_item(0).setStyleSheet('')
            self.out_of_range_label.hide()
            self.saturated_label.hide()

        value = min(max(illuminance * 255 // max_illuminance, 0), 255)
        self.alf.set_color(value, value, value)
Beispiel #46
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletAmbientLightV2, *args)

        self.al = self.device

        self.has_clamped_output = self.firmware_version >= (2, 0, 2)

        self.cbe_illuminance = CallbackEmulator(self.al.get_illuminance, self.cb_illuminance, self.increase_error_count)

        self.alf = AmbientLightFrame()
        self.out_of_range_label = QLabel("Illuminance is out-of-range")
        self.saturated_label = QLabel("Sensor is saturated")

        self.out_of_range_label.hide()
        self.out_of_range_label.setStyleSheet("QLabel { color: red }")
        self.saturated_label.hide()
        self.saturated_label.setStyleSheet("QLabel { color: magenta }")

        self.current_illuminance = None  # float, lx

        plots = [("Illuminance", Qt.red, lambda: self.current_illuminance, "{:.2f} lx (Lux)".format)]
        self.plot_widget = PlotWidget(
            "Illuminance [lx]", plots, extra_key_widgets=[self.out_of_range_label, self.saturated_label, self.alf]
        )

        self.range_label = QLabel("Illuminance Range: ")
        self.range_combo = QComboBox()
        if self.has_clamped_output:  # Also means that the unlimited range is available
            self.range_combo.addItem("Unlimited", BrickletAmbientLightV2.ILLUMINANCE_RANGE_UNLIMITED)
        self.range_combo.addItem("0 - 64000 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_64000LUX)
        self.range_combo.addItem("0 - 32000 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_32000LUX)
        self.range_combo.addItem("0 - 16000 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_16000LUX)
        self.range_combo.addItem("0 - 8000 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_8000LUX)
        self.range_combo.addItem("0 - 1300 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_1300LUX)
        self.range_combo.addItem("0 - 600 lx", BrickletAmbientLightV2.ILLUMINANCE_RANGE_600LUX)
        self.range_combo.currentIndexChanged.connect(self.new_config)

        self.time_label = QLabel("Integration Time: ")
        self.time_combo = QComboBox()
        self.time_combo.addItem("50 ms", BrickletAmbientLightV2.INTEGRATION_TIME_50MS)
        self.time_combo.addItem("100 ms", BrickletAmbientLightV2.INTEGRATION_TIME_100MS)
        self.time_combo.addItem("150 ms", BrickletAmbientLightV2.INTEGRATION_TIME_150MS)
        self.time_combo.addItem("200 ms", BrickletAmbientLightV2.INTEGRATION_TIME_200MS)
        self.time_combo.addItem("250 ms", BrickletAmbientLightV2.INTEGRATION_TIME_250MS)
        self.time_combo.addItem("300 ms", BrickletAmbientLightV2.INTEGRATION_TIME_300MS)
        self.time_combo.addItem("350 ms", BrickletAmbientLightV2.INTEGRATION_TIME_350MS)
        self.time_combo.addItem("400 ms", BrickletAmbientLightV2.INTEGRATION_TIME_400MS)
        self.time_combo.currentIndexChanged.connect(self.new_config)

        hlayout = QHBoxLayout()
        hlayout.addWidget(self.range_label)
        hlayout.addWidget(self.range_combo)
        hlayout.addStretch()
        hlayout.addWidget(self.time_label)
        hlayout.addWidget(self.time_combo)

        line = QFrame()
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line)
        layout.addLayout(hlayout)
Beispiel #47
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickIMU, *args)

        self.setupUi(self)

        self.imu = self.device

        # the firmware version of a Brick can (under common circumstances) not
        # change during the lifetime of a Brick plugin. therefore, it's okay to
        # make final decisions based on it here
        self.has_status_led = self.firmware_version >= (2, 3, 1)

        self.acc_x = CurveValueWrapper()
        self.acc_y = CurveValueWrapper()
        self.acc_z = CurveValueWrapper()
        self.mag_x = CurveValueWrapper()
        self.mag_y = CurveValueWrapper()
        self.mag_z = CurveValueWrapper()
        self.gyr_x = CurveValueWrapper()
        self.gyr_y = CurveValueWrapper()
        self.gyr_z = CurveValueWrapper()
        self.temp  = CurveValueWrapper()
        self.roll  = None
        self.pitch = None
        self.yaw   = None
        self.qua_x = None
        self.qua_y = None
        self.qua_z = None
        self.qua_w = None

        self.all_data_valid = False
        self.quaternion_valid = False
        self.orientation_valid = False

        self.update_timer = QTimer(self)
        self.update_timer.timeout.connect(self.update_data)

        self.cbe_all_data = CallbackEmulator(self.imu.get_all_data,
                                             None,
                                             self.cb_all_data,
                                             self.increase_error_count,
                                             expand_result_tuple_for_callback=True,
                                             use_result_signal=False)
        self.cbe_orientation = CallbackEmulator(self.imu.get_orientation,
                                                None,
                                                self.cb_orientation,
                                                self.increase_error_count,
                                                expand_result_tuple_for_callback=True,
                                                use_result_signal=False)
        self.cbe_quaternion = CallbackEmulator(self.imu.get_quaternion,
                                               None,
                                               self.cb_quaternion,
                                               self.increase_error_count,
                                               expand_result_tuple_for_callback=True,
                                               use_result_signal=False)

        self.imu_gl = IMU3DWidget(self)
        self.imu_gl.setMinimumSize(150, 150)
        self.imu_gl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.update_counter = 0

        self.mag_plot_widget = PlotWidget("Magnetic Field [mG]",
                                          [("X", Qt.red, self.mag_x, str),
                                           ("Y", Qt.darkGreen, self.mag_y, str),
                                           ("Z", Qt.blue, self.mag_z, str)],
                                          clear_button=self.clear_graphs,
                                          key='right-no-icon', y_resolution=5)
        self.acc_plot_widget = PlotWidget("Acceleration [mg]",
                                          [("X", Qt.red, self.acc_x, str),
                                           ("Y", Qt.darkGreen, self.acc_y, str),
                                           ("Z", Qt.blue, self.acc_z, str)],
                                          clear_button=self.clear_graphs,
                                          key='right-no-icon', y_resolution=5)
        self.gyr_plot_widget = PlotWidget("Angular Velocity [°/s]",
                                          [("X", Qt.red, self.gyr_x, str),
                                           ("Y", Qt.darkGreen, self.gyr_y, str),
                                           ("Z", Qt.blue, self.gyr_z, str)],
                                          clear_button=self.clear_graphs,
                                          key='right-no-icon', y_resolution=0.05)
        self.temp_plot_widget = PlotWidget("Temperature [°C]",
                                           [("t", Qt.red, self.temp, str)],
                                           clear_button=self.clear_graphs,
                                           key=None, y_resolution=0.01)

        self.mag_plot_widget.setMinimumSize(250, 250)
        self.acc_plot_widget.setMinimumSize(250, 250)
        self.gyr_plot_widget.setMinimumSize(250, 250)
        self.temp_plot_widget.setMinimumSize(250, 250)

        self.orientation_label = QLabel('Position your IMU Brick as shown in the image above, then press "Save Orientation".')
        self.orientation_label.setWordWrap(True)
        self.orientation_label.setAlignment(Qt.AlignHCenter)
        self.gl_layout = QVBoxLayout()
        self.gl_layout.addWidget(self.imu_gl)
        self.gl_layout.addWidget(self.orientation_label)

        self.layout_top.addWidget(self.gyr_plot_widget)
        self.layout_top.addWidget(self.acc_plot_widget)
        self.layout_top.addWidget(self.mag_plot_widget)
        self.layout_bottom.addLayout(self.gl_layout)
        self.layout_bottom.addWidget(self.temp_plot_widget)

        self.save_orientation.clicked.connect(self.save_orientation_clicked)
        self.calibrate.clicked.connect(self.calibrate_clicked)
        self.led_button.clicked.connect(self.led_clicked)
        self.speed_spinbox.editingFinished.connect(self.speed_finished)

        width = QFontMetrics(self.gyr_x_label.font()).boundingRect('-XXXX.X').width()

        self.gyr_x_label.setMinimumWidth(width)
        self.gyr_y_label.setMinimumWidth(width)
        self.gyr_z_label.setMinimumWidth(width)

        self.calibrate = None
        self.alive = True

        if self.has_status_led:
            self.status_led_action = QAction('Status LED', self)
            self.status_led_action.setCheckable(True)
            self.status_led_action.toggled.connect(lambda checked: self.imu.enable_status_led() if checked else self.imu.disable_status_led())
            self.set_configs([(0, None, [self.status_led_action])])
        else:
            self.status_led_action = None

        reset = QAction('Reset', self)
        reset.triggered.connect(self.imu.reset)
        self.set_actions([(0, None, [reset])])
Beispiel #48
0
    def __init__(self, *args):
        super().__init__(BrickletColorV2, *args)

        self.color = self.device

        self.cbe_color = CallbackEmulator(self.color.get_color,
                                          None,
                                          self.cb_color,
                                          self.increase_error_count,
                                          expand_result_tuple_for_callback=True)
        self.cbe_illuminance = CallbackEmulator(self.color.get_illuminance,
                                                None,
                                                self.cb_illuminance,
                                                self.increase_error_count)
        self.cbe_color_temperature = CallbackEmulator(self.color.get_color_temperature,
                                                      None,
                                                      self.cb_color_temperature,
                                                      self.increase_error_count)

        self.color_frame = ColorFrame()
        self.illuminance_frame = ColorFrame()
        self.color_temperature_frame = ColorFrame()

        self.current_color_r = CurveValueWrapper() # int
        self.current_color_g = CurveValueWrapper() # int
        self.current_color_b = CurveValueWrapper() # int
        self.current_color_c = CurveValueWrapper() # int
        self.current_illuminance = CurveValueWrapper() # float, lx
        self.current_color_temperature = CurveValueWrapper() # int, K

        self.clear_graphs_button = QPushButton("Clear Graphs")

        plots = [('R', Qt.red, self.current_color_r, lambda value: self.format_color(0, value)),
                 ('G', Qt.darkGreen, self.current_color_g, lambda value: self.format_color(1, value)),
                 ('B', Qt.blue, self.current_color_b, lambda value: self.format_color(2, value)),
                 ('C', Qt.black, self.current_color_c, str)]
        self.plot_widget = PlotWidget('Color', plots, clear_button=self.clear_graphs_button,
                                      extra_key_widgets=[self.color_frame], y_resolution=1.0)
        self.plot_widget.setMinimumSize(250, 200)

        plots_illuminance = [('Illuminance', Qt.red, self.current_illuminance, '{} lx (Lux)'.format)]
        self.plot_widget_illuminance = PlotWidget('Illuminance [lx]', plots_illuminance,
                                                  clear_button=self.clear_graphs_button,
                                                  extra_key_widgets=[self.illuminance_frame],
                                                  y_resolution=0.1)
        self.plot_widget_illuminance.setMinimumSize(250, 200)

        plots_color_temperature = [('Color Temperature', Qt.red, self.current_color_temperature, '{} K'.format)]
        self.plot_widget_color_temperature = PlotWidget('Color Temperature [K]', plots_color_temperature,
                                                        clear_button=self.clear_graphs_button,
                                                        extra_key_widgets=[self.color_temperature_frame],
                                                        y_resolution=1.0)
        self.plot_widget_color_temperature.setMinimumSize(250, 200)

        self.gain_label = QLabel('Gain:')
        self.gain_combo = QComboBox()
        self.gain_combo.addItem("1x")
        self.gain_combo.addItem("4x")
        self.gain_combo.addItem("16x")
        self.gain_combo.addItem("60x")

        self.gain_combo.currentIndexChanged.connect(self.gain_changed)

        self.current_gain_factor = 60

        self.conversion_label = QLabel('Integration Time:')
        self.conversion_combo = QComboBox()
        self.conversion_combo.addItem("2.4 ms")
        self.conversion_combo.addItem("24 ms")
        self.conversion_combo.addItem("101 ms")
        self.conversion_combo.addItem("154 ms")
        self.conversion_combo.addItem("700 ms")

        self.current_conversion_time = 154

        self.conversion_combo.currentIndexChanged.connect(self.conversion_changed)

        self.light_checkbox = QCheckBox("Enable Light")

        self.light_checkbox.stateChanged.connect(self.light_state_changed)

        layout_h1 = QHBoxLayout()
        layout_h1.addWidget(self.plot_widget_illuminance)
        layout_h1.addWidget(self.plot_widget_color_temperature)

        layout_h2 = QHBoxLayout()
        layout_h2.addWidget(self.gain_label)
        layout_h2.addWidget(self.gain_combo)
        layout_h2.addWidget(self.conversion_label)
        layout_h2.addWidget(self.conversion_combo)
        layout_h2.addWidget(self.light_checkbox)
        layout_h2.addStretch()
        layout_h2.addWidget(self.clear_graphs_button)

        line1 = QFrame()
        line1.setObjectName("line1")
        line1.setFrameShape(QFrame.HLine)
        line1.setFrameShadow(QFrame.Sunken)

        line2 = QFrame()
        line2.setObjectName("line2")
        line2.setFrameShape(QFrame.HLine)
        line2.setFrameShadow(QFrame.Sunken)

        layout = QVBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addWidget(line1)
        layout.addLayout(layout_h1)
        layout.addWidget(line2)
        layout.addLayout(layout_h2)

        self.k_to_rgb = {1000:(255, 56, 0), 1100:(255, 71, 0), 1200:(255, 83, 0), 1300:(255, 93, 0), 1400:(255, 101, 0), 1500:(255, 109, 0), 1600:(255, 115, 0), 1700:(255, 121, 0), 1800:(255, 126, 0), 1900:(255, 131, 0), 2000:(255, 137, 18), 2100:(255, 142, 33), 2200:(255, 147, 44), 2300:(255, 152, 54), 2400:(255, 157, 63), 2500:(255, 161, 72), 2600:(255, 165, 79), 2700:(255, 169, 87), 2800:(255, 173, 94), 2900:(255, 177, 101), 3000:(255, 180, 107), 3100:(255, 184, 114), 3200:(255, 187, 120), 3300:(255, 190, 126), 3400:(255, 193, 132), 3500:(255, 196, 137), 3600:(255, 199, 143), 3700:(255, 201, 148), 3800:(255, 204, 153), 3900:(255, 206, 159), 4000:(255, 209, 163), 4100:(255, 211, 168), 4200:(255, 213, 173), 4300:(255, 215, 177), 4400:(255, 217, 182), 4500:(255, 219, 186), 4600:(255, 221, 190), 4700:(255, 223, 194), 4800:(255, 225, 198), 4900:(255, 227, 202), 5000:(255, 228, 206), 5100:(255, 230, 210), 5200:(255, 232, 213), 5300:(255, 233, 217), 5400:(255, 235, 220), 5500:(255, 236, 224), 5600:(255, 238, 227), 5700:(255, 239, 230), 5800:(255, 240, 233), 5900:(255, 242, 236), 6000:(255, 243, 239), 6100:(255, 244, 242), 6200:(255, 245, 245), 6300:(255, 246, 248), 6400:(255, 248, 251), 6500:(255, 249, 253), 6600:(254, 249, 255), 6700:(252, 247, 255), 6800:(249, 246, 255), 6900:(247, 245, 255), 7000:(245, 243, 255), 7100:(243, 242, 255), 7200:(240, 241, 255), 7300:(239, 240, 255), 7400:(237, 239, 255), 7500:(235, 238, 255), 7600:(233, 237, 255), 7700:(231, 236, 255), 7800:(230, 235, 255), 7900:(228, 234, 255), 8000:(227, 233, 255), 8100:(225, 232, 255), 8200:(224, 231, 255), 8300:(222, 230, 255), 8400:(221, 230, 255), 8500:(220, 229, 255), 8600:(218, 228, 255), 8700:(217, 227, 255), 8800:(216, 227, 255), 8900:(215, 226, 255), 9000:(214, 225, 255), 9100:(212, 225, 255), 9200:(211, 224, 255), 9300:(210, 223, 255), 9400:(209, 223, 255), 9500:(208, 222, 255), 9600:(207, 221, 255), 9700:(207, 221, 255), 9800:(206, 220, 255), 9900:(205, 220, 255), 10000:(204, 219, 255), 10100:(203, 219, 255), 10200:(202, 218, 255), 10300:(201, 218, 255), 10400:(201, 217, 255), 10500:(200, 217, 255), 10600:(199, 216, 255), 10700:(199, 216, 255), 10800:(198, 216, 255), 10900:(197, 215, 255), 11000:(196, 215, 255), 11100:(196, 214, 255), 11200:(195, 214, 255), 11300:(195, 214, 255), 11400:(194, 213, 255), 11500:(193, 213, 255), 11600:(193, 212, 255), 11700:(192, 212, 255), 11800:(192, 212, 255), 11900:(191, 211, 255), 12000:(191, 211, 255), 12100:(190, 211, 255), 12200:(190, 210, 255), 12300:(189, 210, 255), 12400:(189, 210, 255), 12500:(188, 210, 255), 12600:(188, 209, 255), 12700:(187, 209, 255), 12800:(187, 209, 255), 12900:(186, 208, 255), 13000:(186, 208, 255), 13100:(185, 208, 255), 13200:(185, 208, 255), 13300:(185, 207, 255), 13400:(184, 207, 255), 13500:(184, 207, 255), 13600:(183, 207, 255), 13700:(183, 206, 255), 13800:(183, 206, 255), 13900:(182, 206, 255), 14000:(182, 206, 255), 14100:(182, 205, 255), 14200:(181, 205, 255), 14300:(181, 205, 255), 14400:(181, 205, 255), 14500:(180, 205, 255), 14600:(180, 204, 255), 14700:(180, 204, 255), 14800:(179, 204, 255), 14900:(179, 204, 255), 15000:(179, 204, 255), 15100:(178, 203, 255), 15200:(178, 203, 255), 15300:(178, 203, 255), 15400:(178, 203, 255), 15500:(177, 203, 255), 15600:(177, 202, 255), 15700:(177, 202, 255), 15800:(177, 202, 255), 15900:(176, 202, 255), 16000:(176, 202, 255), 16100:(176, 202, 255), 16200:(175, 201, 255), 16300:(175, 201, 255), 16400:(175, 201, 255), 16500:(175, 201, 255), 16600:(175, 201, 255), 16700:(174, 201, 255), 16800:(174, 201, 255), 16900:(174, 200, 255), 17000:(174, 200, 255), 17100:(173, 200, 255), 17200:(173, 200, 255), 17300:(173, 200, 255), 17400:(173, 200, 255), 17500:(173, 200, 255), 17600:(172, 199, 255), 17700:(172, 199, 255), 17800:(172, 199, 255), 17900:(172, 199, 255), 18000:(172, 199, 255), 18100:(171, 199, 255), 18200:(171, 199, 255), 18300:(171, 199, 255), 18400:(171, 198, 255), 18500:(171, 198, 255), 18600:(170, 198, 255), 18700:(170, 198, 255), 18800:(170, 198, 255), 18900:(170, 198, 255), 19000:(170, 198, 255), 19100:(170, 198, 255), 19200:(169, 198, 255), 19300:(169, 197, 255), 19400:(169, 197, 255), 19500:(169, 197, 255), 19600:(169, 197, 255), 19700:(169, 197, 255), 19800:(169, 197, 255), 19900:(168, 197, 255), 20000:(168, 197, 255), 20100:(168, 197, 255), 20200:(168, 197, 255), 20300:(168, 196, 255), 20400:(168, 196, 255), 20500:(168, 196, 255), 20600:(167, 196, 255), 20700:(167, 196, 255), 20800:(167, 196, 255), 20900:(167, 196, 255), 21000:(167, 196, 255), 21100:(167, 196, 255), 21200:(167, 196, 255), 21300:(166, 196, 255), 21400:(166, 195, 255), 21500:(166, 195, 255), 21600:(166, 195, 255), 21700:(166, 195, 255), 21800:(166, 195, 255), 21900:(166, 195, 255), 22000:(166, 195, 255), 22100:(165, 195, 255), 22200:(165, 195, 255), 22300:(165, 195, 255), 22400:(165, 195, 255), 22500:(165, 195, 255), 22600:(165, 195, 255), 22700:(165, 194, 255), 22800:(165, 194, 255), 22900:(165, 194, 255), 23000:(164, 194, 255), 23100:(164, 194, 255), 23200:(164, 194, 255), 23300:(164, 194, 255), 23400:(164, 194, 255), 23500:(164, 194, 255), 23600:(164, 194, 255), 23700:(164, 194, 255), 23800:(164, 194, 255), 23900:(164, 194, 255), 24000:(163, 194, 255), 24100:(163, 194, 255), 24200:(163, 193, 255), 24300:(163, 193, 255), 24400:(163, 193, 255), 24500:(163, 193, 255), 24600:(163, 193, 255), 24700:(163, 193, 255), 24800:(163, 193, 255), 24900:(163, 193, 255), 25000:(163, 193, 255), 25100:(162, 193, 255), 25200:(162, 193, 255), 25300:(162, 193, 255), 25400:(162, 193, 255), 25500:(162, 193, 255), 25600:(162, 193, 255), 25700:(162, 193, 255), 25800:(162, 193, 255), 25900:(162, 192, 255), 26000:(162, 192, 255), 26100:(162, 192, 255), 26200:(162, 192, 255), 26300:(162, 192, 255), 26400:(161, 192, 255), 26500:(161, 192, 255), 26600:(161, 192, 255), 26700:(161, 192, 255), 26800:(161, 192, 255), 26900:(161, 192, 255), 27000:(161, 192, 255), 27100:(161, 192, 255), 27200:(161, 192, 255), 27300:(161, 192, 255), 27400:(161, 192, 255), 27500:(161, 192, 255), 27600:(161, 192, 255), 27700:(161, 192, 255), 27800:(160, 192, 255), 27900:(160, 192, 255), 28000:(160, 191, 255), 28100:(160, 191, 255), 28200:(160, 191, 255), 28300:(160, 191, 255), 28400:(160, 191, 255), 28500:(160, 191, 255), 28600:(160, 191, 255), 28700:(160, 191, 255), 28800:(160, 191, 255), 28900:(160, 191, 255), 29000:(160, 191, 255), 29100:(160, 191, 255), 29200:(160, 191, 255), 29300:(159, 191, 255), 29400:(159, 191, 255), 29500:(159, 191, 255), 29600:(159, 191, 255), 29700:(159, 191, 255), 29800:(159, 191, 255), 29900:(159, 191, 255), 30000:(159, 191, 255), 30100:(159, 191, 255), 30200:(159, 191, 255), 30300:(159, 191, 255), 30400:(159, 190, 255), 30500:(159, 190, 255), 30600:(159, 190, 255), 30700:(159, 190, 255), 30800:(159, 190, 255), 30900:(159, 190, 255), 31000:(159, 190, 255), 31100:(158, 190, 255), 31200:(158, 190, 255), 31300:(158, 190, 255), 31400:(158, 190, 255), 31500:(158, 190, 255), 31600:(158, 190, 255), 31700:(158, 190, 255), 31800:(158, 190, 255), 31900:(158, 190, 255), 32000:(158, 190, 255), 32100:(158, 190, 255), 32200:(158, 190, 255), 32300:(158, 190, 255), 32400:(158, 190, 255), 32500:(158, 190, 255), 32600:(158, 190, 255), 32700:(158, 190, 255), 32800:(158, 190, 255), 32900:(158, 190, 255), 33000:(158, 190, 255), 33100:(158, 190, 255), 33200:(157, 190, 255), 33300:(157, 190, 255), 33400:(157, 189, 255), 33500:(157, 189, 255), 33600:(157, 189, 255), 33700:(157, 189, 255), 33800:(157, 189, 255), 33900:(157, 189, 255), 34000:(157, 189, 255), 34100:(157, 189, 255), 34200:(157, 189, 255), 34300:(157, 189, 255), 34400:(157, 189, 255), 34500:(157, 189, 255), 34600:(157, 189, 255), 34700:(157, 189, 255), 34800:(157, 189, 255), 34900:(157, 189, 255), 35000:(157, 189, 255), 35100:(157, 189, 255), 35200:(157, 189, 255), 35300:(157, 189, 255), 35400:(157, 189, 255), 35500:(157, 189, 255), 35600:(156, 189, 255), 35700:(156, 189, 255), 35800:(156, 189, 255), 35900:(156, 189, 255), 36000:(156, 189, 255), 36100:(156, 189, 255), 36200:(156, 189, 255), 36300:(156, 189, 255), 36400:(156, 189, 255), 36500:(156, 189, 255), 36600:(156, 189, 255), 36700:(156, 189, 255), 36800:(156, 189, 255), 36900:(156, 189, 255), 37000:(156, 189, 255), 37100:(156, 189, 255), 37200:(156, 188, 255), 37300:(156, 188, 255), 37400:(156, 188, 255), 37500:(156, 188, 255), 37600:(156, 188, 255), 37700:(156, 188, 255), 37800:(156, 188, 255), 37900:(156, 188, 255), 38000:(156, 188, 255), 38100:(156, 188, 255), 38200:(156, 188, 255), 38300:(156, 188, 255), 38400:(155, 188, 255), 38500:(155, 188, 255), 38600:(155, 188, 255), 38700:(155, 188, 255), 38800:(155, 188, 255), 38900:(155, 188, 255), 39000:(155, 188, 255), 39100:(155, 188, 255), 39200:(155, 188, 255), 39300:(155, 188, 255), 39400:(155, 188, 255), 39500:(155, 188, 255), 39600:(155, 188, 255), 39700:(155, 188, 255), 39800:(155, 188, 255), 39900:(155, 188, 255), 40000:(155, 188, 255)}
class SoundPressureLevel(COMCUPluginBase, Ui_SoundPressureLevel):
    qtcb_spectrum = pyqtSignal(object)

    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletSoundPressureLevel, *args)

        self.setupUi(self)

        self.sound_pressure_level = self.device
        self.cbe_get_decibel = CallbackEmulator(self.sound_pressure_level.get_decibel,
                                                None,
                                                self.cb_decibel,
                                                self.increase_error_count)

        self.qtcb_spectrum.connect(self.cb_spectrum)

        self.thermo = TuningThermo()

        plots_spectrum = [('Spectrum', Qt.red, None, '{} °C'.format)]
        self.plot_widget_spectrum = PlotWidget('Value [dB]', plots_spectrum, clear_button=None,
                                               x_diff=20480, x_scale_title_text='Frequency [Hz]',
                                               x_scale_skip_last_tick=False, key=None, y_resolution=0.1,
                                               y_scale_shrinkable=False)
        self.plot_widget_spectrum.set_x_scale(512*40//5, 1)

        self.combo_fft_size.currentIndexChanged.connect(self.config_changed)
        self.combo_weighting.currentIndexChanged.connect(self.config_changed)

        self.layout_graph.addWidget(self.plot_widget_spectrum)
        self.layout_decibel.insertWidget(3, self.thermo)

        self.last_spectrum_length = 512

        self.last_y_data = [0]*512

    def get_spectrum_decrement(self):
        index = self.combo_fft_size.currentIndex()

        if index == 0:
            return 0.5
        elif index == 1:
            return 1
        elif index == 2:
            return 2
        elif index == 3:
            return 4

    def config_changed(self, _):
        self.last_y_data = [0]*512
        self.sound_pressure_level.set_configuration(self.combo_fft_size.currentIndex(), self.combo_weighting.currentIndex())

    def cb_decibel(self, db):
        self.label_decibel.setText("{:.1f}".format(db/10.0))
        self.thermo.set_value(db)

    def cb_spectrum(self, spectrum):
        length = len(spectrum)
        num = 20480 // length

        x_data = list(range(0, num * length, num))
        y_data = list(map(lambda x: 20 * math.log10(max(1, x / math.sqrt(2))), spectrum))

        if self.checkbox_decay.isChecked():
            for i in range(len(y_data)):
                if y_data[i] > self.last_y_data[i]:
                    self.last_y_data[i] = y_data[i]
                else:
                    self.last_y_data[i] -= self.get_spectrum_decrement()

                    if y_data[i] > self.last_y_data[i]:
                        self.last_y_data[i] = y_data[i]

            self.plot_widget_spectrum.set_data(0, x_data, self.last_y_data)
        else:
            self.plot_widget_spectrum.set_data(0, x_data, y_data)

    def get_configuration_async(self, config):
        self.combo_fft_size.blockSignals(True)
        self.combo_fft_size.setCurrentIndex(config.fft_size)
        self.combo_fft_size.blockSignals(False)

        self.combo_weighting.blockSignals(True)
        self.combo_weighting.setCurrentIndex(config.weighting)
        self.combo_weighting.blockSignals(False)

    def start(self):
        self.sound_pressure_level.register_callback(self.sound_pressure_level.CALLBACK_SPECTRUM, self.qtcb_spectrum.emit)

        async_call(self.sound_pressure_level.get_configuration, None, self.get_configuration_async, self.increase_error_count)
        async_call(self.sound_pressure_level.set_spectrum_callback_configuration, 1, None, self.increase_error_count)

        self.cbe_get_decibel.set_period(50)

    def stop(self):
        self.sound_pressure_level.register_callback(self.sound_pressure_level.CALLBACK_SPECTRUM, None)

        async_call(self.sound_pressure_level.set_spectrum_callback_configuration, 0, None, self.increase_error_count)

        self.cbe_get_decibel.set_period(0)

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletSoundPressureLevel.DEVICE_IDENTIFIER
Beispiel #50
0
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'IMU Brick', version)
        
        self.setupUi(self)
        
        self.imu = BrickIMU(uid, ipcon)
        self.device = self.imu
        
        self.acc_x = 0
        self.acc_y = 0
        self.acc_z = 0
        self.mag_x = 0
        self.mag_y = 0
        self.mag_z = 0
        self.gyr_x = 0
        self.gyr_y = 0
        self.gyr_z = 0
        self.tem   = 0
        self.roll  = 0
        self.pitch = 0
        self.yaw   = 0
        self.qua_x = 0
        self.qua_y = 0
        self.qua_z = 0
        self.qua_w = 0
        
        self.old_time = 0
        
        self.update_timer = QTimer()
        self.update_timer.timeout.connect(self.update_data)
        
        self.imu.register_callback(self.imu.CALLBACK_ALL_DATA, 
                                   self.all_data_callback)
        self.imu.register_callback(self.imu.CALLBACK_ORIENTATION,
                                   self.orientation_callback)
        self.imu.register_callback(self.imu.CALLBACK_QUATERNION,
                                   self.quaternion_callback)
        
        # Import IMUGLWidget here, not global. If globally included we get
        # 'No OpenGL_accelerate module loaded: No module named OpenGL_accelerate'
        # as soon as IMU is set as device_class in __init__. 
        # No idea why this happens, doesn't make sense.
        from imu_gl_widget import IMUGLWidget
        
        self.imu_gl = IMUGLWidget(self)
        self.imu_gl.setMinimumSize(150, 150)
        self.imu_gl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.min_x = 0
        self.min_y = 0
        self.min_z = 0
        self.max_x = 0 
        self.max_y = 0
        self.max_z = 0
        
        self.counter = 0
        self.update_counter = 0
        
        self.mag_plot = PlotWidget("Magnetic Field [mG]",
                             [["X", Qt.red, self.get_mag_x],
                              ["Y", Qt.darkGreen, self.get_mag_y],
                              ["Z", Qt.blue, self.get_mag_z]],
                                   self.clear_graphs)
        self.acc_plot = PlotWidget("Acceleration [mG]",
                             [["X", Qt.red, self.get_acc_x],
                              ["Y", Qt.darkGreen, self.get_acc_y],
                              ["Z", Qt.blue, self.get_acc_z]],
                                   self.clear_graphs)
        self.gyr_plot = PlotWidget("Angular Velocity [%c/s]" % 0xB0,
                             [["X", Qt.red, self.get_gyr_x],
                              ["Y", Qt.darkGreen, self.get_gyr_y],
                              ["Z", Qt.blue, self.get_gyr_z]],
                                   self.clear_graphs)
        
        self.tem_plot = PlotWidget("Temperature [%cC]" % 0xB0,
                             [["t", Qt.red, self.get_tem]],
                             self.clear_graphs)
        
        self.mag_plot.setMinimumSize(250, 200)
        self.acc_plot.setMinimumSize(250, 200)
        self.gyr_plot.setMinimumSize(250, 200)
        self.tem_plot.setMinimumSize(250, 200)
        
        
        self.orientation_label = QLabel("""Position your IMU Brick as shown \
in the image above, then press "Save Orientation".""")
        self.orientation_label.setWordWrap(True)
        self.orientation_label.setAlignment(Qt.AlignHCenter)
        self.gl_layout = QVBoxLayout()
        self.gl_layout.addWidget(self.imu_gl)
        self.gl_layout.addWidget(self.orientation_label)
        
        self.layout_top.addWidget(self.gyr_plot)
        self.layout_top.addWidget(self.acc_plot)
        self.layout_top.addWidget(self.mag_plot)
        self.layout_bottom.addLayout(self.gl_layout)
        self.layout_bottom.addWidget(self.tem_plot)
        
        self.save_orientation.clicked.connect(self.imu_gl.save_orientation)
#        self.clear_graphs.clicked.connect(self.clear_graphs_clicked)
        self.calibrate.clicked.connect(self.calibrate_pressed)
        self.led_button.clicked.connect(self.led_clicked)
        self.speed_spinbox.editingFinished.connect(self.speed_finished)
        
        self.calibrate = None
        self.alive = True
Beispiel #51
0
class IMU(PluginBase, Ui_IMU):
    def __init__(self, *args):
        PluginBase.__init__(self, BrickIMU, *args)

        self.setupUi(self)

        self.imu = self.device

        self.acc_x = 0
        self.acc_y = 0
        self.acc_z = 0
        self.mag_x = 0
        self.mag_y = 0
        self.mag_z = 0
        self.gyr_x = 0
        self.gyr_y = 0
        self.gyr_z = 0
        self.tem   = 0
        self.roll  = 0
        self.pitch = 0
        self.yaw   = 0
        self.qua_x = 0
        self.qua_y = 0
        self.qua_z = 0
        self.qua_w = 0

        self.old_time = 0

        self.update_timer = QTimer()
        self.update_timer.timeout.connect(self.update_data)

        self.cbe_all_data = CallbackEmulator(self.imu.get_all_data,
                                             self.all_data_callback,
                                             self.increase_error_count,
                                             use_data_signal=False)
        self.cbe_orientation = CallbackEmulator(self.imu.get_orientation,
                                                self.orientation_callback,
                                                self.increase_error_count,
                                                use_data_signal=False)
        self.cbe_quaternion = CallbackEmulator(self.imu.get_quaternion,
                                               self.quaternion_callback,
                                               self.increase_error_count,
                                               use_data_signal=False)

        # Import IMUGLWidget here, not global. If globally included we get
        # 'No OpenGL_accelerate module loaded: No module named OpenGL_accelerate'
        # as soon as IMU is set as device_class in __init__.
        # No idea why this happens, doesn't make sense.
        try:
            from .imu_gl_widget import IMUGLWidget
        except:
            from imu_gl_widget import IMUGLWidget

        self.imu_gl = IMUGLWidget(self)
        self.imu_gl.setMinimumSize(150, 150)
        self.imu_gl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.min_x = 0
        self.min_y = 0
        self.min_z = 0
        self.max_x = 0
        self.max_y = 0
        self.max_z = 0

        self.update_counter = 0

        self.mag_plot_widget = PlotWidget("Magnetic Field [mG]",
                                          [["X", Qt.red, self.get_mag_x],
                                           ["Y", Qt.darkGreen, self.get_mag_y],
                                           ["Z", Qt.blue, self.get_mag_z]],
                                          self.clear_graphs)
        self.acc_plot_widget = PlotWidget("Acceleration [mG]",
                                          [["X", Qt.red, self.get_acc_x],
                                           ["Y", Qt.darkGreen, self.get_acc_y],
                                           ["Z", Qt.blue, self.get_acc_z]],
                                          self.clear_graphs)
        self.gyr_plot_widget = PlotWidget("Angular Velocity [%c/s]" % 0xB0,
                                          [["X", Qt.red, self.get_gyr_x],
                                           ["Y", Qt.darkGreen, self.get_gyr_y],
                                           ["Z", Qt.blue, self.get_gyr_z]],
                                          self.clear_graphs)
        self.tem_plot_widget = PlotWidget("Temperature [%cC]" % 0xB0,
                                          [["t", Qt.red, self.get_tem]],
                                          self.clear_graphs)

        self.mag_plot_widget.setMinimumSize(250, 200)
        self.acc_plot_widget.setMinimumSize(250, 200)
        self.gyr_plot_widget.setMinimumSize(250, 200)
        self.tem_plot_widget.setMinimumSize(250, 200)

        self.orientation_label = QLabel("""Position your IMU Brick as shown \
in the image above, then press "Save Orientation".""")
        self.orientation_label.setWordWrap(True)
        self.orientation_label.setAlignment(Qt.AlignHCenter)
        self.gl_layout = QVBoxLayout()
        self.gl_layout.addWidget(self.imu_gl)
        self.gl_layout.addWidget(self.orientation_label)

        self.layout_top.addWidget(self.gyr_plot_widget)
        self.layout_top.addWidget(self.acc_plot_widget)
        self.layout_top.addWidget(self.mag_plot_widget)
        self.layout_bottom.addLayout(self.gl_layout)
        self.layout_bottom.addWidget(self.tem_plot_widget)

        self.save_orientation.clicked.connect(self.imu_gl.save_orientation)
        self.calibrate.clicked.connect(self.calibrate_clicked)
        self.led_button.clicked.connect(self.led_clicked)
        self.speed_spinbox.editingFinished.connect(self.speed_finished)

        self.calibrate = None
        self.alive = True

        if self.firmware_version >= (1, 0, 7):
            reset = QAction('Reset', self)
            reset.triggered.connect(lambda: self.imu.reset())
            self.set_actions(reset)

    def start(self):
        if not self.alive:
            return

        self.gl_layout.activate()
        self.cbe_all_data.set_period(100)
        self.cbe_orientation.set_period(100)
        self.cbe_quaternion.set_period(50)
        self.update_timer.start(50)

        async_call(self.imu.get_convergence_speed, None, self.speed_spinbox.setValue, self.increase_error_count)

        self.mag_plot_widget.stop = False
        self.acc_plot_widget.stop = False
        self.gyr_plot_widget.stop = False
        self.tem_plot_widget.stop = False

    def stop(self):
        self.mag_plot_widget.stop = True
        self.acc_plot_widget.stop = True
        self.gyr_plot_widget.stop = True
        self.tem_plot_widget.stop = True

        self.update_timer.stop()
        self.cbe_all_data.set_period(0)
        self.cbe_orientation.set_period(0)
        self.cbe_quaternion.set_period(0)

    def destroy(self):
        self.alive = False
        if self.calibrate:
            self.calibrate.close()

    def get_url_part(self):
        return 'imu'

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickIMU.DEVICE_IDENTIFIER

    def all_data_callback(self, data):
        acc_x, acc_y, acc_z, mag_x, mag_y, mag_z, gyr_x, gyr_y, gyr_z, tem = data
        self.acc_x = acc_x
        self.acc_y = acc_y
        self.acc_z = acc_z
        self.mag_x = mag_x
        self.mag_y = mag_y
        self.mag_z = mag_z
        self.gyr_x = gyr_x
        self.gyr_y = gyr_y
        self.gyr_z = gyr_z
        self.tem = tem

    def quaternion_callback(self, data):
        qua_x, qua_y, qua_z, qua_w = data
        self.qua_x = qua_x
        self.qua_y = qua_y
        self.qua_z = qua_z
        self.qua_w = qua_w

    def orientation_callback(self, data):
        roll, pitch, yaw = data
        self.roll = roll
        self.pitch = pitch
        self.yaw = yaw

    def led_clicked(self):
        if 'On' in self.led_button.text():
            self.led_button.setText('Turn LEDs Off')
            self.imu.leds_on()
        elif 'Off' in self.led_button.text():
            self.led_button.setText('Turn LEDs On')
            self.imu.leds_off()

    def get_acc_x(self):
        return self.acc_x

    def get_acc_y(self):
        return self.acc_y

    def get_acc_z(self):
        return self.acc_z

    def get_mag_x(self):
        return self.mag_x

    def get_mag_y(self):
        return self.mag_y

    def get_mag_z(self):
        return self.mag_z

    def get_gyr_x(self):
        return self.gyr_x/14.375

    def get_gyr_y(self):
        return self.gyr_y/14.375

    def get_gyr_z(self):
        return self.gyr_z/14.375

    def get_tem(self):
        return self.tem/100.0

    def update_data(self):
        self.update_counter += 1

        self.imu_gl.update(self.qua_x, self.qua_y, self.qua_z, self.qua_w)

        if self.update_counter % 2:
            gyr_x = self.gyr_x/14.375
            gyr_y = self.gyr_y/14.375
            gyr_z = self.gyr_z/14.375

            self.acceleration_update(self.acc_x, self.acc_y, self.acc_z)
            self.magnetometer_update(self.mag_x, self.mag_y, self.mag_z)
            self.gyroscope_update(gyr_x, gyr_y, gyr_z)
            self.orientation_update(self.roll, self.pitch, self.yaw)
            self.temperature_update(self.tem)

    def acceleration_update(self, x, y, z):
        x_str = "%g" % x
        y_str = "%g" % y
        z_str = "%g" % z
        self.acc_y_label.setText(y_str)
        self.acc_x_label.setText(x_str)
        self.acc_z_label.setText(z_str)

    def magnetometer_update(self, x, y, z):
        # Earth magnetic field. 0.5 Gauss
        x_str = "%g" % x
        y_str = "%g" % y
        z_str = "%g" % z
        self.mag_x_label.setText(x_str)
        self.mag_y_label.setText(y_str)
        self.mag_z_label.setText(z_str)

    def gyroscope_update(self, x, y, z):
        x_str = "%g" % int(x)
        y_str = "%g" % int(y)
        z_str = "%g" % int(z)
        self.gyr_x_label.setText(x_str)
        self.gyr_y_label.setText(y_str)
        self.gyr_z_label.setText(z_str)

    def orientation_update(self, r, p, y):
        r_str = "%g" % (r/100)
        p_str = "%g" % (p/100)
        y_str = "%g" % (y/100)
        self.roll_label.setText(r_str)
        self.pitch_label.setText(p_str)
        self.yaw_label.setText(y_str)

    def temperature_update(self, t):
        t_str = "%.2f" % (t/100.0)
        self.tem_label.setText(t_str)

    def calibrate_clicked(self):
        self.stop()
        if self.calibrate is None:
            self.calibrate = CalibrateWindow(self)

        self.calibrate.refresh_values()
        self.calibrate.show()

    def speed_finished(self):
        speed = self.speed_spinbox.value()
        self.imu.set_convergence_speed(speed)