FILAMENT_WIDTH_SENSOR feature

This commit is contained in:
Scott Lahteine 2017-09-12 15:02:17 -05:00
parent d5fe0fb02b
commit 4f1eadf41f
10 changed files with 81 additions and 91 deletions

View File

@ -186,15 +186,6 @@ static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL
;
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
bool filament_sensor = false; // M405 turns on filament sensor control. M406 turns it off.
float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA, // Nominal filament width. Change with M404.
filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; // Measured filament diameter
uint8_t meas_delay_cm = MEASUREMENT_DELAY_CM, // Distance delay setting
measurement_delay[MAX_MEASUREMENT_DELAY + 1]; // Ring buffer to delayed measurement. Store extruder factor after subtracting 100
int8_t filwidth_delay_index[2] = { 0, -1 }; // Indexes into ring buffer
#endif
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
static bool filament_ran_out = false;
#endif
@ -667,13 +658,6 @@ static bool pin_is_protected(const int8_t pin) {
#include "gcode/probe/M401_M402.h"
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
#include "gcode/sensor/M404.h"
#include "gcode/sensor/M405.h"
#include "gcode/sensor/M406.h"
#include "gcode/sensor/M407.h"
#endif
void quickstop_stepper() {
stepper.quick_stop();
stepper.synchronize();

View File

@ -211,15 +211,6 @@ extern volatile bool wait_for_heatup;
extern uint8_t baricuda_valve_pressure, baricuda_e_to_p_pressure;
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
extern bool filament_sensor; // Flag that filament sensor readings should control extrusion
extern float filament_width_nominal, // Theoretical filament diameter i.e., 3.00 or 1.75
filament_width_meas; // Measured filament diameter
extern uint8_t meas_delay_cm, // Delay distance
measurement_delay[]; // Ring buffer to delay measurement
extern int8_t filwidth_delay_index[2]; // Ring buffer indexes. Used by planner, temperature, and main code
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE)
extern AdvancedPauseMenuResponse advanced_pause_menu_response;
#endif

View File

@ -20,10 +20,17 @@
*
*/
/**
* M406: Turn off filament sensor for control
*/
void gcode_M406() {
filament_sensor = false;
calculate_volumetric_multipliers(); // Restore correct 'volumetric_multiplier' value
}
#include "../inc/MarlinConfig.h"
#if ENABLED(FILAMENT_WIDTH_SENSOR)
#include "filwidth.h"
bool filament_sensor = false; // M405/M406 turns filament sensor control ON/OFF.
float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA, // Nominal filament width. Change with M404.
filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; // Measured filament diameter
uint8_t meas_delay_cm = MEASUREMENT_DELAY_CM, // Distance delay setting
measurement_delay[MAX_MEASUREMENT_DELAY + 1]; // Ring buffer to delayed measurement. Store extruder factor after subtracting 100
int8_t filwidth_delay_index[2] = { 0, -1 }; // Indexes into ring buffer
#endif // FILAMENT_WIDTH_SENSOR

View File

@ -20,15 +20,16 @@
*
*/
/**
* M404: Display or set (in current units) the nominal filament width (3mm, 1.75mm ) W<3.0>
*/
void gcode_M404() {
if (parser.seen('W')) {
filament_width_nominal = parser.value_linear_units();
}
else {
SERIAL_PROTOCOLPGM("Filament dia (nominal mm):");
SERIAL_PROTOCOLLN(filament_width_nominal);
}
}
#ifndef __FILWIDTH_H__
#define __FILWIDTH_H__
#include "../inc/MarlinConfig.h"
extern bool filament_sensor; // M405/M406 turns filament sensor control ON/OFF.
extern float filament_width_nominal, // Nominal filament width. Change with M404.
filament_width_meas; // Measured filament diameter
extern uint8_t meas_delay_cm, // Distance delay setting
measurement_delay[MAX_MEASUREMENT_DELAY + 1]; // Ring buffer to delayed measurement. Store extruder factor after subtracting 100
extern int8_t filwidth_delay_index[2]; // Indexes into ring buffer
#endif // __FILWIDTH_H__

View File

@ -20,10 +20,33 @@
*
*/
#include "../../../inc/MarlinConfig.h"
#if ENABLED(FILAMENT_WIDTH_SENSOR)
#include "../../../feature/filwidth.h"
#include "../../../module/planner.h"
#include "../../../module/temperature.h"
#include "../../../Marlin.h"
#include "../../gcode.h"
/**
* M404: Display or set (in current units) the nominal filament width (3mm, 1.75mm ) W<3.0>
*/
void GcodeSuite::M404() {
if (parser.seen('W')) {
filament_width_nominal = parser.value_linear_units();
}
else {
SERIAL_PROTOCOLPGM("Filament dia (nominal mm):");
SERIAL_PROTOCOLLN(filament_width_nominal);
}
}
/**
* M405: Turn on filament sensor for control
*/
void gcode_M405() {
void GcodeSuite::M405() {
// This is technically a linear measurement, but since it's quantized to centimeters and is a different
// unit than everything else, it uses parser.value_byte() instead of parser.value_linear_units().
if (parser.seen('D')) {
@ -47,3 +70,21 @@ void gcode_M405() {
//SERIAL_PROTOCOLPGM("Extrusion ratio(%):");
//SERIAL_PROTOCOL(planner.flow_percentage[active_extruder]);
}
/**
* M406: Turn off filament sensor for control
*/
void GcodeSuite::M406() {
filament_sensor = false;
calculate_volumetric_multipliers(); // Restore correct 'volumetric_multiplier' value
}
/**
* M407: Get measured filament diameter on serial output
*/
void GcodeSuite::M407() {
SERIAL_PROTOCOLPGM("Filament dia (measured mm):");
SERIAL_PROTOCOLLN(filament_width_meas);
}
#endif // FILAMENT_WIDTH_SENSOR

View File

@ -102,11 +102,6 @@ void GcodeSuite::get_destination_from_command() {
//
// Placeholders for non-migrated codes
//
extern void gcode_G0_G1(
#if IS_SCARA
bool fast_move=false
#endif
);
extern void gcode_G2_G3(bool clockwise);
extern void gcode_G4();
extern void gcode_G5();
@ -216,10 +211,6 @@ extern void gcode_M381();
extern void gcode_M400();
extern void gcode_M401();
extern void gcode_M402();
extern void gcode_M404();
extern void gcode_M405();
extern void gcode_M406();
extern void gcode_M407();
extern void gcode_M410();
extern void gcode_M428();
extern void gcode_M500();
@ -871,16 +862,16 @@ void GcodeSuite::process_next_command() {
#if ENABLED(FILAMENT_WIDTH_SENSOR)
case 404: // M404: Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or display nominal filament width
gcode_M404();
M404();
break;
case 405: // M405: Turn on filament sensor for control
gcode_M405();
M405();
break;
case 406: // M406: Turn off filament sensor for control
gcode_M406();
M406();
break;
case 407: // M407: Display measured filament diameter
gcode_M407();
M407();
break;
#endif // FILAMENT_WIDTH_SENSOR

View File

@ -1,29 +0,0 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* M407: Get measured filament diameter on serial output
*/
void gcode_M407() {
SERIAL_PROTOCOLPGM("Filament dia (measured mm):");
SERIAL_PROTOCOLLN(filament_width_meas);
}

View File

@ -47,10 +47,6 @@
#include "../feature/filwidth.h"
#endif
#if HAS_BED_PROBE
#include "../module/probe.h"
#endif
#if ENABLED(BLTOUCH)
#include "../module/endstops.h"
#endif

View File

@ -72,6 +72,10 @@
#include "../feature/bedlevel/bedlevel.h"
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
#include "../feature/filwidth.h"
#endif
Planner planner;
// public:

View File

@ -45,6 +45,10 @@
#include "printcounter.h"
#if ENABLED(FILAMENT_WIDTH_SENSOR)
#include "../feature/filwidth.h"
#endif
#ifdef K1 // Defined in Configuration.h in the PID settings
#define K2 (1.0-K1)
#endif