Beispiel #1
0
    def stop_motor(self):
        self.stop = True

        try:
            driver_address = self.advanced_options.motor_driver_address
            _driver.stop_motor(driver_address)

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            msg = _QCoreApplication.translate(
                '', 'Failed to stop motor.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            return
Beispiel #2
0
    def stop_measurement(self, silent=False):
        try:
            self.stop = True
            self.ui.pbt_start_measurement.setEnabled(True)
            _driver.stop_motor(
                self.advanced_options.motor_driver_address)
            if not silent:
                msg = _QCoreApplication.translate(
                    '', 'The user stopped the measurements.')
                title = _QCoreApplication.translate('', 'Abort')
                _QMessageBox.information(
                    self, title, msg, _QMessageBox.Ok)

        except Exception:
            self.stop = True
            _traceback.print_exc(file=_sys.stdout)
            msg = _QCoreApplication.translate(
                '', 'Failed to stop measurements.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
Beispiel #3
0
    def move_half_turn(self):
        try:
            if self.stop:
                return False

            wait = 0.5

            motor_resolution = self.advanced_options.motor_resolution
            driver_address = self.advanced_options.motor_driver_address
            steps = int(int(motor_resolution)*0.5)

            _driver.stop_motor(driver_address)
            _time.sleep(wait)

            if not self.configure_driver(steps):
                return False

            if self.stop:
                return False

            _driver.move_motor(driver_address)
            _time.sleep(wait)

            while not _driver.ready(driver_address) and not self.stop:
                _time.sleep(wait)
                _QApplication.processEvents()

            _time.sleep(wait)

            if self.stop:
                return False

            return True

        except Exception:
            msg = _QCoreApplication.translate(
                '', 'Failed to move motor to initial position.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            _traceback.print_exc(file=_sys.stdout)
            return False
Beispiel #4
0
    def configure_driver(self, steps):
        try:
            _driver.stop_motor(
                self.advanced_options.motor_driver_address)
            _time.sleep(0.1)

            return _driver.config_motor(
                self.advanced_options.motor_driver_address,
                0,
                self.advanced_options.motor_rotation_direction,
                self.advanced_options.motor_resolution,
                self.advanced_options.motor_velocity,
                self.advanced_options.motor_acceleration,
                steps)

        except Exception:
            msg = _QCoreApplication.translate(
                '', 'Failed to configure driver.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            _traceback.print_exc(file=_sys.stdout)
            return False
Beispiel #5
0
    def move_to_initial_position(self):
        try:
            if self.stop:
                return False

            if not _integrator.connected:
                msg = _QCoreApplication.translate(
                    '', 'Integrator not connected.')
                title = _QCoreApplication.translate('', 'Failure')
                _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
                return False

            trigger = self.advanced_options.integration_trigger
            encoder_res = self.advanced_options.integrator_encoder_resolution
            motor_resolution = self.advanced_options.motor_resolution
            rotation_direction = self.advanced_options.motor_rotation_direction
            driver_address = self.advanced_options.motor_driver_address

            wait = 0.5
            tol = encoder_res/10

            _driver.stop_motor(driver_address)
            _time.sleep(wait)

            current_position = int(_integrator.read_encoder())
            position = trigger

            if _np.abs(current_position - position) <= tol:
                return True

            diff = (current_position - position)
            if rotation_direction == '-':
                diff = diff*(-1)
            pulses = (encoder_res - diff) % encoder_res
            steps = int((pulses*motor_resolution)/encoder_res)

            if not self.configure_driver(steps):
                return False

            if self.stop:
                return False

            _driver.move_motor(driver_address)
            _time.sleep(wait)

            while not _driver.ready(driver_address) and not self.stop:
                _time.sleep(wait)
                _QApplication.processEvents()

            _time.sleep(wait)

            if self.stop:
                return False

            return True

        except Exception:
            msg = _QCoreApplication.translate(
                '', 'Failed to move motor to initial position.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            _traceback.print_exc(file=_sys.stdout)
            return False
Beispiel #6
0
    def measure_position(self, gain):
        try:
            if self.stop:
                return False

            self.integrated_voltage = []

            steps = int((self.advanced_options.integration_nr_turns + 1)*(
                self.advanced_options.motor_resolution))

            if not self.configure_integrator(gain):
                return False

            if not self.configure_driver(steps):
                return False

            driver_address = self.advanced_options.motor_driver_address
            nr_turns = self.advanced_options.integration_nr_turns
            integration_points = self.advanced_options.integration_points
            total_npts = nr_turns*integration_points

            if total_npts > 100:
                step_status = int(total_npts/20)
            elif total_npts > 50:
                step_status = int(total_npts/10)
            else:
                step_status = 1

            if not _integrator.start_measurement():
                msg = _QCoreApplication.translate(
                    '', 'Incorrect integrator status.')
                title = _QCoreApplication.translate('', 'Failure')
                _QMessageBox.critical(
                    self, title, msg, _QMessageBox.Ok)
                return False

            if self.stop:
                return False

            _driver.move_motor(driver_address)

            self.ui.pgb_status.setMinimum(0)
            self.ui.pgb_status.setMaximum(total_npts)
            self.ui.pgb_status.setValue(0)

            count = 0
            while (count < total_npts) and (not self.stop):
                _QApplication.processEvents()
                count = _integrator.get_data_count()
                if count % step_status == 0:
                    self.ui.pgb_status.setValue(count)
            data = _integrator.get_data_array()
            if any(_np.isnan(di) for di in data):
                msg = _QCoreApplication.translate(
                    '', (
                    'Integrator over-range.\n' +
                    'Please configure a lower gain.'
                    ))
                title = _QCoreApplication.translate('', 'Warning')
                _QMessageBox.warning(self, title, msg, _QMessageBox.Ok)
                return False

            if self.stop:
                return False

            _driver.stop_motor(driver_address)

            self.ui.pgb_status.setValue(total_npts)

            integrated_voltage = _np.array(data).reshape(
                nr_turns, integration_points).transpose()

            if nr_turns > 5:
                integrated_voltage = integrated_voltage[:, 1:-1]

            self.integrated_voltage = integrated_voltage*(
                _integrator.conversion_factor)

            if self.stop:
                return False

            return True

        except Exception:
            _traceback.print_exc(file=_sys.stdout)
            _driver.stop_motor(
                self.advanced_options.motor_driver_address)
            self.ui.pgb_status.setValue(0)
            msg = _QCoreApplication.translate(
                '', 'Measurement failed.')
            title = _QCoreApplication.translate('', 'Failure')
            _QMessageBox.critical(self, title, msg, _QMessageBox.Ok)
            return False