Exemplo n.º 1
0
        public PrinterStepper(ConfigWrapper config)
        {
            var printer = config.get_printer();

            this.name = config.get_name();
            this.need_motor_enable = true;
            // Stepper definition
            var ppins    = printer.lookup_object <PrinterPins>("pins");
            var step_pin = config.get("step_pin");

            this.mcu_stepper = ppins.setup_pin <Mcu_stepper>("stepper", step_pin);
            var dir_pin        = config.get("dir_pin");
            var dir_pin_params = ppins.lookup_pin(dir_pin, can_invert: true);

            mcu_stepper.setup_dir_pin(dir_pin_params);
            var step_dist = config.getfloat("step_distance", above: 0.0);

            mcu_stepper.setup_step_distance(step_dist);
            this.enable = StepperEnablePin.lookup_enable_pin(ppins, config.get("enable_pin", null));
            // Register STEPPER_BUZZ command
            //var force_move = printer.try_load_module(config, "force_move");
            //force_move.register_stepper(this);
            // Wrappers
            this.step_itersolve           = mcu_stepper.step_itersolve;
            this.setup_itersolve          = mcu_stepper.setup_itersolve;
            this.set_stepper_kinematics   = mcu_stepper.set_stepper_kinematics;
            this.set_ignore_move          = mcu_stepper.set_ignore_move;
            this.calc_position_from_coord = mcu_stepper.calc_position_from_coord;
            this.set_position             = mcu_stepper.set_position;
            this.get_commanded_position   = mcu_stepper.get_commanded_position;
            this.set_commanded_position   = mcu_stepper.set_commanded_position;
            this.get_mcu_position         = mcu_stepper.get_mcu_position;
            this.get_step_dist            = mcu_stepper.get_step_dist;
        }
Exemplo n.º 2
0
        public PrinterHeaters(ConfigWrapper config)
        {
            this.printer = config.get_printer();
            // Register TURN_OFF_HEATERS command
            var gcode = this.printer.lookup_object <GCodeParser>("gcode");

            gcode.register_command("TURN_OFF_HEATERS", this.cmd_TURN_OFF_HEATERS, desc: cmd_TURN_OFF_HEATERS_help);
        }
Exemplo n.º 3
0
        public Heater(ConfigWrapper config, ISensor sensor, string gcode_id)
        {
            var printer = config.get_printer();

            this.name     = config.get_name();
            this.gcode_id = gcode_id;
            // Setup sensor
            this.sensor   = sensor;
            this.min_temp = config.getfloat("min_temp", minval: KELVIN_TO_CELCIUS);
            this.max_temp = config.getfloat("max_temp", above: this.min_temp);
            this.sensor.setup_minmax(this.min_temp, this.max_temp);
            this.sensor.setup_callback(this.temperature_callback);
            this.pwm_delay = this.sensor.get_report_time_delta();
            // Setup temperature checks
            this.min_extrude_temp = config.getfloat("min_extrude_temp", 170.0, minval: this.min_temp, maxval: this.max_temp);
            var is_fileoutput = printer.get_start_args().Get("debugoutput") != null;

            this.can_extrude     = this.min_extrude_temp <= 0.0 || is_fileoutput;
            this.max_power       = config.getfloat("max_power", 1.0, above: 0.0, maxval: 1.0);
            this.smooth_time     = config.getfloat("smooth_time", 2.0, above: 0.0);
            this.inv_smooth_time = 1.0 / this.smooth_time;
            this._lock           = new object();
            this.last_temp       = 0.0;
            this.last_temp_time  = 0.0;
            // pwm caching
            this.next_pwm_time  = 0.0;
            this.last_pwm_value = 0.0;
            // Setup control algorithm sub-class
            //var algos = new Dictionary<string, object> { { "watermark", ControlBangBang }, { "pid", ControlPID } };
            //var algo = config.getchoice("control", algos);
            switch (config.get("control"))
            {
            case "watermark": this.control = new ControlBangBang(this, config); break;

            case "pid": this.control = new ControlPID(this, config); break;
            }
            // Setup output heater pin
            var heater_pin = config.get("heater_pin");
            var ppins      = printer.lookup_object <PrinterPins>("pins");

            if (control is ControlBangBang && this.max_power == 1.0)
            {
                this.mcu_pwm = ppins.setup_pin <Mcu_digital_out>("digital_out", heater_pin);
            }
            else
            {
                var pwm            = ppins.setup_pin <Mcu_pwm>("pwm", heater_pin);
                var pwm_cycle_time = config.getfloat("pwm_cycle_time", 0.1, above: 0.0, maxval: this.pwm_delay);
                pwm.setup_cycle_time(pwm_cycle_time);
                this.mcu_pwm = pwm;
            }
            this.mcu_pwm.setup_max_duration(MAX_HEAT_TIME);
            // Load additional modules
            printer.try_load_module(config, $"verify_heater {this.name}");
            printer.try_load_module(config, "pid_calibrate");
        }
Exemplo n.º 4
0
        public ToolHead(ConfigWrapper config)
        {
            this.printer       = config.get_printer();
            this.reactor       = this.printer.get_reactor();
            this.all_mcus      = (from mcus in this.printer.lookup_objects <Mcu>(module: "mcu") select mcus.modul).ToList();
            this.mcu           = this.all_mcus[0];
            this.move_queue    = new MoveQueue();
            this.commanded_pos = Vector4d.Zero;
            this.printer.register_event_handler("klippy:shutdown", _handle_shutdown);
            // Velocity and acceleration control
            this.max_velocity                  = config.getfloat("max_velocity", above: 0.0);
            this.max_accel                     = config.getfloat("max_accel", above: 0.0);
            this.requested_accel_to_decel      = config.getfloat("max_accel_to_decel", this.max_accel * 0.5, above: 0.0);
            this.max_accel_to_decel            = this.requested_accel_to_decel;
            this.square_corner_velocity        = config.getfloat("square_corner_velocity", 5.0, minval: 0.0);
            this.config_max_velocity           = this.max_velocity;
            this.config_max_accel              = this.max_accel;
            this.config_square_corner_velocity = this.square_corner_velocity;
            this.junction_deviation            = 0.0;
            this._calc_junction_deviation();
            // Print time tracking
            this.buffer_time_low       = config.getfloat("buffer_time_low", 1.0, above: 0.0);
            this.buffer_time_high      = config.getfloat("buffer_time_high", 2.0, above: this.buffer_time_low);
            this.buffer_time_start     = config.getfloat("buffer_time_start", 0.25, above: 0.0);
            this.move_flush_time       = config.getfloat("move_flush_time", 0.05, above: 0.0);
            this.print_time            = 0.0;
            this.last_print_start_time = 0.0;
            this.need_check_stall      = -1.0;
            this.print_stall           = 0;
            this.sync_print_time       = true;
            this.idle_flush_print_time = 0.0;
            this.flush_timer           = this.reactor.register_timer(this._flush_handler);
            this.move_queue.set_flush_time(this.buffer_time_high);
            this.printer.try_load_module(config, "idle_timeout");
            this.printer.try_load_module(config, "statistics");
            // Setup iterative solver
            this.cmove = new move();
            // Create kinematics class
            this.extruder = new ExtruderDummy();
            this.move_queue.set_extruder(this.extruder);
            var kin_name = config.getEnum <KinematicType>("kinematics");

            try
            {
                this.kin = KinematicFactory.load_kinematics(kin_name, this, config);
            }
            catch (ConfigException)
            {
                throw;
            }
            catch (PinsException)
            {
                throw;
            }
            catch (Exception ex)
            {
                var msg = $"Error loading kinematics '{kin_name}'";
                logging.Error(msg);
                throw new Exception(msg, ex);
            }
            var gcode = this.printer.lookup_object <GCodeParser>("gcode");

            gcode.register_command("SET_VELOCITY_LIMIT", this.cmd_SET_VELOCITY_LIMIT, desc: cmd_SET_VELOCITY_LIMIT_help);
            gcode.register_command("M204", this.cmd_M204);
        }