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
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
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 """ 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)) # 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)
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. """ 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