Пример #1
0
 def __init__(self, printer, config):
     self.printer = printer
     self.is_pwm = 'pwm' in config.section.split()[0]
     if self.is_pwm:
         self.mcu_pin = pins.setup_pin(printer, 'pwm', config.get('pin'))
         hard_pwm = config.getint('hard_pwm', None, minval=1)
         if hard_pwm is None:
             self.mcu_pin.setup_cycle_time(config.getfloat(
                 'cycle_time', 0.100, above=0.))
         else:
             self.mcu_pin.setup_hard_pwm(hard_pwm)
         self.scale = config.getfloat('scale', 1., above=0.)
     else:
         self.mcu_pin = pins.setup_pin(
             printer, 'digital_out', config.get('pin'))
         self.scale = 1.
     self.mcu_pin.setup_max_duration(0.)
     self.last_value_time = 0.
     self.last_value = config.getfloat(
         'value', 0., minval=0., maxval=self.scale)
     self.is_static = config.section.startswith('static_')
     if self.is_static:
         self.mcu_pin.setup_static_pwm(self.last_value / self.scale)
     else:
         self.mcu_pin.setup_start_value(
             self.last_value, config.getfloat('shutdown_value', 0.,
                                              minval=0., maxval=self.scale))
     self.gcode = printer.objects['gcode']
     self.gcode.register_command("SET_PIN", self.cmd_SET_PIN,
                                 desc=self.cmd_SET_PIN_help)
Пример #2
0
 def __init__(self, printer, config):
     self.printer = printer
     self.is_pwm = 'pwm' in config.get_name().split()[0]
     if self.is_pwm:
         self.mcu_pin = pins.setup_pin(printer, 'pwm', config.get('pin'))
         cycle_time = config.getfloat('cycle_time', 0.100, above=0.)
         hardware_pwm = config.getboolean('hardware_pwm', False)
         self.mcu_pin.setup_cycle_time(cycle_time, hardware_pwm)
         self.scale = config.getfloat('scale', 1., above=0.)
     else:
         self.mcu_pin = pins.setup_pin(printer, 'digital_out',
                                       config.get('pin'))
         self.scale = 1.
     self.mcu_pin.setup_max_duration(0.)
     self.last_value_time = 0.
     self.last_value = config.getfloat(
         'value', 0., minval=0., maxval=self.scale) / self.scale
     self.is_static = config.get_name().startswith('static_')
     if self.is_static:
         self.mcu_pin.setup_start_value(self.last_value, self.last_value,
                                        True)
     else:
         shutdown_value = config.getfloat(
             'shutdown_value', 0., minval=0.,
             maxval=self.scale) / self.scale
         self.mcu_pin.setup_start_value(self.last_value, shutdown_value)
     self.gcode = printer.lookup_object('gcode')
     self.gcode.register_command("SET_PIN",
                                 self.cmd_SET_PIN,
                                 desc=self.cmd_SET_PIN_help)
Пример #3
0
 def __init__(self, printer, config):
     self.name = config.section
     sensor_params = config.getchoice('sensor_type', Sensors)
     self.sensor = sensor_params['class'](config, sensor_params)
     self.min_temp = config.getfloat('min_temp', minval=0.)
     self.max_temp = config.getfloat('max_temp', above=self.min_temp)
     self.min_extrude_temp = config.getfloat(
         'min_extrude_temp', 170., minval=self.min_temp, maxval=self.max_temp)
     self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.)
     self.lock = threading.Lock()
     self.last_temp = 0.
     self.last_temp_time = 0.
     self.target_temp = 0.
     algos = {'watermark': ControlBangBang, 'pid': ControlPID}
     algo = config.getchoice('control', algos)
     heater_pin = config.get('heater_pin')
     if algo is ControlBangBang and self.max_power == 1.:
         self.mcu_pwm = pins.setup_pin(printer, 'digital_out', heater_pin)
     else:
         self.mcu_pwm = pins.setup_pin(printer, 'pwm', heater_pin)
         self.mcu_pwm.setup_cycle_time(PWM_CYCLE_TIME)
     self.mcu_pwm.setup_max_duration(MAX_HEAT_TIME)
     self.mcu_adc = pins.setup_pin(printer, 'adc', config.get('sensor_pin'))
     adc_range = [self.sensor.calc_adc(self.min_temp),
                  self.sensor.calc_adc(self.max_temp)]
     self.mcu_adc.setup_minmax(SAMPLE_TIME, SAMPLE_COUNT,
                               minval=min(adc_range), maxval=max(adc_range))
     self.mcu_adc.setup_adc_callback(REPORT_TIME, self.adc_callback)
     is_fileoutput = self.mcu_adc.get_mcu().is_fileoutput()
     self.can_extrude = self.min_extrude_temp <= 0. or is_fileoutput
     self.control = algo(self, config)
     # pwm caching
     self.next_pwm_time = 0.
     self.last_pwm_value = 0
Пример #4
0
 def __init__(self, printer, config):
     self.pins = {}
     pin_list = [pin.strip() for pin in config.get('pins').split(',')]
     for pin_desc in pin_list:
         self.pins[pin_desc] = {
             'last_value': 0,
             'mcu_pin': pins.setup_pin(printer, 'digital_out', pin_desc)
         }
         self.pins[pin_desc]['mcu_pin'].setup_max_duration(0.)
Пример #5
0
 def __init__(self, config):
     printer = config.get_printer()
     pins.get_printer_pins(printer).register_chip('replicape', self)
     revisions = {'B3': 'B3'}
     config.getchoice('revision', revisions)
     self.host_mcu = mcu.get_printer_mcu(printer, config.get('host_mcu'))
     # Setup enable pin
     self.mcu_pwm_enable = pins.setup_pin(
         printer, 'digital_out', config.get('enable_pin', '!P9_41'))
     self.mcu_pwm_enable.setup_max_duration(0.)
     self.mcu_pwm_start_value = self.mcu_pwm_shutdown_value = False
     # Setup power pins
     self.pins = {
         "power_e": (pca9685_pwm, 5), "power_h": (pca9685_pwm, 3),
         "power_hotbed": (pca9685_pwm, 4),
         "power_fan0": (pca9685_pwm, 7), "power_fan1": (pca9685_pwm, 8),
         "power_fan2": (pca9685_pwm, 9), "power_fan3": (pca9685_pwm, 10) }
     # Setup stepper config
     self.stepper_dacs = {}
     shift_registers = [1, 0, 0, 1, 1]
     for port, name in enumerate('xyzeh'):
         prefix = 'stepper_%s_' % (name,)
         sc = config.getchoice(
             prefix + 'microstep_mode', ReplicapeStepConfig, 'disable')
         if sc is None:
             continue
         sc |= shift_registers[port]
         if config.getboolean(prefix + 'chopper_off_time_high', False):
             sc |= 1<<3
         if config.getboolean(prefix + 'chopper_hysteresis_high', False):
             sc |= 1<<2
         if config.getboolean(prefix + 'chopper_blank_time_high', True):
             sc |= 1<<1
         shift_registers[port] = sc
         channel = port + 11
         cur = config.getfloat(
             prefix + 'current', above=0., maxval=REPLICAPE_MAX_CURRENT)
         self.stepper_dacs[channel] = cur / REPLICAPE_MAX_CURRENT
         self.pins[prefix + 'enable'] = (ReplicapeDACEnable, channel)
     self.enabled_channels = {ch: False for cl, ch in self.pins.values()}
     self.disable_stepper_cmd = "send_spi bus=%d dev=%d msg=%s" % (
         REPLICAPE_SHIFT_REGISTER_BUS, REPLICAPE_SHIFT_REGISTER_DEVICE,
         "".join(["%02x" % (x,) for x in reversed(shift_registers)]))
     if [i for i in [0, 1, 2] if 11+i in self.stepper_dacs]:
         # Enable xyz steppers
         shift_registers[0] &= ~1
     if [i for i in [3, 4] if 11+i in self.stepper_dacs]:
         # Enable eh steppers
         shift_registers[3] &= ~1
     if (config.getboolean('standstill_power_down', False)
         and self.stepper_dacs):
         shift_registers[4] &= ~1
     self.enable_stepper_cmd = "send_spi bus=%d dev=%d msg=%s" % (
         REPLICAPE_SHIFT_REGISTER_BUS, REPLICAPE_SHIFT_REGISTER_DEVICE,
         "".join(["%02x" % (x,) for x in reversed(shift_registers)]))
     self.host_mcu.add_config_cmd(self.disable_stepper_cmd)
     self.last_stepper_time = 0.
Пример #6
0
    def __init__(self, printer, config, name):
        PrinterStepper.__init__(self, printer, config, name)

        self.mcu_endstop = pins.setup_pin(printer, 'endstop',
                                          config.get('endstop_pin'))
        self.mcu_endstop.add_stepper(self.mcu_stepper)
        self.position_min = config.getfloat('position_min', 0.)
        self.position_max = config.getfloat('position_max',
                                            0.,
                                            above=self.position_min)
        self.position_endstop = config.getfloat('position_endstop')

        self.homing_speed = config.getfloat('homing_speed', 5.0, above=0.)
        self.homing_positive_dir = config.getboolean('homing_positive_dir',
                                                     None)
        if self.homing_positive_dir is None:
            axis_len = self.position_max - self.position_min
            if self.position_endstop <= self.position_min + axis_len / 4.:
                self.homing_positive_dir = False
            elif self.position_endstop >= self.position_max - axis_len / 4.:
                self.homing_positive_dir = True
            else:
                raise config.error(
                    "Unable to infer homing_positive_dir in section '%s'" %
                    (config.section, ))
        self.homing_retract_dist = config.getfloat('homing_retract_dist',
                                                   5.,
                                                   above=0.)
        self.homing_stepper_phases = config.getint('homing_stepper_phases',
                                                   None,
                                                   minval=0)
        endstop_accuracy = config.getfloat('homing_endstop_accuracy',
                                           None,
                                           above=0.)
        self.homing_endstop_accuracy = self.homing_endstop_phase = None
        if self.homing_stepper_phases:
            self.homing_endstop_phase = config.getint(
                'homing_endstop_phase',
                None,
                minval=0,
                maxval=self.homing_stepper_phases - 1)
            if endstop_accuracy is None:
                self.homing_endstop_accuracy = self.homing_stepper_phases // 2 - 1
            elif self.homing_endstop_phase is not None:
                self.homing_endstop_accuracy = int(
                    math.ceil(endstop_accuracy * self.inv_step_dist / 2.))
            else:
                self.homing_endstop_accuracy = int(
                    math.ceil(endstop_accuracy * self.inv_step_dist))
            if self.homing_endstop_accuracy >= self.homing_stepper_phases // 2:
                logging.info(
                    "Endstop for %s is not accurate enough for stepper"
                    " phase adjustment" % (name, ))
                self.homing_stepper_phases = None
            if printer.get_start_args().get('debugoutput') is not None:
                self.homing_endstop_accuracy = self.homing_stepper_phases
Пример #7
0
    def __init__(self, printer, config, name):
        self.name = name

        self.step_dist = config.getfloat('step_distance', above=0.)
        self.inv_step_dist = 1. / self.step_dist
        self.min_stop_interval = 0.
        self.mcu_stepper = pins.setup_pin(printer, 'stepper',
                                          config.get('step_pin'))
        dir_pin_params = pins.get_printer_pins(printer).parse_pin_desc(
            config.get('dir_pin'), can_invert=True)
        self.mcu_stepper.setup_dir_pin(dir_pin_params)
        self.mcu_stepper.setup_step_distance(self.step_dist)

        enable_pin = config.get('enable_pin', None)
        if enable_pin is not None:
            self.mcu_enable = pins.setup_pin(printer, 'digital_out',
                                             enable_pin)
            self.mcu_enable.setup_max_duration(0.)
        self.need_motor_enable = True
Пример #8
0
 def __init__(self, config):
     self.last_fan_value = 0.
     self.last_fan_time = 0.
     self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.)
     self.kick_start_time = config.getfloat('kick_start_time', 0.1, minval=0.)
     printer = config.get_printer()
     self.mcu_fan = pins.setup_pin(printer, 'pwm', config.get('pin'))
     self.mcu_fan.setup_max_duration(0.)
     cycle_time = config.getfloat('cycle_time', 0.010, above=0.)
     hardware_pwm = config.getboolean('hardware_pwm', False)
     self.mcu_fan.setup_cycle_time(cycle_time, hardware_pwm)
Пример #9
0
 def __init__(self, printer, config):
     self.last_fan_value = 0.
     self.last_fan_time = 0.
     self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.)
     self.kick_start_time = config.getfloat('kick_start_time',
                                            0.1,
                                            minval=0.)
     self.mcu_fan = pins.setup_pin(printer, 'pwm', config.get('pin'))
     self.mcu_fan.setup_max_duration(0.)
     self.mcu_fan.setup_cycle_time(PWM_CYCLE_TIME)
     self.mcu_fan.setup_hard_pwm(config.getint('hard_pwm', 0))
Пример #10
0
 def __init__(self, printer, config):
     mcu_pwm = pins.setup_pin(printer, 'pwm', config.get('pin'))
     mcu_pwm.setup_max_duration(0.)
     hard_pwm = config.getint('hard_pwm', None, minval=1)
     if hard_pwm is None:
         mcu_pwm.setup_cycle_time(
             config.getfloat('cycle_time', 0.100, above=0.))
     else:
         mcu_pwm.setup_hard_pwm(hard_pwm)
     scale = config.getfloat('scale', 1., above=0.)
     value = config.getfloat('value', minval=0., maxval=scale)
     mcu_pwm.setup_static_pwm(value / scale)
Пример #11
0
 def __init__(self, printer, config):
     self.name = config.section
     if self.name.startswith('stepper_'):
         self.name = self.name[8:]
     self.need_motor_enable = True
     # Stepper definition
     self.mcu_stepper = pins.setup_pin(printer, 'stepper',
                                       config.get('step_pin'))
     dir_pin_params = pins.get_printer_pins(printer).parse_pin_desc(
         config.get('dir_pin'), can_invert=True)
     self.mcu_stepper.setup_dir_pin(dir_pin_params)
     self.step_dist = config.getfloat('step_distance', above=0.)
     self.mcu_stepper.setup_step_distance(self.step_dist)
     self.step_const = self.mcu_stepper.step_const
     self.step_delta = self.mcu_stepper.step_delta
     # Enable pin
     enable_pin = config.get('enable_pin', None)
     self.mcu_enable = None
     if enable_pin is not None:
         self.mcu_enable = pins.setup_pin(printer, 'digital_out',
                                          enable_pin)
         self.mcu_enable.setup_max_duration(0.)
Пример #12
0
 def __init__(self, printer, config):
     self.mcu_servo = pins.setup_pin(printer, 'pwm', config.get('pin'))
     self.mcu_servo.setup_max_duration(0.)
     self.mcu_servo.setup_cycle_time(SERVO_SIGNAL_PERIOD)
     self.min_width = config.getfloat(
         'minimum_pulse_width', .001, above=0., below=SERVO_SIGNAL_PERIOD)
     self.max_width = config.getfloat(
         'maximum_pulse_width', .002
         , above=self.min_width, below=SERVO_SIGNAL_PERIOD)
     self.max_angle = config.getfloat('maximum_servo_angle', 180.)
     self.angle_to_width = (self.max_width - self.min_width) / self.max_angle
     self.width_to_value = 1. / SERVO_SIGNAL_PERIOD
     self.last_value = self.last_value_time = 0.
Пример #13
0
 def __init__(self, printer, config):
     self.name = config.section
     if self.name.startswith('stepper_'):
         self.name = self.name[8:]
     self.need_motor_enable = True
     # Stepper definition
     self.mcu_stepper = pins.setup_pin(
         printer, 'stepper', config.get('step_pin'))
     dir_pin_params = pins.get_printer_pins(printer).lookup_pin(
         'digital_out', config.get('dir_pin'))
     self.mcu_stepper.setup_dir_pin(dir_pin_params)
     self.step_dist = config.getfloat('step_distance', above=0.)
     self.mcu_stepper.setup_step_distance(self.step_dist)
     self.step_const = self.mcu_stepper.step_const
     self.step_delta = self.mcu_stepper.step_delta
     self.enable = lookup_enable_pin(printer, config.get('enable_pin', None))
Пример #14
0
 def __init__(self, printer, config):
     pins.get_printer_pins(printer).register_chip('replicape', self)
     revisions = {'B3': 'B3'}
     config.getchoice('revision', revisions)
     self.host_mcu = mcu.get_printer_mcu(printer, config.get('host_mcu'))
     # Setup enable pin
     self.mcu_enable = pins.setup_pin(printer, 'digital_out',
                                      config.get('enable_pin', '!P9_41'))
     self.mcu_enable.setup_max_duration(0.)
     self.enabled_channels = {}
     # Setup power pins
     self.pins = {
         "power_e": (pca9685_pwm, 5),
         "power_h": (pca9685_pwm, 3),
         "power_hotbed": (pca9685_pwm, 4),
         "power_fan0": (pca9685_pwm, 7),
         "power_fan1": (pca9685_pwm, 8),
         "power_fan2": (pca9685_pwm, 9),
         "power_fan3": (pca9685_pwm, 10)
     }
     # Setup stepper config
     self.stepper_dacs = {}
     shift_registers = [1] * 5
     for port, name in enumerate('xyzeh'):
         prefix = 'stepper_%s_' % (name, )
         sc = config.getchoice(prefix + 'microstep_mode',
                               ReplicapeStepConfig, 'disable')
         if sc is None:
             continue
         if config.getboolean(prefix + 'chopper_off_time_high', False):
             sc |= 1 << 3
         if config.getboolean(prefix + 'chopper_hysteresis_high', False):
             sc |= 1 << 2
         if config.getboolean(prefix + 'chopper_blank_time_high', True):
             sc |= 1 << 1
         shift_registers[port] = sc
         channel = port + 11
         cur = config.getfloat(prefix + 'current',
                               above=0.,
                               maxval=REPLICAPE_MAX_CURRENT)
         self.stepper_dacs[channel] = cur / REPLICAPE_MAX_CURRENT
         self.pins[prefix + 'enable'] = (ReplicapeDACEnable, channel)
     shift_registers.reverse()
     self.host_mcu.add_config_cmd(
         "send_spi bus=%d dev=%d msg=%s" %
         (REPLICAPE_SHIFT_REGISTER_BUS, REPLICAPE_SHIFT_REGISTER_DEVICE,
          "".join(["%02x" % (x, ) for x in shift_registers])))
Пример #15
0
 def __init__(self, config):
     self.printer = config.get_printer()
     self.mcu_servo = pins.setup_pin(self.printer, 'pwm', config.get('pin'))
     self.mcu_servo.setup_max_duration(0.)
     self.mcu_servo.setup_cycle_time(SERVO_SIGNAL_PERIOD)
     self.min_width = config.getfloat(
         'minimum_pulse_width', .001, above=0., below=SERVO_SIGNAL_PERIOD)
     self.max_width = config.getfloat(
         'maximum_pulse_width', .002
         , above=self.min_width, below=SERVO_SIGNAL_PERIOD)
     self.max_angle = config.getfloat('maximum_servo_angle', 180.)
     self.angle_to_width = (self.max_width - self.min_width) / self.max_angle
     self.width_to_value = 1. / SERVO_SIGNAL_PERIOD
     self.last_value = self.last_value_time = 0.
     self.gcode = self.printer.lookup_object('gcode')
     self.gcode.register_command("SET_SERVO", self.cmd_SET_SERVO,
                                 desc=self.cmd_SET_SERVO_help)
Пример #16
0
 def setup_pin(self, pin_params):
     pin_name = pin_params['pin']
     pin = self.printer.objects.get('multi_pin ' + pin_name)
     if pin is not self:
         if pin is None:
             raise pins.error("multi_pin %s not configured" % (pin_name,))
         return pin.setup_pin(pin_params)
     if self.pin_type is not None:
         raise pins.error("Can't setup multi_pin %s twice" % (pin_name,))
     self.pin_type = pin_params['type']
     invert = ""
     if pin_params['invert']:
         invert = "!"
     self.mcu_pins = [
         pins.setup_pin(self.printer, self.pin_type, invert + pin_desc)
         for pin_desc in self.pin_list]
     return self
Пример #17
0
 def __init__(self, printer, config):
     PrinterHomingStepper.__init__(self, printer, config)
     self.endstops = PrinterHomingStepper.get_endstops(self)
     self.extras = []
     self.all_step_const = [self.step_const]
     for i in range(1, 99):
         if not config.has_section(config.section + str(i)):
             break
         extraconfig = config.getsection(config.section + str(i))
         extra = PrinterStepper(printer, extraconfig)
         self.extras.append(extra)
         self.all_step_const.append(extra.step_const)
         extraendstop = extraconfig.get('endstop_pin', None)
         if extraendstop is not None:
             mcu_endstop = pins.setup_pin(printer, 'endstop', extraendstop)
             mcu_endstop.add_stepper(extra.mcu_stepper)
             self.endstops.append((mcu_endstop, extra.name))
         else:
             self.mcu_endstop.add_stepper(extra.mcu_stepper)
     self.step_const = self.step_multi_const
Пример #18
0
 def __init__(self, printer, config):
     PrinterStepper.__init__(self, printer, config)
     # Endstop and its position
     self.mcu_endstop = pins.setup_pin(printer, 'endstop',
                                       config.get('endstop_pin'))
     self.mcu_endstop.add_stepper(self.mcu_stepper)
     self.position_endstop = config.getfloat('position_endstop')
     # Axis range
     self.position_min = config.getfloat('position_min', 0.)
     self.position_max = config.getfloat('position_max',
                                         0.,
                                         above=self.position_min)
     # Homing mechanics
     self.homing_speed = config.getfloat('homing_speed', 5.0, above=0.)
     self.homing_retract_dist = config.getfloat('homing_retract_dist',
                                                5.,
                                                above=0.)
     self.homing_positive_dir = config.getboolean('homing_positive_dir',
                                                  None)
     if self.homing_positive_dir is None:
         axis_len = self.position_max - self.position_min
         if self.position_endstop <= self.position_min + axis_len / 4.:
             self.homing_positive_dir = False
         elif self.position_endstop >= self.position_max - axis_len / 4.:
             self.homing_positive_dir = True
         else:
             raise config.error(
                 "Unable to infer homing_positive_dir in section '%s'" %
                 (config.section, ))
     # Endstop stepper phase position tracking
     self.homing_stepper_phases = config.getint('homing_stepper_phases',
                                                None,
                                                minval=0)
     endstop_accuracy = config.getfloat('homing_endstop_accuracy',
                                        None,
                                        above=0.)
     self.homing_endstop_accuracy = self.homing_endstop_phase = None
     if self.homing_stepper_phases:
         self.homing_endstop_phase = config.getint(
             'homing_endstop_phase',
             None,
             minval=0,
             maxval=self.homing_stepper_phases - 1)
         if self.homing_endstop_phase is not None:
             # Adjust the endstop position so 0.0 is always at a full step
             micro_steps = self.homing_stepper_phases // 4
             phase_offset = (
                 ((self.homing_endstop_phase + micro_steps // 2) %
                  micro_steps) - micro_steps // 2) * self.step_dist
             full_step = micro_steps * self.step_dist
             es_pos = (
                 int(self.position_endstop / full_step + .5) * full_step +
                 phase_offset)
             if es_pos != self.position_endstop:
                 logging.info(
                     "Changing %s endstop position to %.3f"
                     " (from %.3f)", self.name, es_pos,
                     self.position_endstop)
                 self.position_endstop = es_pos
         if endstop_accuracy is None:
             self.homing_endstop_accuracy = self.homing_stepper_phases // 2 - 1
         elif self.homing_endstop_phase is not None:
             self.homing_endstop_accuracy = int(
                 math.ceil(endstop_accuracy * .5 / self.step_dist))
         else:
             self.homing_endstop_accuracy = int(
                 math.ceil(endstop_accuracy / self.step_dist))
         if self.homing_endstop_accuracy >= self.homing_stepper_phases // 2:
             logging.info(
                 "Endstop for %s is not accurate enough for stepper"
                 " phase adjustment", name)
             self.homing_stepper_phases = None
         if self.mcu_endstop.get_mcu().is_fileoutput():
             self.homing_endstop_accuracy = self.homing_stepper_phases
Пример #19
0
 def __init__(self, printer, config):
     pin_list = [pin.strip() for pin in config.get('pins').split(',')]
     for pin_desc in pin_list:
         mcu_pin = pins.setup_pin(printer, 'digital_out', pin_desc)
         mcu_pin.setup_static()