示例#1
0
    def get_and_verify_pulse_ms(self, pulse_ms: Optional[int]) -> int:
        """Return and verify pulse_ms to use.

        If pulse_ms is None return the default.
        """
        assert self.platform is not None
        if pulse_ms is None:
            if self.config['default_pulse_ms'] is not None:
                pulse_ms = self.config['default_pulse_ms']
            else:
                pulse_ms = self.machine.config['mpf']['default_pulse_ms']

        if not isinstance(pulse_ms, int):
            raise AssertionError("Wrong type {}".format(pulse_ms))

        if 0 > pulse_ms > self.platform.features['max_pulse']:
            raise AssertionError("Pulse_ms {} is not valid.".format(pulse_ms))

        if self.config[
                'max_pulse_ms'] and pulse_ms > self.config['max_pulse_ms']:
            raise DriverLimitsError(
                "Driver {} may not be pulsed with pulse_ms {} because max_pulse_ms is {}"
                .format(self.name, pulse_ms, self.config['max_pulse_ms']))

        return pulse_ms
示例#2
0
    def get_and_verify_pulse_power(self,
                                   pulse_power: Optional[float]) -> float:
        """Return the pulse power to use.

        If pulse_power is None it will use the default_pulse_power. Additionally it will verify the limits.
        """
        if pulse_power is None:
            pulse_power = self.config['default_pulse_power'] if self.config[
                'default_pulse_power'] is not None else 1.0

        if pulse_power and 0 > pulse_power > 1:
            raise AssertionError(
                "Pulse power has to be between 0 and 1 but is {}".format(
                    pulse_power))

        max_pulse_power = 0
        if self.config['max_pulse_power']:
            max_pulse_power = self.config['max_pulse_power']
        elif self.config['default_pulse_power']:
            max_pulse_power = self.config['default_pulse_power']

        if pulse_power > max_pulse_power:
            raise DriverLimitsError(
                "Driver may {} not be pulsed with pulse_power {} because max_pulse_power is {}"
                .format(self.name, pulse_power, max_pulse_power))
        return pulse_power
示例#3
0
    def get_and_verify_hold_power(self, hold_power: Optional[float]) -> float:
        """Return the hold power to use.

        If hold_power is None it will use the default_hold_power. Additionally it will verify the limits.
        """
        if hold_power is None and self.config['default_hold_power']:
            hold_power = self.config['default_hold_power']

        if hold_power is None and self.config['max_hold_power']:
            hold_power = self.config['max_hold_power']

        if hold_power is None and self.config['allow_enable']:
            hold_power = 1.0

        if hold_power is None:
            hold_power = 0.0

        if hold_power and 0 > hold_power > 1:
            raise AssertionError(
                "Hold_power has to be between 0 and 1 but is {}".format(
                    hold_power))

        max_hold_power = 0  # type: float
        if self.config['max_hold_power']:
            max_hold_power = self.config['max_hold_power']
        elif self.config['allow_enable']:
            max_hold_power = 1.0
        elif self.config['default_hold_power']:
            max_hold_power = self.config['default_hold_power']

        if hold_power > max_hold_power:
            raise DriverLimitsError(
                "Driver {} may not be enabled with hold_power {} because max_hold_power is {}"
                .format(self.name, hold_power, max_hold_power))
        return hold_power
示例#4
0
    def enable(self,
               pulse_ms: int = None,
               pulse_power: float = None,
               hold_power: float = None):
        """Enable a driver by holding it 'on'.

        Args:
        ----
            pulse_ms: The number of milliseconds the driver should be
                enabled for. If no value is provided, the driver will be
                enabled for the value specified in the config dictionary.
            pulse_power: The pulse power. A float between 0.0 and 1.0.
            hold_power: The pulse power. A float between 0.0 and 1.0.

        If this driver is configured with a holdpatter, then this method will use
        that holdpatter to pwm pulse the driver.

        If not, then this method will just enable the driver. As a safety
        precaution, if you want to enable() this driver without pwm, then you
        have to add the following option to this driver in your machine
        configuration files:

        allow_enable: True
        """
        assert self.hw_driver is not None
        pulse_ms = self.get_and_verify_pulse_ms(pulse_ms)

        pulse_power = self.get_and_verify_pulse_power(pulse_power)
        hold_power = self.get_and_verify_hold_power(hold_power)

        if hold_power == 0.0:
            raise DriverLimitsError("Cannot enable driver with hold_power 0.0")

        self.info_log(
            "Enabling Driver with power %s (pulse_ms %sms and pulse_power %s)",
            hold_power, pulse_ms, pulse_power)
        self.hw_driver.enable(
            PulseSettings(power=pulse_power, duration=pulse_ms),
            HoldSettings(power=hold_power))

        if self.config['max_hold_duration']:
            self.delay.add_if_doesnt_exist(
                self.config['max_hold_duration'] * 1000,
                self._enable_limit_reached, "enable_limit_reached")

        # inform bcp clients
        self.machine.bcp.interface.send_driver_event(
            action="enable",
            name=self.name,
            number=self.config['number'],
            pulse_ms=pulse_ms,
            pulse_power=pulse_power,
            hold_power=hold_power)
示例#5
0
    def enable(self,
               pulse_ms: int = None,
               pulse_power: float = None,
               hold_power: float = None,
               max_wait_ms: int = None):
        """Enable a driver by holding it 'on'.

        Args:
        ----
            pulse_ms: The number of milliseconds the driver should be
                enabled for. If no value is provided, the driver will be
                enabled for the value specified in the config dictionary.
            pulse_power: The pulse power. A float between 0.0 and 1.0.
            hold_power: The pulse power. A float between 0.0 and 1.0.
            max_wait_ms: Maximum time this pulse may be delayed for PSU optimization.

        If this driver is configured with a holdpatter, then this method will use
        that holdpatter to pwm pulse the driver.

        If not, then this method will just enable the driver. As a safety
        precaution, if you want to enable() this driver without pwm, then you
        have to add the following option to this driver in your machine
        configuration files:

        allow_enable: True
        """
        assert self.hw_driver is not None
        pulse_ms = self.get_and_verify_pulse_ms(pulse_ms)
        wait_ms = self._notify_psu_and_get_wait_ms(pulse_ms, max_wait_ms)

        pulse_power = self.get_and_verify_pulse_power(pulse_power)
        hold_power = self.get_and_verify_hold_power(hold_power)

        if hold_power == 0.0:
            raise DriverLimitsError("Cannot enable driver with hold_power 0.0")

        if wait_ms > 0:
            self.debug_log(
                "Delaying enable by %sms pulse_ms: %sms (%s pulse_power %s hold_power)",
                wait_ms, pulse_ms, pulse_power, hold_power)
            self.delay.add(wait_ms,
                           self._enable_now,
                           pulse_ms=pulse_ms,
                           pulse_power=pulse_power,
                           hold_power=hold_power)
        else:
            self._enable_now(pulse_ms, pulse_power, hold_power)