Beispiel #1
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletOLED64x48, *args)

        self.setupUi(self)

        self.oled = self.device

        self.scribble_widget = ScribbleWidget(64,
                                              48,
                                              7,
                                              QColor(Qt.white),
                                              QColor(Qt.black),
                                              enable_grid=False)
        self.image_button_layout.insertWidget(0, self.scribble_widget)

        self.contrast_syncer = SliderSpinSyncer(
            self.contrast_slider,
            self.contrast_spin,
            lambda value: self.new_configuration(),
            spin_signal='valueChanged')
        self.char_syncer = SliderSpinSyncer(self.char_slider,
                                            self.char_spin,
                                            self.char_slider_changed,
                                            spin_signal='valueChanged')

        self.draw_button.clicked.connect(self.draw_clicked)
        self.clear_button.clicked.connect(self.clear_clicked)
        self.send_button.clicked.connect(self.send_clicked)
        self.clear_display_button.clicked.connect(self.clear_display_clicked)
        self.invert_checkbox.stateChanged.connect(self.new_configuration)

        self.current_char_value = -1
Beispiel #2
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletLCD128x64, *args)

        self.setupUi(self)

        self.lcd = self.device

        self.scribble_area = ScribbleArea(128, 64)
        self.image_button_layout.insertWidget(0, self.scribble_area)

        self.contrast_syncer = SliderSpinSyncer(
            self.contrast_slider, self.contrast_spin,
            lambda value: self.new_configuration())
        self.backlight_syncer = SliderSpinSyncer(
            self.backlight_slider, self.backlight_spin,
            lambda value: self.new_configuration())
        self.char_syncer = SliderSpinSyncer(self.char_slider, self.char_spin,
                                            self.char_slider_changed)

        self.draw_button.clicked.connect(self.draw_clicked)
        self.clear_button.clicked.connect(self.clear_clicked)
        self.send_button.clicked.connect(self.send_clicked)
        self.clear_display_button.clicked.connect(self.clear_display_clicked)
        self.invert_checkbox.stateChanged.connect(self.new_configuration)

        self.current_char_value = -1

        self.write_line_response_expected = False

        self.cbe_touch_position = CallbackEmulator(
            self.lcd.get_touch_position, self.scribble_area.touch_position,
            self.increase_error_count)
        self.cbe_touch_gesture = CallbackEmulator(
            self.lcd.get_touch_gesture, self.scribble_area.touch_gesture,
            self.increase_error_count)
Beispiel #3
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletIndustrialAnalogOut, *args)

        self.setupUi(self)

        self.ao = self.device

        self.voltage_syncer = SliderSpinSyncer(self.slider_voltage,
                                               self.spin_voltage,
                                               self.voltage_changed)

        self.current_syncer = SliderSpinSyncer(self.slider_current,
                                               self.spin_current,
                                               self.current_changed)

        self.radio_voltage.clicked.connect(self.radio_clicked)
        self.radio_current.clicked.connect(self.radio_clicked)

        self.box_voltage_range.currentIndexChanged.connect(self.config_changed)
        self.box_current_range.currentIndexChanged.connect(self.config_changed)

        self.checkbox_enable.clicked.connect(self.enable_changed)

        self.last_voltage = 0
        self.last_current = 4000
        self.last_voltage_range = 0
        self.last_current_range = 1

        self.new_voltage(self.last_voltage)
        self.new_current(self.last_current)
        self.mode_voltage()
Beispiel #4
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletOLED128x64V2, *args)

        self.setupUi(self)

        self.oled = self.device

        self.scribble_widget = ScribbleWidget(128,
                                              64,
                                              5,
                                              QColor(Qt.white),
                                              QColor(Qt.black),
                                              enable_grid=False)
        self.image_button_layout.insertWidget(0, self.scribble_widget)

        self.contrast_syncer = SliderSpinSyncer(
            self.contrast_slider, self.contrast_spin,
            lambda value: self.new_configuration())
        self.char_syncer = SliderSpinSyncer(self.char_slider, self.char_spin,
                                            self.char_slider_changed)

        self.draw_button.clicked.connect(self.draw_clicked)
        self.clear_button.clicked.connect(self.clear_clicked)
        self.send_button.clicked.connect(self.send_clicked)
        self.clear_display_button.clicked.connect(self.clear_display_clicked)
        self.invert_checkbox.stateChanged.connect(self.new_configuration)

        self.current_char_value = -1

        self.write_line_response_expected = None
Beispiel #5
0
    def __init__(self, *args):
        TNGPluginBase.__init__(self, TNGAO4U4IBindings, *args)

        self.setupUi(self)
        self.ao_4u_4i = self.device

        self.voltages = [
            SliderSpinSyncer(self.slider_voltage_ch0, self.spin_voltage_ch0,
                             self.value_changed),
            SliderSpinSyncer(self.slider_voltage_ch1, self.spin_voltage_ch1,
                             self.value_changed),
            SliderSpinSyncer(self.slider_voltage_ch2, self.spin_voltage_ch2,
                             self.value_changed),
            SliderSpinSyncer(self.slider_voltage_ch3, self.spin_voltage_ch3,
                             self.value_changed)
        ]

        self.currents = [
            SliderSpinSyncer(self.slider_current_ch0, self.spin_current_ch0,
                             self.value_changed),
            SliderSpinSyncer(self.slider_current_ch1, self.spin_current_ch1,
                             self.value_changed),
            SliderSpinSyncer(self.slider_current_ch2, self.spin_current_ch2,
                             self.value_changed),
            SliderSpinSyncer(self.slider_current_ch3, self.spin_current_ch3,
                             self.value_changed)
        ]
Beispiel #6
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletPiezoSpeakerV2, *args)

        self.setupUi(self)

        self.ps = self.device

        self.qtcb_beep_finished.connect(self.cb_beep)
        self.ps.register_callback(self.ps.CALLBACK_BEEP_FINISHED,
                                  self.qtcb_beep_finished.emit)
        self.qtcb_alarm_finished.connect(self.cb_alarm)
        self.ps.register_callback(self.ps.CALLBACK_ALARM_FINISHED,
                                  self.qtcb_alarm_finished.emit)

        self.frequency_syncer = SliderSpinSyncer(self.frequency_slider,
                                                 self.frequency_spinbox,
                                                 self.frequency_changed,
                                                 spin_signal='valueChanged')
        self.volume_syncer = SliderSpinSyncer(self.volume_slider,
                                              self.volume_spinbox,
                                              self.volume_changed,
                                              spin_signal='valueChanged')
        self.beep_duration_syncer = SliderSpinSyncer(
            self.beep_duration_slider,
            self.beep_duration_spinbox,
            self.beep_duration_changed,
            spin_signal='valueChanged')
        self.alarm_duration_syncer = SliderSpinSyncer(
            self.alarm_duration_slider,
            self.alarm_duration_spinbox,
            self.alarm_duration_changed,
            spin_signal='valueChanged')
        self.alarm_start_frequency_syncer = SliderSpinSyncer(
            self.alarm_start_frequency_slider,
            self.alarm_start_frequency_spinbox,
            self.alarm_start_frequency_changed,
            spin_signal='valueChanged')
        self.alarm_end_frequency_syncer = SliderSpinSyncer(
            self.alarm_end_frequency_slider,
            self.alarm_end_frequency_spinbox,
            self.alarm_end_frequency_changed,
            spin_signal='valueChanged')
        self.alarm_step_size_syncer = SliderSpinSyncer(
            self.alarm_step_size_slider,
            self.alarm_step_size_spinbox,
            self.alarm_step_size_changed,
            spin_signal='valueChanged')
        self.alarm_step_delay_syncer = SliderSpinSyncer(
            self.alarm_step_delay_slider,
            self.alarm_step_delay_spinbox,
            self.alarm_step_delay_changed,
            spin_signal='valueChanged')

        self.beep_button.clicked.connect(self.beep_clicked)
        self.alarm_button.clicked.connect(self.alarm_clicked)

        self.new_value_timer = QTimer(self)
        self.new_value_timer.timeout.connect(self.new_value_update)
        self.last_frequency = self.frequency_spinbox.value()
        self.last_volume = self.volume_spinbox.value()
Beispiel #7
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletPerformanceDC, *args)

        self.setupUi(self)

        self.dc = self.device

        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)
        self.radio_mode_brake.toggled.connect(self.brake_value_changed)
        self.radio_mode_coast.toggled.connect(self.coast_value_changed)

        self.gpio0_stop_rising_check.stateChanged.connect(
            lambda: self.gpio_action_changed(0))
        self.gpio0_stop_falling_check.stateChanged.connect(
            lambda: self.gpio_action_changed(0))
        self.gpio0_brake_rising_check.stateChanged.connect(
            lambda: self.gpio_action_changed(0))
        self.gpio0_brake_falling_check.stateChanged.connect(
            lambda: self.gpio_action_changed(0))
        self.gpio1_stop_rising_check.stateChanged.connect(
            lambda: self.gpio_action_changed(1))
        self.gpio1_stop_falling_check.stateChanged.connect(
            lambda: self.gpio_action_changed(1))
        self.gpio1_brake_rising_check.stateChanged.connect(
            lambda: self.gpio_action_changed(1))
        self.gpio1_brake_falling_check.stateChanged.connect(
            lambda: self.gpio_action_changed(1))
        self.gpio0_debounce_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(0))
        self.gpio0_stop_deceleration_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(0))
        self.gpio1_debounce_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(1))
        self.gpio1_stop_deceleration_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(1))

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)
        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.motion_changed)
        self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider,
                                                    self.deceleration_spin,
                                                    self.motion_changed)
        self.frequency_syncer = SliderSpinSyncer(self.frequency_slider,
                                                 self.frequency_spin,
                                                 self.frequency_changed)

        self.cbe_power_statistics = CallbackEmulator(
            self.dc.get_power_statistics, None,
            self.get_power_statistics_async, self.increase_error_count)
        self.cbe_current_velocity = CallbackEmulator(
            self.dc.get_current_velocity, None,
            self.get_current_velocity_async, self.increase_error_count)
        self.cbe_gpio_state = CallbackEmulator(self.dc.get_gpio_state, None,
                                               self.get_gpio_state_async,
                                               self.increase_error_count)
Beispiel #8
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletLCD128x64, *args)

        self.setupUi(self)

        self.lcd = self.device

        self.scribble_widget = TouchScribbleWidget(128,
                                                   64,
                                                   5,
                                                   QColor(Qt.black),
                                                   QColor(Qt.white),
                                                   enable_grid=False)
        self.image_button_layout.insertWidget(0, self.scribble_widget)

        self.contrast_syncer = SliderSpinSyncer(
            self.contrast_slider,
            self.contrast_spin,
            lambda value: self.new_configuration(),
            spin_signal='valueChanged')
        self.backlight_syncer = SliderSpinSyncer(
            self.backlight_slider,
            self.backlight_spin,
            lambda value: self.new_configuration(),
            spin_signal='valueChanged')
        self.char_syncer = SliderSpinSyncer(self.char_slider,
                                            self.char_spin,
                                            self.char_slider_changed,
                                            spin_signal='valueChanged')

        self.draw_button.clicked.connect(self.draw_clicked)
        self.clear_button.clicked.connect(self.clear_clicked)
        self.send_button.clicked.connect(self.send_clicked)
        self.clear_display_button.clicked.connect(self.clear_display_clicked)
        self.invert_checkbox.stateChanged.connect(self.new_configuration)

        self.current_char_value = -1
        self.write_line_response_expected = None

        self.cbe_touch_position = CallbackEmulator(
            self, self.lcd.get_touch_position, None,
            self.scribble_widget.touch_position, self.increase_error_count)
        self.cbe_touch_gesture = CallbackEmulator(
            self, self.lcd.get_touch_gesture, None,
            self.scribble_widget.touch_gesture, self.increase_error_count)
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletIndustrialAnalogOutV2, *args)

        self.setupUi(self)

        self.ao = self.device

        self.voltage_syncer = SliderSpinSyncer(self.slider_voltage,
                                               self.spin_voltage,
                                               self.voltage_changed)

        self.current_syncer = SliderSpinSyncer(self.slider_current,
                                               self.spin_current,
                                               self.current_changed)

        self.radio_voltage.clicked.connect(self.radio_clicked)
        self.radio_current.clicked.connect(self.radio_clicked)

        self.box_voltage_range.currentIndexChanged.connect(self.config_changed)
        self.box_current_range.currentIndexChanged.connect(self.config_changed)

        self.checkbox_enable.clicked.connect(self.enable_changed)

        self.cbox_osl_lc.currentIndexChanged.connect(self.cbox_osl_lc_changed)
        self.cbox_osl_lsc.currentIndexChanged.connect(
            self.cbox_osl_lsc_changed)
        self.sbox_osl_min.valueChanged.connect(self.sbox_osl_min_changed)
        self.sbox_osl_max.valueChanged.connect(self.sbox_osl_max_changed)

        self.ui_grp_show_ch_status = [
            self.cbox_osl_lsc, self.sbox_osl_min, self.sbox_osl_max
        ]

        self.box_voltage_range.setCurrentIndex(1)
        self.box_current_range.setCurrentIndex(0)

        self.new_voltage(0)
        self.new_current(0)
        self.mode_voltage()
Beispiel #10
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletOLED128x64, *args)

        self.setupUi(self)

        self.oled = self.device

        self.scribble_area = ScribbleArea(128, 64)
        self.image_button_layout.insertWidget(0, self.scribble_area)

        self.contrast_syncer = SliderSpinSyncer(
            self.contrast_slider, self.contrast_spin,
            lambda value: self.new_configuration())
        self.char_syncer = SliderSpinSyncer(self.char_slider, self.char_spin,
                                            self.char_slider_changed)

        self.draw_button.clicked.connect(self.draw_clicked)
        self.clear_button.clicked.connect(self.clear_clicked)
        self.send_button.clicked.connect(self.send_clicked)
        self.clear_display_button.clicked.connect(self.clear_display_clicked)
        self.invert_checkbox.stateChanged.connect(self.new_configuration)

        self.current_char_value = -1
Beispiel #11
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletRGBLEDV2, *args)

        self.rgb_led = self.device

        self.changing = False
        self.set_rgb_value_response_expected = None

        self.setupUi(self)

        self.r_syncer = SliderSpinSyncer(self.slider_r,
                                         self.spin_r,
                                         self.rgb_changed,
                                         spin_signal='valueChanged')
        self.g_syncer = SliderSpinSyncer(self.slider_g,
                                         self.spin_g,
                                         self.rgb_changed,
                                         spin_signal='valueChanged')
        self.b_syncer = SliderSpinSyncer(self.slider_b,
                                         self.spin_b,
                                         self.rgb_changed,
                                         spin_signal='valueChanged')

        self.h_syncer = SliderSpinSyncer(self.slider_h,
                                         self.spin_h,
                                         self.hsl_changed,
                                         spin_signal='valueChanged')
        self.s_syncer = SliderSpinSyncer(self.slider_s,
                                         self.spin_s,
                                         self.hsl_changed,
                                         spin_signal='valueChanged')
        self.l_syncer = SliderSpinSyncer(self.slider_l,
                                         self.spin_l,
                                         self.hsl_changed,
                                         spin_signal='valueChanged')

        def set_color(r, g, b):
            self.changing = True
            self.spin_r.setValue(r)
            self.spin_g.setValue(g)
            self.spin_b.setValue(b)
            self.changing = False
            self.rgb_changed()

        for color, button in zip(
            [(0, 0, 0), (255, 255, 255), (255, 0, 0), (255, 255, 0),
             (0, 255, 0), (0, 255, 255), (0, 0, 255), (255, 0, 255)], [
                 self.button_black, self.button_white, self.button_red,
                 self.button_yellow, self.button_green, self.button_cyan,
                 self.button_blue, self.button_magenta
             ]):
            button.clicked.connect(lambda clicked, c=color: set_color(*c))
            pixmap = QPixmap(16, 16)
            QPainter(pixmap).fillRect(0, 0, 16, 16, QColor(*color))
            button.setIcon(QIcon(pixmap))
            button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
Beispiel #12
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletRGBLEDButton, *args)

        self.rgb_led_button = self.device

        self.changing = False

        self.setupUi(self)

        self.qtcb_button_state_changed.connect(self.cb_button_state_changed)
        self.rgb_led_button.register_callback(
            self.rgb_led_button.CALLBACK_BUTTON_STATE_CHANGED,
            self.qtcb_button_state_changed.emit)

        self.r_syncer = SliderSpinSyncer(self.slider_r,
                                         self.spin_r,
                                         self.rgb_changed,
                                         spin_signal='valueChanged')
        self.g_syncer = SliderSpinSyncer(self.slider_g,
                                         self.spin_g,
                                         self.rgb_changed,
                                         spin_signal='valueChanged')
        self.b_syncer = SliderSpinSyncer(self.slider_b,
                                         self.spin_b,
                                         self.rgb_changed,
                                         spin_signal='valueChanged')

        self.h_syncer = SliderSpinSyncer(self.slider_h,
                                         self.spin_h,
                                         self.hsl_changed,
                                         spin_signal='valueChanged')
        self.s_syncer = SliderSpinSyncer(self.slider_s,
                                         self.spin_s,
                                         self.hsl_changed,
                                         spin_signal='valueChanged')
        self.l_syncer = SliderSpinSyncer(self.slider_l,
                                         self.spin_l,
                                         self.hsl_changed,
                                         spin_signal='valueChanged')

        def set_color(r, g, b):
            self.changing = True
            self.spin_r.setValue(r)
            self.spin_g.setValue(g)
            self.spin_b.setValue(b)
            self.changing = False
            self.rgb_changed()

        self.button_black.clicked.connect(lambda: set_color(0, 0, 0))
        self.button_white.clicked.connect(lambda: set_color(255, 255, 255))
        self.button_red.clicked.connect(lambda: set_color(255, 0, 0))
        self.button_yellow.clicked.connect(lambda: set_color(255, 255, 0))
        self.button_green.clicked.connect(lambda: set_color(0, 255, 0))
        self.button_cyan.clicked.connect(lambda: set_color(0, 255, 255))
        self.button_blue.clicked.connect(lambda: set_color(0, 0, 255))
        self.button_magenta.clicked.connect(lambda: set_color(255, 0, 255))
Beispiel #13
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletRGBLED, *args)

        self.rgb_led = self.device

        self.changing = False

        self.setupUi(self)

        self.r_syncer = SliderSpinSyncer(self.slider_r,
                                         self.spin_r,
                                         self.rgb_changed,
                                         spin_signal='valueChanged')
        self.g_syncer = SliderSpinSyncer(self.slider_g,
                                         self.spin_g,
                                         self.rgb_changed,
                                         spin_signal='valueChanged')
        self.b_syncer = SliderSpinSyncer(self.slider_b,
                                         self.spin_b,
                                         self.rgb_changed,
                                         spin_signal='valueChanged')

        self.h_syncer = SliderSpinSyncer(self.slider_h,
                                         self.spin_h,
                                         self.hsl_changed,
                                         spin_signal='valueChanged')
        self.s_syncer = SliderSpinSyncer(self.slider_s,
                                         self.spin_s,
                                         self.hsl_changed,
                                         spin_signal='valueChanged')
        self.l_syncer = SliderSpinSyncer(self.slider_l,
                                         self.spin_l,
                                         self.hsl_changed,
                                         spin_signal='valueChanged')

        def set_color(r, g, b):
            self.changing = True
            self.spin_r.setValue(r)
            self.spin_g.setValue(g)
            self.spin_b.setValue(b)
            self.changing = False
            self.rgb_changed()

        self.button_black.clicked.connect(lambda: set_color(0, 0, 0))
        self.button_white.clicked.connect(lambda: set_color(255, 255, 255))
        self.button_red.clicked.connect(lambda: set_color(255, 0, 0))
        self.button_yellow.clicked.connect(lambda: set_color(255, 255, 0))
        self.button_green.clicked.connect(lambda: set_color(0, 255, 0))
        self.button_cyan.clicked.connect(lambda: set_color(0, 255, 255))
        self.button_blue.clicked.connect(lambda: set_color(0, 0, 255))
        self.button_magenta.clicked.connect(lambda: set_color(255, 0, 255))
Beispiel #14
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletDCV2, *args)

        self.setupUi(self)

        self.dc = self.device

        self.qem = QErrorMessage(self)
        self.qtcb_emergency_shutdown.connect(self.cb_emergency_shutdown)
        self.dc.register_callback(self.dc.CALLBACK_EMERGENCY_SHUTDOWN,
                                  self.qtcb_emergency_shutdown.emit)

        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)
        self.radio_mode_brake.toggled.connect(self.brake_value_changed)
        self.radio_mode_coast.toggled.connect(self.coast_value_changed)

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)
        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.motion_changed)
        self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider,
                                                    self.deceleration_spin,
                                                    self.motion_changed)
        self.frequency_syncer = SliderSpinSyncer(self.frequency_slider,
                                                 self.frequency_spin,
                                                 self.frequency_changed)

        self.cbe_power_statistics = CallbackEmulator(
            self, self.dc.get_power_statistics, None,
            self.get_power_statistics_async, self.increase_error_count)
        self.cbe_current_velocity = CallbackEmulator(
            self, self.dc.get_current_velocity, None,
            self.get_current_velocity_async, self.increase_error_count)
Beispiel #15
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickDC, *args)

        self.setupUi(self)

        self.dc = 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.encoder_hide_all()

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

        self.new_value = 0
        self.update_counter = 0

        self.full_brake_time = 0

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)

        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.acceleration_changed)

        self.frequency_syncer = SliderSpinSyncer(self.frequency_slider,
                                                 self.frequency_spin,
                                                 self.frequency_changed)

        self.radio_mode_brake.toggled.connect(self.brake_value_changed)
        self.radio_mode_coast.toggled.connect(self.coast_value_changed)

        self.minimum_voltage_button.clicked.connect(
            self.minimum_voltage_button_clicked)
        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)

        self.emergency_signal = None
        self.under_signal = None
        self.current_velocity_signal = None
        self.velocity_reached_signal = None

        self.qem = QErrorMessage(self)

        self.qtcb_under_voltage.connect(self.cb_under_voltage)
        self.dc.register_callback(self.dc.CALLBACK_UNDER_VOLTAGE,
                                  self.qtcb_under_voltage.emit)

        self.qtcb_emergency_shutdown.connect(self.cb_emergency_shutdown)
        self.dc.register_callback(self.dc.CALLBACK_EMERGENCY_SHUTDOWN,
                                  self.qtcb_emergency_shutdown.emit)

        self.qtcb_velocity_reached.connect(self.update_velocity)
        self.dc.register_callback(self.dc.CALLBACK_VELOCITY_REACHED,
                                  self.qtcb_velocity_reached.emit)

        self.cbe_current_velocity = CallbackEmulator(
            self.dc.get_current_velocity, None, self.update_velocity,
            self.increase_error_count)

        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.dc.enable_status_led()
                if checked else self.dc.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(lambda: self.dc.reset())
        self.set_actions([(0, None, [reset])])
Beispiel #16
0
class DC(PluginBase, Ui_DC):
    qtcb_velocity_reached = pyqtSignal(int)
    qtcb_under_voltage = pyqtSignal(int)
    qtcb_emergency_shutdown = pyqtSignal()

    def __init__(self, *args):
        PluginBase.__init__(self, BrickDC, *args)

        self.setupUi(self)

        self.dc = 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.encoder_hide_all()

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

        self.new_value = 0
        self.update_counter = 0

        self.full_brake_time = 0

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)

        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.acceleration_changed)

        self.frequency_syncer = SliderSpinSyncer(self.frequency_slider,
                                                 self.frequency_spin,
                                                 self.frequency_changed)

        self.radio_mode_brake.toggled.connect(self.brake_value_changed)
        self.radio_mode_coast.toggled.connect(self.coast_value_changed)

        self.minimum_voltage_button.clicked.connect(
            self.minimum_voltage_button_clicked)
        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)

        self.emergency_signal = None
        self.under_signal = None
        self.current_velocity_signal = None
        self.velocity_reached_signal = None

        self.qem = QErrorMessage(self)

        self.qtcb_under_voltage.connect(self.cb_under_voltage)
        self.dc.register_callback(self.dc.CALLBACK_UNDER_VOLTAGE,
                                  self.qtcb_under_voltage.emit)

        self.qtcb_emergency_shutdown.connect(self.cb_emergency_shutdown)
        self.dc.register_callback(self.dc.CALLBACK_EMERGENCY_SHUTDOWN,
                                  self.qtcb_emergency_shutdown.emit)

        self.qtcb_velocity_reached.connect(self.update_velocity)
        self.dc.register_callback(self.dc.CALLBACK_VELOCITY_REACHED,
                                  self.qtcb_velocity_reached.emit)

        self.cbe_current_velocity = CallbackEmulator(
            self.dc.get_current_velocity, None, self.update_velocity,
            self.increase_error_count)

        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.dc.enable_status_led()
                if checked else self.dc.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(lambda: self.dc.reset())
        self.set_actions([(0, None, [reset])])

    def start(self):
        if self.has_status_led:
            async_call(self.dc.is_status_led_enabled, None,
                       self.status_led_action.setChecked,
                       self.increase_error_count)

        self.update_timer.start(1000)
        self.cbe_current_velocity.set_period(100)
        self.update_start()
        self.update_data()

    def stop(self):
        self.update_timer.stop()
        self.cbe_current_velocity.set_period(0)

    def destroy(self):
        pass

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

    def cb_emergency_shutdown(self):
        if not self.qem.isVisible():
            self.qem.setWindowTitle("Emergency Shutdown")
            self.qem.showMessage(
                "Emergency Shutdown: Short-Circuit or Over-Temperature")

    def cb_under_voltage(self, ov):
        mv_str = self.minimum_voltage_label.text()
        ov_str = "%gV" % round(ov / 1000.0, 1)
        if not self.qem.isVisible():
            self.qem.setWindowTitle("Under Voltage")
            self.qem.showMessage(
                "Under Voltage: Output Voltage of " + ov_str +
                " is below minimum voltage of " + mv_str, "DC_UnderVoltage")

    def encoder_hide_all(self):
        self.enable_encoder_checkbox.hide()
        self.encoder_hide()

    def encoder_hide(self):
        self.p_label.hide()
        self.p_spinbox.hide()
        self.i_label.hide()
        self.i_spinbox.hide()
        self.d_label.hide()
        self.d_spinbox.hide()
        self.st_label.hide()
        self.st_spinbox.hide()
        self.cpr_label.hide()
        self.cpr_spinbox.hide()
        self.encoder_spacer.hide()

    def encoder_show(self):
        self.p_label.show()
        self.p_spinbox.show()
        self.i_label.show()
        self.i_spinbox.show()
        self.d_label.show()
        self.d_spinbox.show()
        self.st_label.show()
        self.st_spinbox.show()
        self.cpr_label.show()
        self.cpr_spinbox.show()
        self.encoder_spacer.show()

    def enable_encoder_state_changed(self, state):
        try:
            if state == Qt.Checked:
                self.dc.enable_encoder()
                self.update_encoder()
            elif state == Qt.Unchecked:
                self.dc.disable_encoder()

        except ip_connection.Error:
            return

    def enable_state_changed(self, state):
        try:
            if state == Qt.Checked:
                self.dc.enable()
            elif state == Qt.Unchecked:
                self.dc.disable()
        except ip_connection.Error:
            return

    def brake_value_changed(self, checked):
        if checked:
            try:
                self.dc.set_drive_mode(0)
            except ip_connection.Error:
                return

    def coast_value_changed(self, checked):
        if checked:
            try:
                self.dc.set_drive_mode(1)
            except ip_connection.Error:
                return

    def full_brake_clicked(self):
        try:
            self.dc.full_brake()
        except ip_connection.Error:
            return

    def minimum_voltage_selected(self, value):
        try:
            self.dc.set_minimum_voltage(value)
        except ip_connection.Error:
            return

    def minimum_voltage_button_clicked(self):
        qid = QInputDialog(self)
        qid.setInputMode(QInputDialog.IntInput)
        qid.setIntMinimum(5000)
        qid.setIntMaximum(0xFFFF)
        qid.setIntStep(100)
        async_call(self.dc.get_minimum_voltage, None, qid.setIntValue,
                   self.increase_error_count)
        qid.intValueSelected.connect(self.minimum_voltage_selected)
        qid.setLabelText("Choose minimum motor voltage in mV.")
        qid.open()

    def stack_input_voltage_update(self, sv):
        sv_str = "%gV" % round(sv / 1000.0, 1)
        self.stack_voltage_label.setText(sv_str)

    def external_input_voltage_update(self, ev):
        ev_str = "%gV" % round(ev / 1000.0, 1)
        self.external_voltage_label.setText(ev_str)

    def minimum_voltage_update(self, mv):
        mv_str = "%gV" % round(mv / 1000.0, 1)
        self.minimum_voltage_label.setText(mv_str)

    def drive_mode_update(self, dm):
        if dm == 0:
            self.radio_mode_brake.setChecked(True)
            self.radio_mode_coast.setChecked(False)
        else:
            self.radio_mode_brake.setChecked(False)
            self.radio_mode_coast.setChecked(True)

    def current_consumption_update(self, cc):
        if cc >= 1000:
            cc_str = "%gA" % round(cc / 1000.0, 1)
        else:
            cc_str = "%gmA" % cc

        self.current_label.setText(cc_str)

    def update_velocity(self, velocity):
        self.speedometer.set_velocity(velocity)
        self.current_velocity_label.setText('{0} ({1}%)'.format(
            velocity, round(abs(velocity) * 100 / 32768.0, 1)))

    def get_velocity_async(self, velocity):
        self.velocity_syncer.set_value(velocity)

        self.update_velocity(velocity)

    def get_acceleration_async(self, acceleration):
        self.acceleration_syncer.set_value(acceleration)

    def get_pwm_frequency_async(self, frequency):
        self.frequency_syncer.set_value(frequency)

    def is_enabled_async(self, enabled):
        self.enable_checkbox.setChecked(enabled)

    def is_encoder_enabled_async(self, enabled):
        self.enable_encoder_checkbox.setChecked(enabled)

    def get_encoder_config_async(self, cpr):
        self.cpr_spinbox.setValue(cpr)

    def get_encoder_pid_config_async(self, pid_config):
        self.p_spinbox.setValue(pid_config.p)
        self.i_spinbox.setValue(pid_config.i)
        self.d_spinbox.setValue(pid_config.d)
        self.st_spinbox.setValue(pid_config.sample_time)

    def update_encoder(self):
        async_call(self.dc.get_encoder_config, None,
                   self.get_encoder_config_async, self.increase_error_count)
        async_call(self.dc.get_encoder_pid_config, None,
                   self.get_encoder_pid_config_async,
                   self.increase_error_count)
        async_call(self.dc.is_encoder_enabled, None,
                   self.is_encoder_enabled_async, self.increase_error_count)

    def update_start(self):
        async_call(self.dc.get_drive_mode, None, self.drive_mode_update,
                   self.increase_error_count)
        async_call(self.dc.get_velocity, None, self.get_velocity_async,
                   self.increase_error_count)
        async_call(self.dc.get_acceleration, None, self.get_acceleration_async,
                   self.increase_error_count)
        async_call(self.dc.get_pwm_frequency, None,
                   self.get_pwm_frequency_async, self.increase_error_count)
        async_call(self.dc.is_enabled, None, self.is_enabled_async,
                   self.increase_error_count)

    def update_data(self):
        async_call(self.dc.get_stack_input_voltage, None,
                   self.stack_input_voltage_update, self.increase_error_count)
        async_call(self.dc.get_external_input_voltage, None,
                   self.external_input_voltage_update,
                   self.increase_error_count)
        async_call(self.dc.get_minimum_voltage, None,
                   self.minimum_voltage_update, self.increase_error_count)
        async_call(self.dc.get_current_consumption, None,
                   self.current_consumption_update, self.increase_error_count)

    def acceleration_changed(self, value):
        try:
            self.dc.set_acceleration(value)
        except ip_connection.Error:
            return

    def velocity_changed(self, value):
        try:
            self.dc.set_velocity(value)
        except ip_connection.Error:
            return

    def frequency_changed(self, value):
        try:
            self.dc.set_pwm_frequency(value)
        except ip_connection.Error:
            return
Beispiel #17
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickServo, *args)

        self.setupUi(self)

        self.servo = 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.position_list = []
        self.velocity_list = []
        self.acceleration_list = []
        self.enable_list = []

        self.up_cur = 0
        self.up_siv = 0
        self.up_eiv = 0
        self.up_opv = 0
        self.up_mv = 0

        self.up_ena = [0] * 7
        self.up_pos = [0] * 7
        self.up_vel = [0] * 7
        self.up_acc = [0] * 7

        self.update_timer = QTimer(self)
        self.update_timer.timeout.connect(self.update_apply)
        self.update_timer.setInterval(50)

        self.alive = True

        for i in range(1, 8):
            label = QLabel()
            label.setText('Off')
            self.enable_list.append(label)
            self.status_grid.addWidget(label, i, 1)

        for i in range(1, 8):
            pk = PositionKnob()
            self.position_list.append(pk)
            self.status_grid.addWidget(pk, i, 2)

        for i in range(1, 8):
            cb = ColorBar(Qt.Vertical)
            self.velocity_list.append(cb)
            self.status_grid.addWidget(cb, i, 3)

        for i in range(1, 8):
            cb = ColorBar(Qt.Vertical)
            self.acceleration_list.append(cb)
            self.status_grid.addWidget(cb, i, 4)

        self.qem = QErrorMessage(self)
        self.qem.setWindowTitle("Under Voltage")

        self.test_button.clicked.connect(self.test_button_clicked)
        self.output_voltage_button.clicked.connect(
            self.output_voltage_button_clicked)

        self.servo_dropbox.currentIndexChanged.connect(
            lambda x: self.update_servo_specific())
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)

        self.position_syncer = SliderSpinSyncer(self.position_slider,
                                                self.position_spin,
                                                self.position_changed)

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)

        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.acceleration_changed)

        self.period_syncer = SliderSpinSyncer(self.period_slider,
                                              self.period_spin,
                                              self.period_changed)

        self.pulse_width_min_spin.editingFinished.connect(
            self.pulse_width_spin_finished)
        self.pulse_width_max_spin.editingFinished.connect(
            self.pulse_width_spin_finished)
        self.degree_min_spin.editingFinished.connect(self.degree_spin_finished)
        self.degree_max_spin.editingFinished.connect(self.degree_spin_finished)

        self.minimum_voltage_button.clicked.connect(
            self.minimum_voltage_button_clicked)

        self.qtcb_under_voltage.connect(self.cb_under_voltage)
        self.servo.register_callback(self.servo.CALLBACK_UNDER_VOLTAGE,
                                     self.qtcb_under_voltage.emit)

        class WorkerThread(QThread):
            def __init__(self, parent=None, func=None):
                super().__init__(parent)
                self.func = func

            def run(self):
                self.func()

        self.test_event = Event()
        self.test_thread_object = WorkerThread(self, self.test_thread)
        self.update_event = Event()
        self.update_thread_object = WorkerThread(self, self.update_thread)

        self.update_thread_first_time = False

        self.update_done_event = Event()
        self.update_done_event.set()

        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.servo.enable_status_led()
                if checked else self.servo.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(lambda: self.servo.reset())
        self.set_actions([(0, None, [reset])])
Beispiel #18
0
class DCV2(COMCUPluginBase, Ui_DCV2):
    qtcb_emergency_shutdown = pyqtSignal()

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

        self.setupUi(self)

        self.dc = self.device

        self.qem = QErrorMessage(self)
        self.qtcb_emergency_shutdown.connect(self.cb_emergency_shutdown)
        self.dc.register_callback(self.dc.CALLBACK_EMERGENCY_SHUTDOWN,
                                  self.qtcb_emergency_shutdown.emit)

        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)
        self.radio_mode_brake.toggled.connect(self.brake_value_changed)
        self.radio_mode_coast.toggled.connect(self.coast_value_changed)

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)
        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.motion_changed)
        self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider,
                                                    self.deceleration_spin,
                                                    self.motion_changed)
        self.frequency_syncer = SliderSpinSyncer(self.frequency_slider,
                                                 self.frequency_spin,
                                                 self.frequency_changed)

        self.cbe_power_statistics = CallbackEmulator(
            self, self.dc.get_power_statistics, None,
            self.get_power_statistics_async, self.increase_error_count)
        self.cbe_current_velocity = CallbackEmulator(
            self, self.dc.get_current_velocity, None,
            self.get_current_velocity_async, self.increase_error_count)

    def start(self):
        async_call(self.dc.get_drive_mode, None, self.get_drive_mode_async,
                   self.increase_error_count)
        async_call(self.dc.get_velocity, None, self.get_velocity_async,
                   self.increase_error_count)
        async_call(self.dc.get_motion, None, self.get_motion_async,
                   self.increase_error_count)
        async_call(self.dc.get_pwm_frequency, None,
                   self.get_pwm_frequency_async, self.increase_error_count)
        async_call(self.dc.get_enabled, None, self.get_enabled_async,
                   self.increase_error_count)

        self.cbe_power_statistics.set_period(100)
        self.cbe_current_velocity.set_period(50)

    def stop(self):
        self.cbe_power_statistics.set_period(0)
        self.cbe_current_velocity.set_period(0)

    def destroy(self):
        pass

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

    def cb_emergency_shutdown(self):
        # Refresh enabled checkbox in case of emergency shutdown
        async_call(self.dc.get_enabled, None, self.get_enabled_async,
                   self.increase_error_count)

        if not self.qem.isVisible():
            self.qem.setWindowTitle("Emergency Shutdown")
            self.qem.showMessage(
                "Emergency Shutdown: Short-Circuit or Over-Temperature or Under-Voltage"
            )

    def brake_value_changed(self, checked):
        if checked:
            try:
                self.dc.set_drive_mode(0)
            except ip_connection.Error:
                return

    def coast_value_changed(self, checked):
        if checked:
            try:
                self.dc.set_drive_mode(1)
            except ip_connection.Error:
                return

    def full_brake_clicked(self):
        try:
            self.dc.full_brake()
            self.velocity_syncer.set_value(0)
        except ip_connection.Error:
            return

    def get_drive_mode_async(self, dm):
        if dm == 0:
            self.radio_mode_brake.setChecked(True)
            self.radio_mode_coast.setChecked(False)
        else:
            self.radio_mode_brake.setChecked(False)
            self.radio_mode_coast.setChecked(True)

    def get_power_statistics_async(self, ps):
        if ps.current >= 1000:
            current_str = "{0}A".format(round(ps.current / 1000.0, 1))
        else:
            current_str = "{0}mA".format(ps.current)

        if ps.voltage >= 1000:
            voltage_str = "{0}V".format(round(ps.voltage / 1000.0, 1))
        else:
            voltage_str = "{0}mV".format(ps.voltage)

        self.current_label.setText(current_str)
        self.input_voltage_label.setText(voltage_str)

    def get_current_velocity_async(self, velocity):
        self.speedometer.set_velocity(velocity)
        self.current_velocity_label.setText('{0} ({1}%)'.format(
            velocity, round(abs(velocity) * 100 / 32768.0, 1)))

    def get_velocity_async(self, velocity):
        self.velocity_syncer.set_value(velocity)

    def get_motion_async(self, motion):
        self.acceleration_syncer.set_value(motion.acceleration)
        self.deceleration_syncer.set_value(motion.deceleration)

    def get_pwm_frequency_async(self, frequency):
        self.frequency_syncer.set_value(frequency)

    def get_enabled_async(self, enabled):
        self.enable_checkbox.setChecked(enabled)

    def enable_state_changed(self, state):
        try:
            self.dc.set_enabled(state == Qt.Checked)
        except ip_connection.Error:
            return

    def motion_changed(self, _):
        acceleration = self.acceleration_spin.value()
        deceleration = self.deceleration_spin.value()
        try:
            self.dc.set_motion(acceleration, deceleration)
        except ip_connection.Error:
            return

    def velocity_changed(self, value):
        try:
            self.dc.set_velocity(value)
        except ip_connection.Error:
            return

    def frequency_changed(self, value):
        try:
            self.dc.set_pwm_frequency(value)
        except ip_connection.Error:
            return
Beispiel #19
0
class PerformanceDC(COMCUPluginBase, Ui_PerformanceDC):
    qtcb_emergency_shutdown = pyqtSignal()

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

        self.setupUi(self)

        self.dc = self.device

        self.qem = QErrorMessage(self)
        self.qtcb_emergency_shutdown.connect(self.cb_emergency_shutdown)
        self.dc.register_callback(self.dc.CALLBACK_EMERGENCY_SHUTDOWN,
                                  self.qtcb_emergency_shutdown.emit)

        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)
        self.radio_mode_brake.toggled.connect(self.brake_value_changed)
        self.radio_mode_coast.toggled.connect(self.coast_value_changed)

        self.gpio0_rising_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(0))
        self.gpio0_falling_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(0))
        self.gpio1_rising_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(1))
        self.gpio1_falling_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(1))
        self.gpio0_debounce_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(0))
        self.gpio0_stop_deceleration_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(0))
        self.gpio1_debounce_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(1))
        self.gpio1_stop_deceleration_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(1))

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)
        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.motion_changed)
        self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider,
                                                    self.deceleration_spin,
                                                    self.motion_changed)
        self.frequency_syncer = SliderSpinSyncer(self.frequency_slider,
                                                 self.frequency_spin,
                                                 self.frequency_changed)

        self.cbe_power_statistics = CallbackEmulator(
            self, self.dc.get_power_statistics, None,
            self.get_power_statistics_async, self.increase_error_count)
        self.cbe_current_velocity = CallbackEmulator(
            self, self.dc.get_current_velocity, None,
            self.get_current_velocity_async, self.increase_error_count)
        self.cbe_gpio_state = CallbackEmulator(self, self.dc.get_gpio_state,
                                               None, self.get_gpio_state_async,
                                               self.increase_error_count)

        self.error_led_off_action = QAction('Off', self)
        self.error_led_off_action.triggered.connect(
            lambda: self.dc.set_error_led_config(BrickletPerformanceDC.
                                                 ERROR_LED_CONFIG_OFF))
        self.error_led_on_action = QAction('On', self)
        self.error_led_on_action.triggered.connect(
            lambda: self.dc.set_error_led_config(BrickletPerformanceDC.
                                                 ERROR_LED_CONFIG_ON))
        self.error_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.error_led_show_heartbeat_action.triggered.connect(
            lambda: self.dc.set_error_led_config(
                BrickletPerformanceDC.ERROR_LED_CONFIG_SHOW_HEARTBEAT))
        self.error_led_show_error_action = QAction('Show Error', self)
        self.error_led_show_error_action.triggered.connect(
            lambda: self.dc.set_error_led_config(BrickletPerformanceDC.
                                                 ERROR_LED_CONFIG_SHOW_ERROR))

        self.extra_configs += [(1, 'Error LED:', [
            self.error_led_off_action, self.error_led_on_action,
            self.error_led_show_heartbeat_action,
            self.error_led_show_error_action
        ])]

        self.cw_led_off_action = QAction('Off', self)
        self.cw_led_off_action.triggered.connect(
            lambda: self.dc.set_cw_led_config(BrickletPerformanceDC.
                                              CW_LED_CONFIG_OFF))
        self.cw_led_on_action = QAction('On', self)
        self.cw_led_on_action.triggered.connect(
            lambda: self.dc.set_cw_led_config(BrickletPerformanceDC.
                                              CW_LED_CONFIG_ON))
        self.cw_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.cw_led_show_heartbeat_action.triggered.connect(
            lambda: self.dc.set_cw_led_config(BrickletPerformanceDC.
                                              CW_LED_CONFIG_SHOW_HEARTBEAT))
        self.cw_led_show_cw_as_forward_action = QAction(
            'Show CW As Forward', self)
        self.cw_led_show_cw_as_forward_action.triggered.connect(
            lambda: self.dc.set_cw_led_config(
                BrickletPerformanceDC.CW_LED_CONFIG_SHOW_CW_AS_FORWARD))
        self.cw_led_show_cw_as_backward_action = QAction(
            'Show CW As Backward', self)
        self.cw_led_show_cw_as_backward_action.triggered.connect(
            lambda: self.dc.set_cw_led_config(
                BrickletPerformanceDC.CW_LED_CONFIG_SHOW_CW_AS_BACKWARD))

        self.extra_configs += [(2, 'CW LED:', [
            self.cw_led_off_action, self.cw_led_on_action,
            self.cw_led_show_heartbeat_action,
            self.cw_led_show_cw_as_forward_action,
            self.cw_led_show_cw_as_backward_action
        ])]

        self.ccw_led_off_action = QAction('Off', self)
        self.ccw_led_off_action.triggered.connect(
            lambda: self.dc.set_ccw_led_config(BrickletPerformanceDC.
                                               CCW_LED_CONFIG_OFF))
        self.ccw_led_on_action = QAction('On', self)
        self.ccw_led_on_action.triggered.connect(
            lambda: self.dc.set_ccw_led_config(BrickletPerformanceDC.
                                               CCW_LED_CONFIG_ON))
        self.ccw_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.ccw_led_show_heartbeat_action.triggered.connect(
            lambda: self.dc.set_ccw_led_config(BrickletPerformanceDC.
                                               CCW_LED_CONFIG_SHOW_HEARTBEAT))
        self.ccw_led_show_ccw_as_forward_action = QAction(
            'Show CCW As Forward', self)
        self.ccw_led_show_ccw_as_forward_action.triggered.connect(
            lambda: self.dc.set_ccw_led_config(
                BrickletPerformanceDC.CCW_LED_CONFIG_SHOW_CCW_AS_FORWARD))
        self.ccw_led_show_ccw_as_backward_action = QAction(
            'Show CCW As Backward', self)
        self.ccw_led_show_ccw_as_backward_action.triggered.connect(
            lambda: self.dc.set_ccw_led_config(
                BrickletPerformanceDC.CCW_LED_CONFIG_SHOW_CCW_AS_BACKWARD))

        self.extra_configs += [(2, 'CCW LED:', [
            self.ccw_led_off_action, self.ccw_led_on_action,
            self.ccw_led_show_heartbeat_action,
            self.ccw_led_show_ccw_as_forward_action,
            self.ccw_led_show_ccw_as_backward_action
        ])]

        self.gpio0_led_off_action = QAction('Off', self)
        self.gpio0_led_off_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                0, BrickletPerformanceDC.GPIO_LED_CONFIG_OFF))
        self.gpio0_led_on_action = QAction('On', self)
        self.gpio0_led_on_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                0, BrickletPerformanceDC.GPIO_LED_CONFIG_ON))
        self.gpio0_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.gpio0_led_show_heartbeat_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                0, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_HEARTBEAT))
        self.gpio0_led_show_show_gpio_active_high_action = QAction(
            'Show GPIO Active High', self)
        self.gpio0_led_show_show_gpio_active_high_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                0, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_HIGH
            ))
        self.gpio0_led_show_show_gpio_active_low_action = QAction(
            'Show GPIO Active Low', self)
        self.gpio0_led_show_show_gpio_active_low_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                0, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_LOW))

        self.extra_configs += [(3, 'GPIO0 LED:', [
            self.gpio0_led_off_action, self.gpio0_led_on_action,
            self.gpio0_led_show_heartbeat_action,
            self.gpio0_led_show_show_gpio_active_high_action,
            self.gpio0_led_show_show_gpio_active_low_action
        ])]

        self.gpio1_led_off_action = QAction('Off', self)
        self.gpio1_led_off_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                1, BrickletPerformanceDC.GPIO_LED_CONFIG_OFF))
        self.gpio1_led_on_action = QAction('On', self)
        self.gpio1_led_on_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                1, BrickletPerformanceDC.GPIO_LED_CONFIG_ON))
        self.gpio1_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.gpio1_led_show_heartbeat_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                1, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_HEARTBEAT))
        self.gpio1_led_show_show_gpio_active_high_action = QAction(
            'Show GPIO Active High', self)
        self.gpio1_led_show_show_gpio_active_high_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                1, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_HIGH
            ))
        self.gpio1_led_show_show_gpio_active_low_action = QAction(
            'Show GPIO Active Low', self)
        self.gpio1_led_show_show_gpio_active_low_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                1, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_LOW))

        self.extra_configs += [(3, 'GPIO1 LED:', [
            self.gpio1_led_off_action, self.gpio1_led_on_action,
            self.gpio1_led_show_heartbeat_action,
            self.gpio1_led_show_show_gpio_active_high_action,
            self.gpio1_led_show_show_gpio_active_low_action
        ])]

    def start(self):
        async_call(self.dc.get_drive_mode, None, self.get_drive_mode_async,
                   self.increase_error_count)
        async_call(self.dc.get_velocity, None, self.get_velocity_async,
                   self.increase_error_count)
        async_call(self.dc.get_motion, None, self.get_motion_async,
                   self.increase_error_count)
        async_call(self.dc.get_pwm_frequency, None,
                   self.get_pwm_frequency_async, self.increase_error_count)
        async_call(self.dc.get_enabled, None, self.get_enabled_async,
                   self.increase_error_count)

        async_call(self.dc.get_gpio_configuration, 0,
                   lambda x: self.get_gpio_configuration_async(0, x),
                   self.increase_error_count)
        async_call(self.dc.get_gpio_configuration, 1,
                   lambda x: self.get_gpio_configuration_async(1, x),
                   self.increase_error_count)
        async_call(self.dc.get_gpio_action, 0,
                   lambda x: self.get_gpio_action_async(0, x),
                   self.increase_error_count)
        async_call(self.dc.get_gpio_action, 1,
                   lambda x: self.get_gpio_action_async(1, x),
                   self.increase_error_count)

        async_call(self.dc.get_error_led_config, None,
                   self.get_error_led_config_async, self.increase_error_count)
        async_call(self.dc.get_cw_led_config, None,
                   self.get_cw_led_config_async, self.increase_error_count)
        async_call(self.dc.get_ccw_led_config, None,
                   self.get_ccw_led_config_async, self.increase_error_count)
        async_call(self.dc.get_gpio_led_config, 0,
                   self.get_gpio0_led_config_async, self.increase_error_count)
        async_call(self.dc.get_gpio_led_config, 1,
                   self.get_gpio1_led_config_async, self.increase_error_count)

        self.cbe_gpio_state.set_period(200)
        self.cbe_power_statistics.set_period(100)
        self.cbe_current_velocity.set_period(50)

    def stop(self):
        self.cbe_gpio_state.set_period(0)
        self.cbe_power_statistics.set_period(0)
        self.cbe_current_velocity.set_period(0)

    def destroy(self):
        pass

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

    def get_error_led_config_async(self, config):
        if config == BrickletPerformanceDC.ERROR_LED_CONFIG_OFF:
            self.error_led_off_action.trigger()
        elif config == BrickletPerformanceDC.ERROR_LED_CONFIG_ON:
            self.error_led_on_action.trigger()
        elif config == BrickletPerformanceDC.ERROR_LED_CONFIG_SHOW_HEARTBEAT:
            self.error_led_show_heartbeat_action.trigger()
        elif config == BrickletPerformanceDC.ERROR_LED_CONFIG_SHOW_ERROR:
            self.error_led_show_error_action.trigger()

    def get_cw_led_config_async(self, config):
        if config == BrickletPerformanceDC.CW_LED_CONFIG_OFF:
            self.cw_led_off_action.trigger()
        elif config == BrickletPerformanceDC.CW_LED_CONFIG_ON:
            self.cw_led_on_action.trigger()
        elif config == BrickletPerformanceDC.CW_LED_CONFIG_SHOW_HEARTBEAT:
            self.cw_led_show_heartbeat_action.trigger()
        elif config == BrickletPerformanceDC.CW_LED_CONFIG_SHOW_CW_AS_FORWARD:
            self.cw_led_show_cw_as_forward_action.trigger()
        elif config == BrickletPerformanceDC.CW_LED_CONFIG_SHOW_CW_AS_BACKWARD:
            self.cw_led_show_cw_as_backward_action.trigger()

    def get_ccw_led_config_async(self, config):
        if config == BrickletPerformanceDC.CCW_LED_CONFIG_OFF:
            self.ccw_led_off_action.trigger()
        elif config == BrickletPerformanceDC.CCW_LED_CONFIG_ON:
            self.ccw_led_on_action.trigger()
        elif config == BrickletPerformanceDC.CCW_LED_CONFIG_SHOW_HEARTBEAT:
            self.ccw_led_show_heartbeat_action.trigger()
        elif config == BrickletPerformanceDC.CCW_LED_CONFIG_SHOW_CCW_AS_FORWARD:
            self.ccw_led_show_ccw_as_forward_action.trigger()
        elif config == BrickletPerformanceDC.CCW_LED_CONFIG_SHOW_CCW_AS_BACKWARD:
            self.ccw_led_show_ccw_as_backward_action.trigger()

    def get_gpio0_led_config_async(self, config):
        if config == BrickletPerformanceDC.GPIO_LED_CONFIG_OFF:
            self.gpio0_led_off_action.trigger()
        elif config == BrickletPerformanceDC.GPIO_LED_CONFIG_ON:
            self.gpio0_led_on_action.trigger()
        elif config == BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_HEARTBEAT:
            self.gpio0_led_show_heartbeat_action.trigger()
        elif config == BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_HIGH:
            self.gpio0_led_show_show_gpio_active_high_action.trigger()
        elif config == BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_LOW:
            self.gpio0_led_show_show_gpio_active_low_action.trigger()

    def get_gpio1_led_config_async(self, config):
        if config == BrickletPerformanceDC.GPIO_LED_CONFIG_OFF:
            self.gpio1_led_off_action.trigger()
        elif config == BrickletPerformanceDC.GPIO_LED_CONFIG_ON:
            self.gpio1_led_on_action.trigger()
        elif config == BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_HEARTBEAT:
            self.gpio1_led_show_heartbeat_action.trigger()
        elif config == BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_HIGH:
            self.gpio1_led_show_show_gpio_active_high_action.trigger()
        elif config == BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_LOW:
            self.gpio1_led_show_show_gpio_active_low_action.trigger()

    def cb_emergency_shutdown(self):
        # Refresh enabled checkbox in case of emergency shutdown
        async_call(self.dc.get_enabled, None, self.get_enabled_async,
                   self.increase_error_count)

        if not self.qem.isVisible():
            self.qem.setWindowTitle("Emergency Shutdown")
            self.qem.showMessage(
                "Emergency Shutdown: Short-Circuit or Over-Temperature or Under-Voltage"
            )

    def brake_value_changed(self, checked):
        if checked:
            try:
                self.dc.set_drive_mode(0)
            except ip_connection.Error:
                return

    def coast_value_changed(self, checked):
        if checked:
            try:
                self.dc.set_drive_mode(1)
            except ip_connection.Error:
                return

    def full_brake_clicked(self):
        try:
            self.dc.full_brake()
            self.velocity_syncer.set_value(0)
        except ip_connection.Error:
            return

    def get_drive_mode_async(self, dm):
        if dm == 0:
            self.radio_mode_brake.setChecked(True)
            self.radio_mode_coast.setChecked(False)
        else:
            self.radio_mode_brake.setChecked(False)
            self.radio_mode_coast.setChecked(True)

    def get_power_statistics_async(self, ps):
        if ps.current >= 1000:
            current_str = "{0}A".format(round(ps.current / 1000.0, 1))
        else:
            current_str = "{0}mA".format(ps.current)

        if ps.voltage >= 1000:
            voltage_str = "{0}V".format(round(ps.voltage / 1000.0, 1))
        else:
            voltage_str = "{0}mV".format(ps.voltage)

        temperature_str = "{0}°C".format(round(ps.temperature / 10.0, 1))

        self.current_label.setText(current_str)
        self.input_voltage_label.setText(voltage_str)
        self.temperature_label.setText(temperature_str)

    def get_current_velocity_async(self, velocity):
        self.speedometer.set_velocity(velocity)
        self.current_velocity_label.setText('{0} ({1}%)'.format(
            velocity, round(abs(velocity) * 100 / 32768.0, 1)))

    def get_velocity_async(self, velocity):
        self.velocity_syncer.set_value(velocity)

    def get_motion_async(self, motion):
        self.acceleration_syncer.set_value(motion.acceleration)
        self.deceleration_syncer.set_value(motion.deceleration)

    def get_pwm_frequency_async(self, frequency):
        self.frequency_syncer.set_value(frequency)

    def get_enabled_async(self, enabled):
        self.enable_checkbox.setChecked(enabled)

    def get_gpio_configuration_async(self, channel, conf):
        if channel == 0:
            self.gpio0_debounce_spin.setValue(conf.debounce)
            self.gpio0_stop_deceleration_spin.setValue(conf.stop_deceleration)
        elif channel == 1:
            self.gpio1_debounce_spin.setValue(conf.debounce)
            self.gpio1_stop_deceleration_spin.setValue(conf.stop_deceleration)

    def get_gpio_action_async(self, channel, action):
        if channel == 0:
            if action & self.dc.GPIO_ACTION_FULL_BRAKE_RISING_EDGE:  # full brake has higher priority
                self.gpio0_rising_combo.setCurrentIndex(2)
            elif action & self.dc.GPIO_ACTION_NORMAL_STOP_RISING_EDGE:
                self.gpio0_rising_combo.setCurrentIndex(1)
            else:
                self.gpio0_rising_combo.setCurrentIndex(0)

            if action & self.dc.GPIO_ACTION_FULL_BRAKE_FALLING_EDGE:  # full brake has higher priority
                self.gpio0_falling_combo.setCurrentIndex(2)
            elif action & self.dc.GPIO_ACTION_NORMAL_STOP_FALLING_EDGE:
                self.gpio0_falling_combo.setCurrentIndex(1)
            else:
                self.gpio0_falling_combo.setCurrentIndex(0)
        elif channel == 1:
            if action & self.dc.GPIO_ACTION_FULL_BRAKE_RISING_EDGE:  # full brake has higher priority
                self.gpio1_rising_combo.setCurrentIndex(2)
            elif action & self.dc.GPIO_ACTION_NORMAL_STOP_RISING_EDGE:
                self.gpio1_rising_combo.setCurrentIndex(1)
            else:
                self.gpio1_rising_combo.setCurrentIndex(0)

            if action & self.dc.GPIO_ACTION_FULL_BRAKE_FALLING_EDGE:  # full brake has higher priority
                self.gpio1_falling_combo.setCurrentIndex(2)
            elif action & self.dc.GPIO_ACTION_NORMAL_STOP_FALLING_EDGE:
                self.gpio1_falling_combo.setCurrentIndex(1)
            else:
                self.gpio1_falling_combo.setCurrentIndex(0)

    def get_gpio_state_async(self, state):
        if state[0]:
            self.gpio0_state_label.setText('High')
        else:
            self.gpio0_state_label.setText('Low')

        if state[1]:
            self.gpio1_state_label.setText('High')
        else:
            self.gpio1_state_label.setText('Low')

    def enable_state_changed(self, state):
        try:
            self.dc.set_enabled(state == Qt.Checked)
        except ip_connection.Error:
            return

    def motion_changed(self, _):
        acceleration = self.acceleration_spin.value()
        deceleration = self.deceleration_spin.value()
        try:
            self.dc.set_motion(acceleration, deceleration)
        except ip_connection.Error:
            return

    def velocity_changed(self, value):
        try:
            self.dc.set_velocity(value)
        except ip_connection.Error:
            return

    def frequency_changed(self, value):
        try:
            self.dc.set_pwm_frequency(value)
        except ip_connection.Error:
            return

    def gpio_action_changed(self, channel):
        async_call(self.dc.get_gpio_action, channel,
                   lambda x: self.gpio_action_changed_step2(channel, x),
                   self.increase_error_count)

    def gpio_action_changed_step2(self, channel, action):
        action &= self.dc.GPIO_ACTION_CALLBACK_RISING_EDGE | self.dc.GPIO_ACTION_CALLBACK_FALLING_EDGE

        if channel == 0:
            rising = self.gpio0_rising_combo.currentIndex()
            falling = self.gpio0_falling_combo.currentIndex()
        elif channel == 1:
            rising = self.gpio1_rising_combo.currentIndex()
            falling = self.gpio1_falling_combo.currentIndex()
        else:
            return  # unreachable

        if rising == 1: action |= self.dc.GPIO_ACTION_NORMAL_STOP_RISING_EDGE
        if falling == 1: action |= self.dc.GPIO_ACTION_NORMAL_STOP_FALLING_EDGE
        if rising == 2: action |= self.dc.GPIO_ACTION_FULL_BRAKE_RISING_EDGE
        if falling == 2: action |= self.dc.GPIO_ACTION_FULL_BRAKE_FALLING_EDGE

        self.dc.set_gpio_action(channel, action)

    def gpio_configuration_changed(self, channel):
        if channel == 0:
            debounce = self.gpio0_debounce_spin.value()
            stop_deceleration = self.gpio0_stop_deceleration_spin.value()
        elif channel == 1:
            debounce = self.gpio1_debounce_spin.value()
            stop_deceleration = self.gpio1_stop_deceleration_spin.value()

        self.dc.set_gpio_configuration(channel, debounce, stop_deceleration)
Beispiel #20
0
class PerformanceDC(COMCUPluginBase, Ui_PerformanceDC):
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletPerformanceDC, *args)

        self.setupUi(self)

        self.dc = self.device

        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)
        self.radio_mode_brake.toggled.connect(self.brake_value_changed)
        self.radio_mode_coast.toggled.connect(self.coast_value_changed)

        self.gpio0_stop_rising_check.stateChanged.connect(
            lambda: self.gpio_action_changed(0))
        self.gpio0_stop_falling_check.stateChanged.connect(
            lambda: self.gpio_action_changed(0))
        self.gpio0_brake_rising_check.stateChanged.connect(
            lambda: self.gpio_action_changed(0))
        self.gpio0_brake_falling_check.stateChanged.connect(
            lambda: self.gpio_action_changed(0))
        self.gpio1_stop_rising_check.stateChanged.connect(
            lambda: self.gpio_action_changed(1))
        self.gpio1_stop_falling_check.stateChanged.connect(
            lambda: self.gpio_action_changed(1))
        self.gpio1_brake_rising_check.stateChanged.connect(
            lambda: self.gpio_action_changed(1))
        self.gpio1_brake_falling_check.stateChanged.connect(
            lambda: self.gpio_action_changed(1))
        self.gpio0_debounce_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(0))
        self.gpio0_stop_deceleration_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(0))
        self.gpio1_debounce_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(1))
        self.gpio1_stop_deceleration_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(1))

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)
        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.motion_changed)
        self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider,
                                                    self.deceleration_spin,
                                                    self.motion_changed)
        self.frequency_syncer = SliderSpinSyncer(self.frequency_slider,
                                                 self.frequency_spin,
                                                 self.frequency_changed)

        self.cbe_power_statistics = CallbackEmulator(
            self.dc.get_power_statistics, None,
            self.get_power_statistics_async, self.increase_error_count)
        self.cbe_current_velocity = CallbackEmulator(
            self.dc.get_current_velocity, None,
            self.get_current_velocity_async, self.increase_error_count)
        self.cbe_gpio_state = CallbackEmulator(self.dc.get_gpio_state, None,
                                               self.get_gpio_state_async,
                                               self.increase_error_count)

    def start(self):
        async_call(self.dc.get_drive_mode, None, self.get_drive_mode_async,
                   self.increase_error_count)
        async_call(self.dc.get_velocity, None, self.get_velocity_async,
                   self.increase_error_count)
        async_call(self.dc.get_motion, None, self.get_motion_async,
                   self.increase_error_count)
        async_call(self.dc.get_pwm_frequency, None,
                   self.get_pwm_frequency_async, self.increase_error_count)
        async_call(self.dc.get_enabled, None, self.get_enabled_async,
                   self.increase_error_count)

        async_call(self.dc.get_gpio_configuration, 0,
                   lambda x: self.get_gpio_configuration_async(0, x),
                   self.increase_error_count)
        async_call(self.dc.get_gpio_configuration, 1,
                   lambda x: self.get_gpio_configuration_async(1, x),
                   self.increase_error_count)
        async_call(self.dc.get_gpio_action, 0,
                   lambda x: self.get_gpio_action_async(0, x),
                   self.increase_error_count)
        async_call(self.dc.get_gpio_action, 1,
                   lambda x: self.get_gpio_action_async(1, x),
                   self.increase_error_count)

        self.cbe_gpio_state.set_period(200)
        self.cbe_power_statistics.set_period(100)
        self.cbe_current_velocity.set_period(50)

    def stop(self):
        self.cbe_gpio_state.set_period(0)
        self.cbe_power_statistics.set_period(0)
        self.cbe_current_velocity.set_period(0)

    def destroy(self):
        pass

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

    def brake_value_changed(self, checked):
        if checked:
            try:
                self.dc.set_drive_mode(0)
            except ip_connection.Error:
                return

    def coast_value_changed(self, checked):
        if checked:
            try:
                self.dc.set_drive_mode(1)
            except ip_connection.Error:
                return

    def full_brake_clicked(self):
        try:
            self.dc.full_brake()
            self.velocity_syncer.set_value(0)
        except ip_connection.Error:
            return

    def get_drive_mode_async(self, dm):
        if dm == 0:
            self.radio_mode_brake.setChecked(True)
            self.radio_mode_coast.setChecked(False)
        else:
            self.radio_mode_brake.setChecked(False)
            self.radio_mode_coast.setChecked(True)

    def get_power_statistics_async(self, ps):
        if ps.current >= 1000:
            current_str = "{0}A".format(round(ps.current / 1000.0, 1))
        else:
            current_str = "{0}mA".format(ps.current)

        if ps.voltage >= 1000:
            voltage_str = "{0}V".format(round(ps.voltage / 1000.0, 1))
        else:
            voltage_str = "{0}mV".format(ps.voltage)

        temperature_str = "{0}°C".format(round(ps.temperature / 10.0, 1))

        self.current_label.setText(current_str)
        self.input_voltage_label.setText(voltage_str)
        self.temperature_label.setText(temperature_str)

    def get_current_velocity_async(self, velocity):
        self.speedometer.set_velocity(velocity)
        self.current_velocity_label.setText('{0} ({1}%)'.format(
            velocity, round(abs(velocity) * 100 / 32768.0, 1)))

    def get_velocity_async(self, velocity):
        self.velocity_syncer.set_value(velocity)

    def get_motion_async(self, motion):
        self.acceleration_syncer.set_value(motion.acceleration)
        self.deceleration_syncer.set_value(motion.deceleration)

    def get_pwm_frequency_async(self, frequency):
        self.frequency_syncer.set_value(frequency)

    def get_enabled_async(self, enabled):
        self.enable_checkbox.setChecked(enabled)

    def get_gpio_configuration_async(self, channel, conf):
        if channel == 0:
            self.gpio0_debounce_spin.setValue(conf.debounce)
            self.gpio0_stop_deceleration_spin.setValue(conf.stop_deceleration)
        elif channel == 1:
            self.gpio1_debounce_spin.setValue(conf.debounce)
            self.gpio1_stop_deceleration_spin.setValue(conf.stop_deceleration)

    def get_gpio_action_async(self, channel, action):
        if channel == 0:
            self.gpio0_stop_rising_check.setChecked(
                (action & self.dc.GPIO_ACTION_NORMAL_STOP_RISING_EDGE) != 0)
            self.gpio0_stop_falling_check.setChecked(
                (action & self.dc.GPIO_ACTION_NORMAL_STOP_FALLING_EDGE) != 0)
            self.gpio0_brake_rising_check.setChecked(
                (action & self.dc.GPIO_ACTION_FULL_BRAKE_RISING_EDGE) != 0)
            self.gpio0_brake_falling_check.setChecked(
                (action & self.dc.GPIO_ACTION_FULL_BRAKE_FALLING_EDGE) != 0)
        elif channel == 1:
            self.gpio1_stop_rising_check.setChecked(
                (action & self.dc.GPIO_ACTION_NORMAL_STOP_RISING_EDGE) != 0)
            self.gpio1_stop_falling_check.setChecked(
                (action & self.dc.GPIO_ACTION_NORMAL_STOP_FALLING_EDGE) != 0)
            self.gpio1_brake_rising_check.setChecked(
                (action & self.dc.GPIO_ACTION_FULL_BRAKE_RISING_EDGE) != 0)
            self.gpio1_brake_falling_check.setChecked(
                (action & self.dc.GPIO_ACTION_FULL_BRAKE_FALLING_EDGE) != 0)

    def get_gpio_state_async(self, state):
        if state[0]:
            self.gpio0_state_label.setText('High')
        else:
            self.gpio0_state_label.setText('Low')

        if state[1]:
            self.gpio1_state_label.setText('High')
        else:
            self.gpio1_state_label.setText('Low')

    def enable_state_changed(self, state):
        try:
            self.dc.set_enabled(state == Qt.Checked)
        except ip_connection.Error:
            return

    def motion_changed(self, _):
        acceleration = self.acceleration_spin.value()
        deceleration = self.deceleration_spin.value()
        try:
            self.dc.set_motion(acceleration, deceleration)
        except ip_connection.Error:
            return

    def velocity_changed(self, value):
        try:
            self.dc.set_velocity(value)
        except ip_connection.Error:
            return

    def frequency_changed(self, value):
        try:
            self.dc.set_pwm_frequency(value)
        except ip_connection.Error:
            return

    def gpio_action_changed(self, channel):
        action = 0
        if channel == 0:
            if self.gpio0_stop_rising_check.isChecked():
                action = action | self.dc.GPIO_ACTION_NORMAL_STOP_RISING_EDGE
            if self.gpio0_stop_falling_check.isChecked():
                action = action | self.dc.GPIO_ACTION_NORMAL_STOP_FALLING_EDGE
            if self.gpio0_brake_rising_check.isChecked():
                action = action | self.dc.GPIO_ACTION_FULL_BRAKE_RISING_EDGE
            if self.gpio0_brake_falling_check.isChecked():
                action = action | self.dc.GPIO_ACTION_FULL_BRAKE_FALLING_EDGE
        elif channel == 1:
            if self.gpio1_stop_rising_check.isChecked():
                action = action | self.dc.GPIO_ACTION_NORMAL_STOP_RISING_EDGE
            if self.gpio1_stop_falling_check.isChecked():
                action = action | self.dc.GPIO_ACTION_NORMAL_STOP_FALLING_EDGE
            if self.gpio1_brake_rising_check.isChecked():
                action = action | self.dc.GPIO_ACTION_FULL_BRAKE_RISING_EDGE
            if self.gpio1_brake_falling_check.isChecked():
                action = action | self.dc.GPIO_ACTION_FULL_BRAKE_FALLING_EDGE

        # TODO: Retain callback configuration
        self.dc.set_gpio_action(channel, action)

    def gpio_configuration_changed(self, channel):
        if channel == 0:
            debounce = self.gpio0_debounce_spin.value()
            stop_deceleration = self.gpio0_stop_deceleration_spin.value()
        elif channel == 1:
            debounce = self.gpio1_debounce_spin.value()
            stop_deceleration = self.gpio1_stop_deceleration_spin.value()

        self.dc.set_gpio_configuration(channel, debounce, stop_deceleration)
Beispiel #21
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletMotionDetectorV2, *args)

        self.motion_detector_v2 = self.device

        self.changing = False

        self.setupUi(self)

        self.qtcb_motion_detected.connect(self.cb_motion_detected)
        self.motion_detector_v2.register_callback(
            self.motion_detector_v2.CALLBACK_MOTION_DETECTED,
            self.qtcb_motion_detected.emit)

        self.qtcb_detection_cylce_ended.connect(self.cb_detection_cycle_ended)
        self.motion_detector_v2.register_callback(
            self.motion_detector_v2.CALLBACK_DETECTION_CYCLE_ENDED,
            self.qtcb_detection_cylce_ended.emit)

        self.left_syncer = SliderSpinSyncer(self.slider_left,
                                            self.spin_left,
                                            self.indicator_changed,
                                            spin_signal='valueChanged')
        self.right_syncer = SliderSpinSyncer(self.slider_right,
                                             self.spin_right,
                                             self.indicator_changed,
                                             spin_signal='valueChanged')
        self.bottom_syncer = SliderSpinSyncer(self.slider_bottom,
                                              self.spin_bottom,
                                              self.indicator_changed,
                                              spin_signal='valueChanged')

        self.all_syncer = SliderSpinSyncer(self.slider_all,
                                           self.spin_all,
                                           self.all_changed,
                                           spin_signal='valueChanged')

        self.sensitivity_syncer = SliderSpinSyncer(self.slider_sensitivity,
                                                   self.spin_sensitivity,
                                                   self.sensitivity_changed,
                                                   spin_signal='valueChanged')

        def set_indicator(l, r, b):
            self.changing = True
            self.spin_left.setValue(l)
            self.spin_right.setValue(r)
            self.spin_bottom.setValue(b)
            self.changing = False
            self.indicator_changed()

        self.button_off.clicked.connect(lambda: set_indicator(0, 0, 0))
        self.button_on.clicked.connect(lambda: set_indicator(255, 255, 255))
        self.button_left.clicked.connect(lambda: set_indicator(255, 0, 0))
        self.button_right.clicked.connect(lambda: set_indicator(0, 255, 0))
        self.button_bottom.clicked.connect(lambda: set_indicator(0, 0, 255))

        self.indicator_update = False
        self.indicator_value = [0, 0, 0]
        self.sensitivity_update = False
        self.sensitivity_value = 50

        self.update_timer = QTimer()
        self.update_timer.timeout.connect(self.update)
        self.update_timer.setInterval(50)
        self.update_timer.start()
Beispiel #22
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletSilentStepperV2, *args)

        self.setupUi(self)

        self.silent_stepper_v2 = self.device

        self.endis_all(False)

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

        self.speedometer = SpeedoMeter()
        self.vertical_layout_right.insertWidget(5, self.speedometer)

        self.new_value = 0
        self.update_counter = 0

        self.full_brake_time = 0

        self.qem = QErrorMessage(self)
        self.qem.setWindowTitle("Under Voltage")

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)

        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.acceleration_changed)

        self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider,
                                                    self.deceleration_spin,
                                                    self.deceleration_changed)

        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)
        self.forward_button.clicked.connect(self.forward_clicked)
        self.stop_button.clicked.connect(self.stop_clicked)
        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.backward_button.clicked.connect(self.backward_clicked)
        self.to_button.clicked.connect(self.to_button_clicked)
        self.steps_button.clicked.connect(self.steps_button_clicked)
        self.motor_current_button.clicked.connect(
            self.motor_current_button_clicked)
        self.minimum_motor_voltage_button.clicked.connect(
            self.minimum_motor_voltage_button_clicked)

        self.qtcb_position_reached.connect(self.cb_position_reached)
        self.silent_stepper_v2.register_callback(
            self.silent_stepper_v2.CALLBACK_POSITION_REACHED,
            self.qtcb_position_reached.emit)

        self.qtcb_under_voltage.connect(self.cb_under_voltage)
        self.silent_stepper_v2.register_callback(
            self.silent_stepper_v2.CALLBACK_UNDER_VOLTAGE,
            self.qtcb_under_voltage.emit)

        # Step Configuration
        self.step_resolution_dropbox.currentIndexChanged.connect(
            self.step_configuration_changed)
        self.interpolate_checkbox.stateChanged.connect(
            self.step_configuration_changed)

        # Basic Configuration
        self.standstill_current_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.motor_run_current_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.standstill_delay_time_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.power_down_time_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.stealth_threshold_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.coolstep_threashold_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.classic_threshold_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.high_velocity_chopper_mode_checkbox.stateChanged.connect(
            self.basic_configuration_changed)

        # Spreadcycle Configuration
        self.slow_decay_duration_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.enable_random_slow_decay_checkbox.stateChanged.connect(
            self.spreadcycle_configuration_changed)
        self.fast_decay_duration_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.hysteresis_start_value_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.hysteresis_end_value_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.sine_wave_offset_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.chopper_mode_combo.currentIndexChanged.connect(
            self.spreadcycle_configuration_changed)
        self.comparator_blank_time_combo.currentIndexChanged.connect(
            self.spreadcycle_configuration_changed)
        self.fast_decay_without_comparator_checkbox.stateChanged.connect(
            self.spreadcycle_configuration_changed)

        # Stealth Configuration
        self.enable_stealth_checkbox.stateChanged.connect(
            self.stealth_configuration_changed)
        self.amplitude_spin.valueChanged.connect(
            self.stealth_configuration_changed)
        self.gradient_spin.valueChanged.connect(
            self.stealth_configuration_changed)
        self.enable_autoscale_checkbox.stateChanged.connect(
            self.stealth_configuration_changed)
        self.force_symmetric_checkbox.stateChanged.connect(
            self.stealth_configuration_changed)
        self.freewheel_mode_combo.currentIndexChanged.connect(
            self.stealth_configuration_changed)

        # Coolstep Configuration
        self.minimum_stallguard_value_spin.valueChanged.connect(
            self.coolstep_configuration_changed)
        self.maximum_stallguard_value_spin.valueChanged.connect(
            self.coolstep_configuration_changed)
        self.current_up_step_width_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)
        self.current_down_step_width_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)
        self.minimum_current_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)
        self.stallguard_threshold_value_spin.valueChanged.connect(
            self.coolstep_configuration_changed)
        self.stallguard_mode_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)

        # Misc Configuration
        self.disable_short_to_ground_protection_checkbox.stateChanged.connect(
            self.misc_configuration_changed)
        self.synchronize_phase_frequency_spin.valueChanged.connect(
            self.misc_configuration_changed)

        self.gpio0_rising_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(0))
        self.gpio0_falling_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(0))
        self.gpio1_rising_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(1))
        self.gpio1_falling_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(1))
        self.gpio0_debounce_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(0))
        self.gpio0_stop_deceleration_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(0))
        self.gpio1_debounce_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(1))
        self.gpio1_stop_deceleration_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(1))

        self.ste = 0
        self.pos = 0
        self.current_velocity = 0
        self.cur = 0
        self.sv = 0
        self.ev = 0
        self.mv = 0
        self.mod = 0
Beispiel #23
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletServoV2, *args)

        self.setupUi(self)

        self.servo = self.device

        self.cbe_status = CallbackEmulator(self,
                                           self.servo.get_status,
                                           None,
                                           self.cb_status,
                                           self.increase_error_count)

        self.position_list = []
        self.velocity_list = []
        self.current_list = []
        self.enable_list = []

        self.up_cur = 0
        self.up_siv = 0
        self.up_eiv = 0
        self.up_opv = 0
        self.up_mv = 0

        self.up_ena = [0]*10
        self.up_pos = [0]*10
        self.up_vel = [0]*10
        self.up_acc = [0]*10

        self.alive = True

        for i in range(1, 11):
            label = QLabel()
            label.setText('Off')
            self.enable_list.append(label)
            self.status_grid.addWidget(label, i, 1)

        for i in range(1, 11):
            pk = PositionKnob()
            self.position_list.append(pk)
            self.status_grid.addWidget(pk, i, 2)

        for i in range(1, 11):
            cb = ColorBar(Qt.Vertical)
            self.velocity_list.append(cb)
            self.status_grid.addWidget(cb, i, 3)

        for i in range(1, 11):
            cb = ColorBar(Qt.Vertical)
            self.current_list.append(cb)
            self.status_grid.addWidget(cb, i, 4)

        self.servo_dropbox.currentIndexChanged.connect(lambda x: self.update_servo_specific())
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)

        self.position_syncer = SliderSpinSyncer(self.position_slider,
                                                self.position_spin,
                                                self.position_changed)

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.motion_changed)

        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.motion_changed)

        self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider,
                                                    self.deceleration_spin,
                                                    self.motion_changed)

        self.period_syncer = SliderSpinSyncer(self.period_slider,
                                              self.period_spin,
                                              self.period_changed)

        self.pulse_width_min_spin.editingFinished.connect(self.pulse_width_spin_finished)
        self.pulse_width_max_spin.editingFinished.connect(self.pulse_width_spin_finished)
        self.degree_min_spin.editingFinished.connect(self.degree_spin_finished)
        self.degree_max_spin.editingFinished.connect(self.degree_spin_finished)
Beispiel #24
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickStepper, *args)

        self.setupUi(self)
     
        self.stepper = self.device
     
        self.endis_all(False)
        
        self.update_timer = QTimer()
        self.update_timer.timeout.connect(self.update_data)

        self.speedometer = SpeedoMeter()
        self.vertical_layout_right.insertWidget(5, self.speedometer)
        
        self.new_value = 0
        self.update_counter = 0
        
        self.full_brake_time = 0

        self.qem = QErrorMessage(self)
        self.qem.setWindowTitle("Under Voltage")

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)

        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.acceleration_changed)

        self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider,
                                                    self.deceleration_spin,
                                                    self.deceleration_changed)

#        self.decay_syncer = SliderSpinSyncer(self.decay_slider,
#                                             self.decay_spin,
#                                             self.decay_changed)

        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)
        self.forward_button.clicked.connect(self.forward_clicked)
        self.stop_button.clicked.connect(self.stop_clicked)
        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.backward_button.clicked.connect(self.backward_clicked)
        self.to_button.clicked.connect(self.to_button_clicked)
        self.steps_button.clicked.connect(self.steps_button_clicked)
        self.motor_current_button.clicked.connect(self.motor_current_button_clicked)
        self.minimum_motor_voltage_button.clicked.connect(self.minimum_motor_voltage_button_clicked)
        
        self.mode_dropbox.currentIndexChanged.connect(self.mode_changed)
        
        self.qtcb_position_reached.connect(self.cb_position_reached)
        self.stepper.register_callback(self.stepper.CALLBACK_POSITION_REACHED, 
                                       self.qtcb_position_reached.emit)
        
        self.qtcb_under_voltage.connect(self.cb_under_voltage)
        self.stepper.register_callback(self.stepper.CALLBACK_UNDER_VOLTAGE, 
                                       self.qtcb_under_voltage.emit)

        self.ste = 0
        self.pos = 0
        self.current_velocity = 0
        self.cur = 0
        self.sv  = 0
        self.ev  = 0
        self.mv  = 0
        self.mod = 0

        if self.firmware_version >= (1, 1, 4):
            reset = QAction('Reset', self)
            reset.triggered.connect(lambda: self.stepper.reset())
            self.set_actions(reset)
Beispiel #25
0
class PerformanceStepper(COMCUPluginBase, Ui_PerformanceStepper):
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletPerformanceStepper, *args)

        self.setupUi(self)

        self.ps = self.device

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

        # Init register access elements
        self.parent_items = {}
        for register_name in registers.keys():
            self.parent_items[register_name] = QTreeWidgetItem([register_name])

        for pi in self.parent_items.values():
            self.tree_widget.addTopLevelItem(pi)

        self.child_items = []
        for name, rows in registers.items():
            for row in rows:
                child = QTreeWidgetItem([row[0], hex(row[1]), row[2], '0', ''])
                self.child_items.append(child)
                self.parent_items[name].addChild(child)

        for pi in self.parent_items.values():
            pi.setExpanded(True)

        self.tree_widget.itemClicked.connect(self.register_item_clicked)
        self.button_read_registers.clicked.connect(self.read_registers_clicked)
        self.button_write_register.clicked.connect(self.write_register_clicked)

        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)
        self.maximum_motor_current_spinbox.valueChanged.connect(
            self.maximum_motor_current_changed)
        self.to_button.clicked.connect(self.to_button_clicked)
        self.steps_button.clicked.connect(self.steps_button_clicked)

        # Motion Configuration
        self.velocity_start_syncer = SliderSpinSyncer(
            self.velocity_start_slider, self.velocity_start_spinbox,
            self.motion_changed)
        self.velocity_stop_syncer = SliderSpinSyncer(
            self.velocity_stop_slider, self.velocity_stop_spinbox,
            self.motion_changed)
        self.velocity_1_syncer = SliderSpinSyncer(self.velocity_1_slider,
                                                  self.velocity_1_spinbox,
                                                  self.motion_changed)
        self.velocity_max_syncer = SliderSpinSyncer(self.velocity_max_slider,
                                                    self.velocity_max_spinbox,
                                                    self.motion_changed)
        self.acceleration_1_syncer = SliderSpinSyncer(
            self.acceleration_1_slider, self.acceleration_1_spinbox,
            self.motion_changed)
        self.acceleration_max_syncer = SliderSpinSyncer(
            self.acceleration_max_slider, self.acceleration_max_spinbox,
            self.motion_changed)
        self.deceleration_max_syncer = SliderSpinSyncer(
            self.deceleration_max_slider, self.deceleration_max_spinbox,
            self.motion_changed)
        self.deceleration_1_syncer = SliderSpinSyncer(
            self.deceleration_1_slider, self.deceleration_1_spinbox,
            self.motion_changed)
        self.ramp_zero_wait_syncer = SliderSpinSyncer(
            self.ramp_zero_wait_slider, self.ramp_zero_wait_spinbox,
            self.motion_changed)

        # Step Configuration
        self.step_resolution_dropbox.currentIndexChanged.connect(
            self.step_configuration_changed)
        self.interpolate_checkbox.stateChanged.connect(
            self.step_configuration_changed)

        # Basic Configuration
        self.standstill_current_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.motor_run_current_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.standstill_delay_time_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.power_down_time_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.stealth_threshold_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.coolstep_threashold_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.classic_threshold_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.high_velocity_chopper_mode_checkbox.stateChanged.connect(
            self.basic_configuration_changed)

        # Spreadcycle Configuration
        self.slow_decay_duration_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.fast_decay_duration_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.hysteresis_start_value_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.hysteresis_end_value_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.sine_wave_offset_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.chopper_mode_combo.currentIndexChanged.connect(
            self.spreadcycle_configuration_changed)
        self.comparator_blank_time_combo.currentIndexChanged.connect(
            self.spreadcycle_configuration_changed)
        self.high_velocity_fullstep_checkbox.stateChanged.connect(
            self.spreadcycle_configuration_changed)
        self.fast_decay_without_comparator_checkbox.stateChanged.connect(
            self.spreadcycle_configuration_changed)

        # Stealth Configuration
        self.enable_stealth_checkbox.stateChanged.connect(
            self.stealth_configuration_changed)
        self.offset_spin.valueChanged.connect(
            self.stealth_configuration_changed)
        self.gradient_spin.valueChanged.connect(
            self.stealth_configuration_changed)
        self.enable_autoscale_checkbox.stateChanged.connect(
            self.stealth_configuration_changed)
        self.enable_autogradient_checkbox.stateChanged.connect(
            self.stealth_configuration_changed)
        self.freewheel_mode_combo.currentIndexChanged.connect(
            self.stealth_configuration_changed)
        self.regulation_loop_gradient_spin.valueChanged.connect(
            self.stealth_configuration_changed)
        self.amplitude_limit_spin.valueChanged.connect(
            self.stealth_configuration_changed)

        # Coolstep Configuration
        self.minimum_stallguard_value_spin.valueChanged.connect(
            self.coolstep_configuration_changed)
        self.maximum_stallguard_value_spin.valueChanged.connect(
            self.coolstep_configuration_changed)
        self.current_up_step_width_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)
        self.current_down_step_width_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)
        self.minimum_current_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)
        self.stallguard_threshold_value_spin.valueChanged.connect(
            self.coolstep_configuration_changed)
        self.stallguard_mode_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)

        # Short Configuration
        self.disable_short_to_voltage_protection_checkbox.stateChanged.connect(
            self.short_configuration_changed)
        self.disable_short_to_ground_protection_checkbox.stateChanged.connect(
            self.short_configuration_changed)
        self.short_to_voltage_level_spin.valueChanged.connect(
            self.short_configuration_changed)
        self.short_to_ground_level_spin.valueChanged.connect(
            self.short_configuration_changed)
        self.spike_filter_bandwidth_combo.currentIndexChanged.connect(
            self.short_configuration_changed)
        self.short_detection_delay_checkbox.stateChanged.connect(
            self.short_configuration_changed)
        self.filter_time_combo.currentIndexChanged.connect(
            self.short_configuration_changed)

    def motion_changed(self, _):
        ramping_mode = self.ramping_mode_combobox.currentIndex()
        velocity_start = self.velocity_start_slider.value()
        acceleration_1 = self.acceleration_1_slider.value()
        velocity_1 = self.velocity_1_slider.value()
        acceleration_max = self.acceleration_max_slider.value()
        velocity_max = self.velocity_max_slider.value()
        deceleration_max = self.deceleration_max_slider.value()
        deceleration_1 = self.deceleration_1_slider.value()
        velocity_stop = self.velocity_stop_slider.value()
        ramp_zero_wait = self.ramp_zero_wait_slider.value()

        motion_configuration = (ramping_mode, velocity_start, acceleration_1,
                                velocity_1, acceleration_max, velocity_max,
                                deceleration_max, deceleration_1,
                                velocity_stop, ramp_zero_wait)
        self.ps.set_motion_configuration(*motion_configuration)

    def register_item_clicked(self, item, column):
        try:
            reg = int(item.text(1), 16)
            value = int(item.text(3))

            self.spinbox_write_register.setValue(reg)
            self.spinbox_write_value.setValue(value)
        except:
            pass

    def read_registers_clicked(self):
        for child in self.child_items:
            reg = int(child.text(1), 0)
            ret = self.ps.read_register(reg)
            child.setText(3, str(ret.value))

    def write_register_clicked(self):
        reg = self.spinbox_write_register.value()
        value = self.spinbox_write_value.value()
        ret = self.ps.write_register(reg, value)

    def start(self):
        async_call(self.ps.get_motion_configuration, None,
                   self.get_motion_configuration_async,
                   self.increase_error_count)
        async_call(self.ps.get_step_configuration, None,
                   self.get_step_configuration_async,
                   self.increase_error_count)
        async_call(self.ps.get_motor_current, None,
                   self.get_motor_current_async, self.increase_error_count)
        async_call(self.ps.get_enabled, None, self.get_enabled_async,
                   self.increase_error_count)

        async_call(self.ps.get_step_configuration, None,
                   self.get_step_configuration_async,
                   self.increase_error_count)
        async_call(self.ps.get_basic_configuration, None,
                   self.get_basic_configuration_async,
                   self.increase_error_count)
        async_call(self.ps.get_spreadcycle_configuration, None,
                   self.get_spreadcycle_configuration_async,
                   self.increase_error_count)
        async_call(self.ps.get_stealth_configuration, None,
                   self.get_stealth_configuration_async,
                   self.increase_error_count)
        async_call(self.ps.get_coolstep_configuration, None,
                   self.get_coolstep_configuration_async,
                   self.increase_error_count)
        async_call(self.ps.get_short_configuration, None,
                   self.get_short_configuration_async,
                   self.increase_error_count)

        self.update_timer.start(100)

    def stop(self):
        self.update_timer.stop()

    def destroy(self):
        pass

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

    def update_data(self):
        async_call(self.ps.get_remaining_steps, None,
                   self.get_remaining_steps_async, self.increase_error_count)
        async_call(self.ps.get_current_position, None,
                   self.get_current_position_async, self.increase_error_count)
        async_call(self.ps.get_current_velocity, None,
                   self.get_current_velocity_async, self.increase_error_count)

        self.update_counter += 1
        if self.update_counter % 10 == 0:
            async_call(self.ps.get_input_voltage, None,
                       self.get_input_voltage_async, self.increase_error_count)
            async_call(self.ps.get_driver_status, None,
                       self.get_driver_status_async, self.increase_error_count)
            async_call(self.ps.get_temperature, None,
                       self.get_temperature_async, self.increase_error_count)

    def to_button_clicked(self):
        drive_to = self.to_spin.value()
        try:
            self.ps.set_target_position(drive_to)
        except ip_connection.Error:
            return

    def steps_button_clicked(self):
        drive_steps = self.steps_spin.value()
        try:
            self.ps.set_steps(drive_steps)
        except ip_connection.Error:
            return

    def enable_state_changed(self, state):
        self.ps.set_enabled(state == Qt.Checked)

    def maximum_motor_current_changed(self, value):
        try:
            self.ps.set_motor_current(value)
        except ip_connection.Error:
            return

    def step_configuration_changed(self, _):
        step_resolution = self.step_resolution_dropbox.currentIndex()
        interpolation = self.interpolate_checkbox.isChecked()
        try:
            self.ps.set_step_configuration(step_resolution, interpolation)
        except ip_connection.Error:
            return

    def basic_configuration_changed(self, _):
        standstill_current = self.standstill_current_spin.value()
        motor_run_current = self.motor_run_current_spin.value()
        standstill_delay_time = self.standstill_delay_time_spin.value()
        power_down_time = self.power_down_time_spin.value()
        stealth_threshold = self.stealth_threshold_spin.value()
        coolstep_threshold = self.coolstep_threashold_spin.value()
        classic_threshold = self.classic_threshold_spin.value()
        high_velocity_chopper_mode = self.high_velocity_chopper_mode_checkbox.isChecked(
        )

        try:
            self.ps.set_basic_configuration(
                standstill_current, motor_run_current, standstill_delay_time,
                power_down_time, stealth_threshold, coolstep_threshold,
                classic_threshold, high_velocity_chopper_mode)
        except ip_connection.Error:
            return

    def spreadcycle_configuration_changed(self, _):
        slow_decay_duration = self.slow_decay_duration_spin.value()
        fast_decay_duration = self.fast_decay_duration_spin.value()
        hysteresis_start_value = self.hysteresis_start_value_spin.value()
        hysteresis_end_value = self.hysteresis_end_value_spin.value()
        sine_wave_offset = self.sine_wave_offset_spin.value()
        chopper_mode = self.chopper_mode_combo.currentIndex()
        comparator_blank_time = self.comparator_blank_time_combo.currentIndex()
        high_velocity_fullstep = self.high_velocity_fullstep_checkbox.isChecked(
        )
        fast_decay_without_comparator = self.fast_decay_without_comparator_checkbox.isChecked(
        )

        try:
            self.ps.set_spreadcycle_configuration(
                slow_decay_duration, high_velocity_fullstep,
                fast_decay_duration, hysteresis_start_value,
                hysteresis_end_value, sine_wave_offset, chopper_mode,
                comparator_blank_time, fast_decay_without_comparator)
        except ip_connection.Error:
            return

    def stealth_configuration_changed(self, _):
        enable_stealth = self.enable_stealth_checkbox.isChecked()
        offset = self.offset_spin.value()
        gradient = self.gradient_spin.value()
        enable_autoscale = self.enable_autoscale_checkbox.isChecked()
        enable_autogradient = self.enable_autogradient_checkbox.isChecked()
        freewheel_mode = self.freewheel_mode_combo.currentIndex()
        regulation_loop_gradient = self.regulation_loop_gradient_spin.value()
        amplitude_limit = self.amplitude_limit_spin.value()

        try:
            self.ps.set_stealth_configuration(enable_stealth, offset, gradient,
                                              enable_autoscale,
                                              enable_autogradient,
                                              freewheel_mode,
                                              regulation_loop_gradient,
                                              amplitude_limit)
        except ip_connection.Error:
            return

    def coolstep_configuration_changed(self, _):
        minimum_stallguard_value = self.minimum_stallguard_value_spin.value()
        maximum_stallguard_value = self.maximum_stallguard_value_spin.value()
        current_up_step_width = self.current_up_step_width_combo.currentIndex()
        current_down_step_width = self.current_down_step_width_combo.currentIndex(
        )
        minimum_current = self.minimum_current_combo.currentIndex()
        stallguard_threshold_value = self.stallguard_threshold_value_spin.value(
        )
        stallguard_mode = self.stallguard_mode_combo.currentIndex()

        try:
            self.ps.set_coolstep_configuration(
                minimum_stallguard_value, maximum_stallguard_value,
                current_up_step_width, current_down_step_width,
                minimum_current, stallguard_threshold_value, stallguard_mode)
        except ip_connection.Error:
            return

    def short_configuration_changed(self, _):
        disable_short_to_voltage_protection = self.disable_short_to_voltage_protection_checkbox.isChecked(
        )
        disable_short_to_ground_protection = self.disable_short_to_ground_protection_checkbox.isChecked(
        )
        short_to_voltage_level = self.short_to_voltage_level_spin.value()
        short_to_ground_level = self.short_to_ground_level_spin.value()
        spike_filter_bandwidth = self.spike_filter_bandwidth_combo.currentIndex(
        )
        short_detection_delay = self.short_detection_delay_checkbox.isChecked()
        filter_time = self.filter_time_combo.currentIndex()

        try:
            self.ps.set_short_configuration(
                disable_short_to_voltage_protection,
                disable_short_to_ground_protection, short_to_voltage_level,
                short_to_ground_level, spike_filter_bandwidth,
                short_detection_delay, filter_time)
        except ip_connection.Error:
            return

    def get_remaining_steps_async(self, remaining_steps):
        self.remaining_steps_label.setText(str(remaining_steps))

    def get_current_position_async(self, current_position):
        self.position_label.setText(str(current_position))

    def get_current_velocity_async(self, current_velocity):
        self.velocity_label.setText(str(current_velocity))

    def get_input_voltage_async(self, input_voltage):
        self.input_voltage_label.setText('{0:.1f}V'.format(input_voltage /
                                                           1000))

    def get_temperature_async(self, temperature):
        self.status_temperature.setText('{0:.1f}°C'.format(temperature / 10))

    def get_driver_status_async(self, driver_status):
        if driver_status.open_load == 0:
            self.status_open_load.setText('No')
        elif driver_status.open_load == 1:
            self.status_open_load.setText('Phase A')
        elif driver_status.open_load == 2:
            self.status_open_load.setText('Phase B')
        elif driver_status.open_load == 3:
            self.status_open_load.setText('Phase A and B')
        else:
            self.status_open_load.setText('Unknown')

        if driver_status.short_to_ground == 0:
            self.status_short_to_ground.setText('No')
        elif driver_status.short_to_ground == 1:
            self.status_short_to_ground.setText('Phase A')
        elif driver_status.short_to_ground == 2:
            self.status_short_to_ground.setText('Phase B')
        elif driver_status.short_to_ground == 3:
            self.status_short_to_ground.setText('Phase A and B')
        else:
            self.status_short_to_ground.setText('Unknown')

        if driver_status.over_temperature == 0:
            self.status_over_temperature.setText('No')
        elif driver_status.over_temperature == 1:
            self.status_over_temperature.setText(
                '<font color=yellow>Warning</font>')
        elif driver_status.over_temperature == 2:
            self.status_over_temperature.setText(
                '<font color=red>Limit</font>')

        if driver_status.motor_stalled:
            self.status_motor_stalled.setText('Yes')
        else:
            self.status_motor_stalled.setText('No')

        self.status_actual_motor_current.setText(
            str(driver_status.actual_motor_current))

        if driver_status.full_step_active:
            self.status_full_step_active.setText('Yes')
        else:
            self.status_full_step_active.setText('No')

        self.status_stallguard_result.setText(
            str(driver_status.stallguard_result))
        self.status_stealth_voltage_amplitude.setText(
            str(driver_status.stealth_voltage_amplitude))

    def get_enabled_async(self, enabled):
        old_state = self.enable_checkbox.blockSignals(True)
        self.enable_checkbox.setChecked(enabled)
        self.enable_checkbox.blockSignals(old_state)

    def get_motor_current_async(self, value):
        old_state = self.maximum_motor_current_spinbox.blockSignals(True)
        self.maximum_motor_current_spinbox.setValue(value)
        self.maximum_motor_current_spinbox.blockSignals(old_state)

    def get_step_configuration_async(self, conf):
        old_state = self.step_resolution_dropbox.blockSignals(True)
        self.step_resolution_dropbox.setCurrentIndex(conf.step_resolution)
        self.step_resolution_dropbox.blockSignals(old_state)

        old_state = self.interpolate_checkbox.blockSignals(True)
        self.interpolate_checkbox.setChecked(conf.interpolation)
        self.interpolate_checkbox.blockSignals(old_state)

    def get_motion_configuration_async(self, conf):
        self.velocity_start_syncer.set_value(conf.velocity_start)
        self.acceleration_1_syncer.set_value(conf.acceleration_1)
        self.velocity_1_syncer.set_value(conf.velocity_1)
        self.acceleration_max_syncer.set_value(conf.acceleration_max)
        self.velocity_max_syncer.set_value(conf.velocity_max)
        self.deceleration_max_syncer.set_value(conf.deceleration_max)
        self.deceleration_1_syncer.set_value(conf.deceleration_1)
        self.velocity_stop_syncer.set_value(conf.velocity_stop)
        self.ramp_zero_wait_syncer.set_value(conf.ramp_zero_wait)

        self.ramping_mode_combobox.setCurrentIndex(conf.ramping_mode)

    def get_basic_configuration_async(self, conf):
        old_state = self.standstill_current_spin.blockSignals(True)
        self.standstill_current_spin.setValue(conf.standstill_current)
        self.standstill_current_spin.blockSignals(old_state)

        old_state = self.motor_run_current_spin.blockSignals(True)
        self.motor_run_current_spin.setValue(conf.motor_run_current)
        self.motor_run_current_spin.blockSignals(old_state)

        old_state = self.standstill_delay_time_spin.blockSignals(True)
        self.standstill_delay_time_spin.setValue(conf.standstill_delay_time)
        self.standstill_delay_time_spin.blockSignals(old_state)

        old_state = self.power_down_time_spin.blockSignals(True)
        self.power_down_time_spin.setValue(conf.power_down_time)
        self.power_down_time_spin.blockSignals(old_state)

        old_state = self.stealth_threshold_spin.blockSignals(True)
        self.stealth_threshold_spin.setValue(conf.stealth_threshold)
        self.stealth_threshold_spin.blockSignals(old_state)

        old_state = self.coolstep_threashold_spin.blockSignals(True)
        self.coolstep_threashold_spin.setValue(conf.coolstep_threshold)
        self.coolstep_threashold_spin.blockSignals(old_state)

        old_state = self.classic_threshold_spin.blockSignals(True)
        self.classic_threshold_spin.setValue(conf.classic_threshold)
        self.classic_threshold_spin.blockSignals(old_state)

        old_state = self.high_velocity_chopper_mode_checkbox.blockSignals(True)
        self.high_velocity_chopper_mode_checkbox.setChecked(
            conf.high_velocity_chopper_mode)
        self.high_velocity_chopper_mode_checkbox.blockSignals(old_state)

    def get_spreadcycle_configuration_async(self, conf):
        old_state = self.slow_decay_duration_spin.blockSignals(True)
        self.slow_decay_duration_spin.setValue(conf.slow_decay_duration)
        self.slow_decay_duration_spin.blockSignals(old_state)

        old_state = self.fast_decay_duration_spin.blockSignals(True)
        self.fast_decay_duration_spin.setValue(conf.fast_decay_duration)
        self.fast_decay_duration_spin.blockSignals(old_state)

        old_state = self.hysteresis_start_value_spin.blockSignals(True)
        self.hysteresis_start_value_spin.setValue(conf.hysteresis_start_value)
        self.hysteresis_start_value_spin.blockSignals(old_state)

        old_state = self.hysteresis_end_value_spin.blockSignals(True)
        self.hysteresis_end_value_spin.setValue(conf.hysteresis_end_value)
        self.hysteresis_end_value_spin.blockSignals(old_state)

        old_state = self.sine_wave_offset_spin.blockSignals(True)
        self.sine_wave_offset_spin.setValue(conf.sine_wave_offset)
        self.sine_wave_offset_spin.blockSignals(old_state)

        old_state = self.chopper_mode_combo.blockSignals(True)
        self.chopper_mode_combo.setCurrentIndex(conf.chopper_mode)
        self.chopper_mode_combo.blockSignals(old_state)

        old_state = self.standstill_current_spin.blockSignals(True)
        self.comparator_blank_time_combo.setCurrentIndex(
            conf.comparator_blank_time)
        self.standstill_current_spin.blockSignals(old_state)

        old_state = self.high_velocity_fullstep_checkbox.blockSignals(True)
        self.high_velocity_fullstep_checkbox.setChecked(
            conf.high_velocity_fullstep)
        self.high_velocity_fullstep_checkbox.blockSignals(old_state)

        old_state = self.fast_decay_without_comparator_checkbox.blockSignals(
            True)
        self.fast_decay_without_comparator_checkbox.setChecked(
            conf.fast_decay_without_comparator)
        self.fast_decay_without_comparator_checkbox.blockSignals(old_state)

    def get_stealth_configuration_async(self, conf):
        old_state = self.enable_stealth_checkbox.blockSignals(True)
        self.enable_stealth_checkbox.setChecked(conf.enable_stealth)
        self.enable_stealth_checkbox.blockSignals(old_state)

        old_state = self.offset_spin.blockSignals(True)
        self.offset_spin.setValue(conf.offset)
        self.offset_spin.blockSignals(old_state)

        old_state = self.gradient_spin.blockSignals(True)
        self.gradient_spin.setValue(conf.gradient)
        self.gradient_spin.blockSignals(old_state)

        old_state = self.enable_autoscale_checkbox.blockSignals(True)
        self.enable_autoscale_checkbox.setChecked(conf.enable_autoscale)
        self.enable_autoscale_checkbox.blockSignals(old_state)

        old_state = self.enable_autogradient_checkbox.blockSignals(True)
        self.enable_autogradient_checkbox.setChecked(conf.enable_autogradient)
        self.enable_autogradient_checkbox.blockSignals(old_state)

        old_state = self.freewheel_mode_combo.blockSignals(True)
        self.freewheel_mode_combo.setCurrentIndex(conf.freewheel_mode)
        self.freewheel_mode_combo.blockSignals(old_state)

        old_state = self.regulation_loop_gradient_spin.blockSignals(True)
        self.regulation_loop_gradient_spin.setValue(
            conf.regulation_loop_gradient)
        self.regulation_loop_gradient_spin.blockSignals(old_state)

        old_state = self.amplitude_limit_spin.blockSignals(True)
        self.amplitude_limit_spin.setValue(conf.amplitude_limit)
        self.amplitude_limit_spin.blockSignals(old_state)

    def get_coolstep_configuration_async(self, conf):
        old_state = self.minimum_stallguard_value_spin.blockSignals(True)
        self.minimum_stallguard_value_spin.setValue(
            conf.minimum_stallguard_value)
        self.minimum_stallguard_value_spin.blockSignals(old_state)

        old_state = self.maximum_stallguard_value_spin.blockSignals(True)
        self.maximum_stallguard_value_spin.setValue(
            conf.maximum_stallguard_value)
        self.maximum_stallguard_value_spin.blockSignals(old_state)

        old_state = self.current_up_step_width_combo.blockSignals(True)
        self.current_up_step_width_combo.setCurrentIndex(
            conf.current_up_step_width)
        self.current_up_step_width_combo.blockSignals(old_state)

        old_state = self.current_down_step_width_combo.blockSignals(True)
        self.current_down_step_width_combo.setCurrentIndex(
            conf.current_down_step_width)
        self.current_down_step_width_combo.blockSignals(old_state)

        old_state = self.minimum_current_combo.blockSignals(True)
        self.minimum_current_combo.setCurrentIndex(conf.minimum_current)
        self.minimum_current_combo.blockSignals(old_state)

        old_state = self.stallguard_threshold_value_spin.blockSignals(True)
        self.stallguard_threshold_value_spin.setValue(
            conf.stallguard_threshold_value)
        self.stallguard_threshold_value_spin.blockSignals(old_state)

        old_state = self.stallguard_mode_combo.blockSignals(True)
        self.stallguard_mode_combo.setCurrentIndex(conf.stallguard_mode)
        self.stallguard_mode_combo.blockSignals(old_state)

    def get_short_configuration_async(self, conf):
        old_state = self.disable_short_to_voltage_protection_checkbox.blockSignals(
            True)
        self.disable_short_to_voltage_protection_checkbox.setChecked(
            conf.disable_short_to_voltage_protection)
        self.disable_short_to_voltage_protection_checkbox.blockSignals(
            old_state)

        old_state = self.disable_short_to_ground_protection_checkbox.blockSignals(
            True)
        self.disable_short_to_ground_protection_checkbox.setChecked(
            conf.disable_short_to_ground_protection)
        self.disable_short_to_ground_protection_checkbox.blockSignals(
            old_state)

        old_state = self.short_to_voltage_level_spin.blockSignals(True)
        self.short_to_voltage_level_spin.setValue(conf.short_to_voltage_level)
        self.short_to_voltage_level_spin.blockSignals(old_state)

        old_state = self.short_to_ground_level_spin.blockSignals(True)
        self.short_to_ground_level_spin.setValue(conf.short_to_ground_level)
        self.short_to_ground_level_spin.blockSignals(old_state)

        old_state = self.spike_filter_bandwidth_combo.blockSignals(True)
        self.spike_filter_bandwidth_combo.setCurrentIndex(
            conf.spike_filter_bandwidth)
        self.spike_filter_bandwidth_combo.blockSignals(old_state)

        old_state = self.short_detection_delay_checkbox.blockSignals(True)
        self.short_detection_delay_checkbox.setChecked(
            conf.short_detection_delay)
        self.short_detection_delay_checkbox.blockSignals(old_state)

        old_state = self.filter_time_combo.blockSignals(True)
        self.filter_time_combo.setCurrentIndex(conf.filter_time)
        self.filter_time_combo.blockSignals(old_state)
Beispiel #26
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletPerformanceStepper, *args)

        self.setupUi(self)

        self.ps = self.device

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

        # Init register access elements
        self.parent_items = {}
        for register_name in registers.keys():
            self.parent_items[register_name] = QTreeWidgetItem([register_name])

        for pi in self.parent_items.values():
            self.tree_widget.addTopLevelItem(pi)

        self.child_items = []
        for name, rows in registers.items():
            for row in rows:
                child = QTreeWidgetItem([row[0], hex(row[1]), row[2], '0', ''])
                self.child_items.append(child)
                self.parent_items[name].addChild(child)

        for pi in self.parent_items.values():
            pi.setExpanded(True)

        self.tree_widget.itemClicked.connect(self.register_item_clicked)
        self.button_read_registers.clicked.connect(self.read_registers_clicked)
        self.button_write_register.clicked.connect(self.write_register_clicked)

        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)
        self.maximum_motor_current_spinbox.valueChanged.connect(
            self.maximum_motor_current_changed)
        self.to_button.clicked.connect(self.to_button_clicked)
        self.steps_button.clicked.connect(self.steps_button_clicked)

        # Motion Configuration
        self.velocity_start_syncer = SliderSpinSyncer(
            self.velocity_start_slider, self.velocity_start_spinbox,
            self.motion_changed)
        self.velocity_stop_syncer = SliderSpinSyncer(
            self.velocity_stop_slider, self.velocity_stop_spinbox,
            self.motion_changed)
        self.velocity_1_syncer = SliderSpinSyncer(self.velocity_1_slider,
                                                  self.velocity_1_spinbox,
                                                  self.motion_changed)
        self.velocity_max_syncer = SliderSpinSyncer(self.velocity_max_slider,
                                                    self.velocity_max_spinbox,
                                                    self.motion_changed)
        self.acceleration_1_syncer = SliderSpinSyncer(
            self.acceleration_1_slider, self.acceleration_1_spinbox,
            self.motion_changed)
        self.acceleration_max_syncer = SliderSpinSyncer(
            self.acceleration_max_slider, self.acceleration_max_spinbox,
            self.motion_changed)
        self.deceleration_max_syncer = SliderSpinSyncer(
            self.deceleration_max_slider, self.deceleration_max_spinbox,
            self.motion_changed)
        self.deceleration_1_syncer = SliderSpinSyncer(
            self.deceleration_1_slider, self.deceleration_1_spinbox,
            self.motion_changed)
        self.ramp_zero_wait_syncer = SliderSpinSyncer(
            self.ramp_zero_wait_slider, self.ramp_zero_wait_spinbox,
            self.motion_changed)

        # Step Configuration
        self.step_resolution_dropbox.currentIndexChanged.connect(
            self.step_configuration_changed)
        self.interpolate_checkbox.stateChanged.connect(
            self.step_configuration_changed)

        # Basic Configuration
        self.standstill_current_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.motor_run_current_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.standstill_delay_time_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.power_down_time_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.stealth_threshold_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.coolstep_threashold_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.classic_threshold_spin.valueChanged.connect(
            self.basic_configuration_changed)
        self.high_velocity_chopper_mode_checkbox.stateChanged.connect(
            self.basic_configuration_changed)

        # Spreadcycle Configuration
        self.slow_decay_duration_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.fast_decay_duration_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.hysteresis_start_value_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.hysteresis_end_value_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.sine_wave_offset_spin.valueChanged.connect(
            self.spreadcycle_configuration_changed)
        self.chopper_mode_combo.currentIndexChanged.connect(
            self.spreadcycle_configuration_changed)
        self.comparator_blank_time_combo.currentIndexChanged.connect(
            self.spreadcycle_configuration_changed)
        self.high_velocity_fullstep_checkbox.stateChanged.connect(
            self.spreadcycle_configuration_changed)
        self.fast_decay_without_comparator_checkbox.stateChanged.connect(
            self.spreadcycle_configuration_changed)

        # Stealth Configuration
        self.enable_stealth_checkbox.stateChanged.connect(
            self.stealth_configuration_changed)
        self.offset_spin.valueChanged.connect(
            self.stealth_configuration_changed)
        self.gradient_spin.valueChanged.connect(
            self.stealth_configuration_changed)
        self.enable_autoscale_checkbox.stateChanged.connect(
            self.stealth_configuration_changed)
        self.enable_autogradient_checkbox.stateChanged.connect(
            self.stealth_configuration_changed)
        self.freewheel_mode_combo.currentIndexChanged.connect(
            self.stealth_configuration_changed)
        self.regulation_loop_gradient_spin.valueChanged.connect(
            self.stealth_configuration_changed)
        self.amplitude_limit_spin.valueChanged.connect(
            self.stealth_configuration_changed)

        # Coolstep Configuration
        self.minimum_stallguard_value_spin.valueChanged.connect(
            self.coolstep_configuration_changed)
        self.maximum_stallguard_value_spin.valueChanged.connect(
            self.coolstep_configuration_changed)
        self.current_up_step_width_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)
        self.current_down_step_width_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)
        self.minimum_current_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)
        self.stallguard_threshold_value_spin.valueChanged.connect(
            self.coolstep_configuration_changed)
        self.stallguard_mode_combo.currentIndexChanged.connect(
            self.coolstep_configuration_changed)

        # Short Configuration
        self.disable_short_to_voltage_protection_checkbox.stateChanged.connect(
            self.short_configuration_changed)
        self.disable_short_to_ground_protection_checkbox.stateChanged.connect(
            self.short_configuration_changed)
        self.short_to_voltage_level_spin.valueChanged.connect(
            self.short_configuration_changed)
        self.short_to_ground_level_spin.valueChanged.connect(
            self.short_configuration_changed)
        self.spike_filter_bandwidth_combo.currentIndexChanged.connect(
            self.short_configuration_changed)
        self.short_detection_delay_checkbox.stateChanged.connect(
            self.short_configuration_changed)
        self.filter_time_combo.currentIndexChanged.connect(
            self.short_configuration_changed)
Beispiel #27
0
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletPerformanceDC, *args)

        self.setupUi(self)

        self.dc = self.device

        self.qem = QErrorMessage(self)
        self.qtcb_emergency_shutdown.connect(self.cb_emergency_shutdown)
        self.dc.register_callback(self.dc.CALLBACK_EMERGENCY_SHUTDOWN,
                                  self.qtcb_emergency_shutdown.emit)

        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)
        self.radio_mode_brake.toggled.connect(self.brake_value_changed)
        self.radio_mode_coast.toggled.connect(self.coast_value_changed)

        self.gpio0_rising_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(0))
        self.gpio0_falling_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(0))
        self.gpio1_rising_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(1))
        self.gpio1_falling_combo.currentIndexChanged.connect(
            lambda x: self.gpio_action_changed(1))
        self.gpio0_debounce_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(0))
        self.gpio0_stop_deceleration_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(0))
        self.gpio1_debounce_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(1))
        self.gpio1_stop_deceleration_spin.valueChanged.connect(
            lambda: self.gpio_configuration_changed(1))

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)
        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.motion_changed)
        self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider,
                                                    self.deceleration_spin,
                                                    self.motion_changed)
        self.frequency_syncer = SliderSpinSyncer(self.frequency_slider,
                                                 self.frequency_spin,
                                                 self.frequency_changed)

        self.cbe_power_statistics = CallbackEmulator(
            self, self.dc.get_power_statistics, None,
            self.get_power_statistics_async, self.increase_error_count)
        self.cbe_current_velocity = CallbackEmulator(
            self, self.dc.get_current_velocity, None,
            self.get_current_velocity_async, self.increase_error_count)
        self.cbe_gpio_state = CallbackEmulator(self, self.dc.get_gpio_state,
                                               None, self.get_gpio_state_async,
                                               self.increase_error_count)

        self.error_led_off_action = QAction('Off', self)
        self.error_led_off_action.triggered.connect(
            lambda: self.dc.set_error_led_config(BrickletPerformanceDC.
                                                 ERROR_LED_CONFIG_OFF))
        self.error_led_on_action = QAction('On', self)
        self.error_led_on_action.triggered.connect(
            lambda: self.dc.set_error_led_config(BrickletPerformanceDC.
                                                 ERROR_LED_CONFIG_ON))
        self.error_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.error_led_show_heartbeat_action.triggered.connect(
            lambda: self.dc.set_error_led_config(
                BrickletPerformanceDC.ERROR_LED_CONFIG_SHOW_HEARTBEAT))
        self.error_led_show_error_action = QAction('Show Error', self)
        self.error_led_show_error_action.triggered.connect(
            lambda: self.dc.set_error_led_config(BrickletPerformanceDC.
                                                 ERROR_LED_CONFIG_SHOW_ERROR))

        self.extra_configs += [(1, 'Error LED:', [
            self.error_led_off_action, self.error_led_on_action,
            self.error_led_show_heartbeat_action,
            self.error_led_show_error_action
        ])]

        self.cw_led_off_action = QAction('Off', self)
        self.cw_led_off_action.triggered.connect(
            lambda: self.dc.set_cw_led_config(BrickletPerformanceDC.
                                              CW_LED_CONFIG_OFF))
        self.cw_led_on_action = QAction('On', self)
        self.cw_led_on_action.triggered.connect(
            lambda: self.dc.set_cw_led_config(BrickletPerformanceDC.
                                              CW_LED_CONFIG_ON))
        self.cw_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.cw_led_show_heartbeat_action.triggered.connect(
            lambda: self.dc.set_cw_led_config(BrickletPerformanceDC.
                                              CW_LED_CONFIG_SHOW_HEARTBEAT))
        self.cw_led_show_cw_as_forward_action = QAction(
            'Show CW As Forward', self)
        self.cw_led_show_cw_as_forward_action.triggered.connect(
            lambda: self.dc.set_cw_led_config(
                BrickletPerformanceDC.CW_LED_CONFIG_SHOW_CW_AS_FORWARD))
        self.cw_led_show_cw_as_backward_action = QAction(
            'Show CW As Backward', self)
        self.cw_led_show_cw_as_backward_action.triggered.connect(
            lambda: self.dc.set_cw_led_config(
                BrickletPerformanceDC.CW_LED_CONFIG_SHOW_CW_AS_BACKWARD))

        self.extra_configs += [(2, 'CW LED:', [
            self.cw_led_off_action, self.cw_led_on_action,
            self.cw_led_show_heartbeat_action,
            self.cw_led_show_cw_as_forward_action,
            self.cw_led_show_cw_as_backward_action
        ])]

        self.ccw_led_off_action = QAction('Off', self)
        self.ccw_led_off_action.triggered.connect(
            lambda: self.dc.set_ccw_led_config(BrickletPerformanceDC.
                                               CCW_LED_CONFIG_OFF))
        self.ccw_led_on_action = QAction('On', self)
        self.ccw_led_on_action.triggered.connect(
            lambda: self.dc.set_ccw_led_config(BrickletPerformanceDC.
                                               CCW_LED_CONFIG_ON))
        self.ccw_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.ccw_led_show_heartbeat_action.triggered.connect(
            lambda: self.dc.set_ccw_led_config(BrickletPerformanceDC.
                                               CCW_LED_CONFIG_SHOW_HEARTBEAT))
        self.ccw_led_show_ccw_as_forward_action = QAction(
            'Show CCW As Forward', self)
        self.ccw_led_show_ccw_as_forward_action.triggered.connect(
            lambda: self.dc.set_ccw_led_config(
                BrickletPerformanceDC.CCW_LED_CONFIG_SHOW_CCW_AS_FORWARD))
        self.ccw_led_show_ccw_as_backward_action = QAction(
            'Show CCW As Backward', self)
        self.ccw_led_show_ccw_as_backward_action.triggered.connect(
            lambda: self.dc.set_ccw_led_config(
                BrickletPerformanceDC.CCW_LED_CONFIG_SHOW_CCW_AS_BACKWARD))

        self.extra_configs += [(2, 'CCW LED:', [
            self.ccw_led_off_action, self.ccw_led_on_action,
            self.ccw_led_show_heartbeat_action,
            self.ccw_led_show_ccw_as_forward_action,
            self.ccw_led_show_ccw_as_backward_action
        ])]

        self.gpio0_led_off_action = QAction('Off', self)
        self.gpio0_led_off_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                0, BrickletPerformanceDC.GPIO_LED_CONFIG_OFF))
        self.gpio0_led_on_action = QAction('On', self)
        self.gpio0_led_on_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                0, BrickletPerformanceDC.GPIO_LED_CONFIG_ON))
        self.gpio0_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.gpio0_led_show_heartbeat_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                0, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_HEARTBEAT))
        self.gpio0_led_show_show_gpio_active_high_action = QAction(
            'Show GPIO Active High', self)
        self.gpio0_led_show_show_gpio_active_high_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                0, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_HIGH
            ))
        self.gpio0_led_show_show_gpio_active_low_action = QAction(
            'Show GPIO Active Low', self)
        self.gpio0_led_show_show_gpio_active_low_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                0, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_LOW))

        self.extra_configs += [(3, 'GPIO0 LED:', [
            self.gpio0_led_off_action, self.gpio0_led_on_action,
            self.gpio0_led_show_heartbeat_action,
            self.gpio0_led_show_show_gpio_active_high_action,
            self.gpio0_led_show_show_gpio_active_low_action
        ])]

        self.gpio1_led_off_action = QAction('Off', self)
        self.gpio1_led_off_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                1, BrickletPerformanceDC.GPIO_LED_CONFIG_OFF))
        self.gpio1_led_on_action = QAction('On', self)
        self.gpio1_led_on_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                1, BrickletPerformanceDC.GPIO_LED_CONFIG_ON))
        self.gpio1_led_show_heartbeat_action = QAction('Show Heartbeat', self)
        self.gpio1_led_show_heartbeat_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                1, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_HEARTBEAT))
        self.gpio1_led_show_show_gpio_active_high_action = QAction(
            'Show GPIO Active High', self)
        self.gpio1_led_show_show_gpio_active_high_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                1, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_HIGH
            ))
        self.gpio1_led_show_show_gpio_active_low_action = QAction(
            'Show GPIO Active Low', self)
        self.gpio1_led_show_show_gpio_active_low_action.triggered.connect(
            lambda: self.dc.set_gpio_led_config(
                1, BrickletPerformanceDC.GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_LOW))

        self.extra_configs += [(3, 'GPIO1 LED:', [
            self.gpio1_led_off_action, self.gpio1_led_on_action,
            self.gpio1_led_show_heartbeat_action,
            self.gpio1_led_show_show_gpio_active_high_action,
            self.gpio1_led_show_show_gpio_active_low_action
        ])]
Beispiel #28
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickDC, *args)

        self.setupUi(self)

        self.dc = self.device

        self.encoder_hide_all()

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

        self.speedometer = SpeedoMeter()
        self.vertical_layout_right.insertWidget(4, self.speedometer)

        self.new_value = 0
        self.update_counter = 0

        self.full_brake_time = 0

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)

        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.acceleration_changed)

        self.frequency_syncer = SliderSpinSyncer(self.frequency_slider,
                                                 self.frequency_spin,
                                                 self.frequency_changed)

        self.radio_mode_brake.toggled.connect(self.brake_value_changed)
        self.radio_mode_coast.toggled.connect(self.coast_value_changed)

        self.minimum_voltage_button.clicked.connect(
            self.minimum_voltage_button_clicked)
        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)

        self.emergency_signal = None
        self.under_signal = None
        self.current_velocity_signal = None
        self.velocity_reached_signal = None

        self.qem = QErrorMessage(self)

        self.qtcb_under_voltage.connect(self.cb_under_voltage)
        self.dc.register_callback(self.dc.CALLBACK_UNDER_VOLTAGE,
                                  self.qtcb_under_voltage.emit)

        self.qtcb_emergency_shutdown.connect(self.cb_emergency_shutdown)
        self.dc.register_callback(self.dc.CALLBACK_EMERGENCY_SHUTDOWN,
                                  self.qtcb_emergency_shutdown.emit)

        self.qtcb_velocity_reached.connect(self.update_velocity)
        self.dc.register_callback(self.dc.CALLBACK_VELOCITY_REACHED,
                                  self.qtcb_velocity_reached.emit)

        self.cbe_current_velocity = CallbackEmulator(
            self.dc.get_current_velocity, self.update_velocity,
            self.increase_error_count)

        if self.firmware_version >= (1, 1, 3):
            reset = QAction('Reset', self)
            reset.triggered.connect(lambda: self.dc.reset())
            self.set_actions(reset)
Beispiel #29
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickServo, *args)

        self.setupUi(self)

        self.servo = self.device

        self.position_list = []
        self.velocity_list = []
        self.acceleration_list = []
        self.enable_list = []

        self.up_cur = 0
        self.up_siv = 0
        self.up_eiv = 0
        self.up_opv = 0
        self.up_mv = 0

        self.up_ena = [0] * 7
        self.up_pos = [0] * 7
        self.up_vel = [0] * 7
        self.up_acc = [0] * 7

        self.update_timer = QTimer()
        self.update_timer.timeout.connect(self.update_apply)
        self.update_timer.setInterval(50)

        self.alive = True

        for i in range(1, 8):
            label = QLabel()
            label.setText('Off')
            self.enable_list.append(label)
            self.status_grid.addWidget(label, i, 1)

        for i in range(1, 8):
            pk = PositionKnob()
            self.position_list.append(pk)
            self.status_grid.addWidget(pk, i, 2)

        for i in range(1, 8):
            cb = ColorBar(Qt.Vertical)
            self.velocity_list.append(cb)
            self.status_grid.addWidget(cb, i, 3)

        for i in range(1, 8):
            cb = ColorBar(Qt.Vertical)
            self.acceleration_list.append(cb)
            self.status_grid.addWidget(cb, i, 4)

        self.qem = QErrorMessage(self)
        self.qem.setWindowTitle("Under Voltage")

        self.test_button.clicked.connect(self.test_button_clicked)
        self.output_voltage_button.clicked.connect(
            self.output_voltage_button_clicked)

        self.servo_dropbox.currentIndexChanged.connect(
            lambda x: self.update_servo_specific())
        self.enable_checkbox.stateChanged.connect(self.enable_state_changed)

        self.position_syncer = SliderSpinSyncer(self.position_slider,
                                                self.position_spin,
                                                self.position_changed)

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)

        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.acceleration_changed)

        self.period_syncer = SliderSpinSyncer(self.period_slider,
                                              self.period_spin,
                                              self.period_changed)

        self.pulse_width_min_spin.editingFinished.connect(
            self.pulse_width_spin_finished)
        self.pulse_width_max_spin.editingFinished.connect(
            self.pulse_width_spin_finished)
        self.degree_min_spin.editingFinished.connect(self.degree_spin_finished)
        self.degree_max_spin.editingFinished.connect(self.degree_spin_finished)

        self.minimum_voltage_button.clicked.connect(
            self.minimum_voltage_button_clicked)

        self.qtcb_under_voltage.connect(self.cb_under_voltage)
        self.servo.register_callback(self.servo.CALLBACK_UNDER_VOLTAGE,
                                     self.qtcb_under_voltage.emit)

        class WorkerThread(QThread):
            def __init__(self, parent=None, func=None):
                QThread.__init__(self, parent)
                self.func = func

            def run(self):
                self.func()

        self.test_event = Event()
        self.test_thread_object = WorkerThread(self, self.test_thread)
        self.update_event = Event()
        self.update_thread_object = WorkerThread(self, self.update_thread)

        self.update_thread_first_time = False

        self.update_done_event = Event()
        self.update_done_event.set()

        if self.firmware_version >= (1, 1, 3):
            reset = QAction('Reset', self)
            reset.triggered.connect(lambda: self.servo.reset())
            self.set_actions(reset)
Beispiel #30
0
    def __init__(self, *args):
        PluginBase.__init__(self, BrickStepper, *args)

        self.setupUi(self)

        self.stepper = self.device

        self.endis_all(False)

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

        self.new_value = 0
        self.update_counter = 0

        self.full_brake_time = 0

        self.qem = QErrorMessage(self)
        self.qem.setWindowTitle("Under Voltage")

        self.decay_widget.hide()

        self.setting_sync_rect_checkbox = False

        self.velocity_syncer = SliderSpinSyncer(self.velocity_slider,
                                                self.velocity_spin,
                                                self.velocity_changed)

        self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider,
                                                    self.acceleration_spin,
                                                    self.acceleration_changed)

        self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider,
                                                    self.deceleration_spin,
                                                    self.deceleration_changed)

        self.decay_syncer = SliderSpinSyncer(self.decay_slider,
                                             self.decay_spin,
                                             self.decay_changed)

        self.enable_checkbox.toggled.connect(self.enable_toggled)
        self.forward_button.clicked.connect(self.forward_clicked)
        self.stop_button.clicked.connect(self.stop_clicked)
        self.full_brake_button.clicked.connect(self.full_brake_clicked)
        self.backward_button.clicked.connect(self.backward_clicked)
        self.to_button.clicked.connect(self.to_button_clicked)
        self.steps_button.clicked.connect(self.steps_button_clicked)
        self.motor_current_button.clicked.connect(
            self.motor_current_button_clicked)
        self.minimum_motor_voltage_button.clicked.connect(
            self.minimum_motor_voltage_button_clicked)
        self.sync_rect_checkbox.toggled.connect(self.sync_rect_toggled)

        self.mode_dropbox.currentIndexChanged.connect(self.mode_changed)

        self.qtcb_position_reached.connect(self.cb_position_reached)
        self.stepper.register_callback(self.stepper.CALLBACK_POSITION_REACHED,
                                       self.qtcb_position_reached.emit)

        self.qtcb_under_voltage.connect(self.cb_under_voltage)
        self.stepper.register_callback(self.stepper.CALLBACK_UNDER_VOLTAGE,
                                       self.qtcb_under_voltage.emit)

        self.ste = 0
        self.pos = 0
        self.current_velocity = 0
        self.cur = 0
        self.sv = 0
        self.ev = 0
        self.mv = 0
        self.mod = 0

        if self.firmware_version >= (2, 3, 1):
            self.status_led_action = QAction('Status LED', self)
            self.status_led_action.setCheckable(True)
            self.status_led_action.toggled.connect(
                lambda checked: self.stepper.enable_status_led()
                if checked else self.stepper.disable_status_led())
            self.set_configs([(0, None, [self.status_led_action])])
        else:
            self.status_led_action = None

        if self.firmware_version >= (1, 1, 4):
            reset = QAction('Reset', self)
            reset.triggered.connect(lambda: self.stepper.reset())
            self.set_actions([(0, None, [reset])])