Fix FILAMENT_WIDTH_SENSOR infinite loop issue

Addressing #6992 and #5851
This commit is contained in:
Scott Lahteine 2017-06-23 14:48:02 -05:00
parent a18324bc8d
commit a9f8e518bf
5 changed files with 15 additions and 15 deletions

View File

@ -370,9 +370,9 @@ extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
extern bool filament_sensor; // Flag that filament sensor readings should control extrusion 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 extern float filament_width_nominal, // Theoretical filament diameter i.e., 3.00 or 1.75
filament_width_meas; // Measured filament diameter filament_width_meas; // Measured filament diameter
extern int8_t measurement_delay[]; // Ring buffer to delay measurement extern uint8_t meas_delay_cm, // Delay distance
extern int filwidth_delay_index[2]; // Ring buffer indexes. Used by planner, temperature, and main code measurement_delay[]; // Ring buffer to delay measurement
extern int meas_delay_cm; // Delay distance extern int8_t filwidth_delay_index[2]; // Ring buffer indexes. Used by planner, temperature, and main code
#endif #endif
#if ENABLED(ADVANCED_PAUSE_FEATURE) #if ENABLED(ADVANCED_PAUSE_FEATURE)

View File

@ -630,9 +630,9 @@ float cartes[XYZ] = { 0 };
bool filament_sensor = false; // M405 turns on filament sensor control. M406 turns it off. 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. float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA, // Nominal filament width. Change with M404.
filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; // Measured filament diameter filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; // Measured filament diameter
int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1]; // Ring buffer to delayed measurement. Store extruder factor after subtracting 100 uint8_t meas_delay_cm = MEASUREMENT_DELAY_CM, // Distance delay setting
int filwidth_delay_index[2] = { 0, -1 }; // Indexes into ring buffer measurement_delay[MAX_MEASUREMENT_DELAY + 1]; // Ring buffer to delayed measurement. Store extruder factor after subtracting 100
int meas_delay_cm = MEASUREMENT_DELAY_CM; // Distance delay setting int8_t filwidth_delay_index[2] = { 0, -1 }; // Indexes into ring buffer
#endif #endif
#if ENABLED(FILAMENT_RUNOUT_SENSOR) #if ENABLED(FILAMENT_RUNOUT_SENSOR)
@ -8898,11 +8898,11 @@ inline void gcode_M400() { stepper.synchronize(); }
inline void gcode_M405() { inline void gcode_M405() {
// This is technically a linear measurement, but since it's quantized to centimeters and is a different unit than // 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_int() instead of parser.value_linear_units(). // everything else, it uses parser.value_int() instead of parser.value_linear_units().
if (parser.seen('D')) meas_delay_cm = parser.value_int(); if (parser.seen('D')) meas_delay_cm = parser.value_byte();
NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY); NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY);
if (filwidth_delay_index[1] == -1) { // Initialize the ring buffer if not done since startup if (filwidth_delay_index[1] == -1) { // Initialize the ring buffer if not done since startup
const int temp_ratio = thermalManager.widthFil_to_size_ratio() - 100; // -100 to scale within a signed byte const uint8_t temp_ratio = thermalManager.widthFil_to_size_ratio() - 100; // -100 to scale within a signed byte
for (uint8_t i = 0; i < COUNT(measurement_delay); ++i) for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
measurement_delay[i] = temp_ratio; measurement_delay[i] = temp_ratio;

View File

@ -1103,12 +1103,12 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM; while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
// Convert into an index into the measurement array // Convert into an index into the measurement array
filwidth_delay_index[0] = (int)(filwidth_delay_dist * 0.1 + 0.0001); filwidth_delay_index[0] = int8_t(filwidth_delay_dist * 0.1);
// If the index has changed (must have gone forward)... // If the index has changed (must have gone forward)...
if (filwidth_delay_index[0] != filwidth_delay_index[1]) { if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
filwidth_e_count = 0; // Reset the E movement counter filwidth_e_count = 0; // Reset the E movement counter
const int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char const uint8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
do { do {
filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
measurement_delay[filwidth_delay_index[1]] = meas_sample; // Store the measurement measurement_delay[filwidth_delay_index[1]] = meas_sample; // Store the measurement

View File

@ -180,7 +180,7 @@ int16_t Temperature::minttemp_raw[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_RAW_LO_TE
#endif #endif
#if ENABLED(FILAMENT_WIDTH_SENSOR) #if ENABLED(FILAMENT_WIDTH_SENSOR)
int16_t Temperature::meas_shift_index; // Index of a delayed sample in buffer int8_t Temperature::meas_shift_index; // Index of a delayed sample in buffer
#endif #endif
#if HAS_AUTO_FAN #if HAS_AUTO_FAN
@ -196,7 +196,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS],
#endif #endif
#if ENABLED(FILAMENT_WIDTH_SENSOR) #if ENABLED(FILAMENT_WIDTH_SENSOR)
int Temperature::current_raw_filwidth = 0; //Holds measured filament diameter - one extruder only uint16_t Temperature::current_raw_filwidth = 0; // Measured filament diameter - one extruder only
#endif #endif
#if ENABLED(PROBING_HEATERS_OFF) #if ENABLED(PROBING_HEATERS_OFF)
@ -957,7 +957,7 @@ void Temperature::updateTemperaturesFromRawValues() {
// Convert raw Filament Width to millimeters // Convert raw Filament Width to millimeters
float Temperature::analog2widthFil() { float Temperature::analog2widthFil() {
return current_raw_filwidth / 16383.0 * 5.0; return current_raw_filwidth * 5.0 * (1.0 / 16383.0);
//return current_raw_filwidth; //return current_raw_filwidth;
} }

View File

@ -247,7 +247,7 @@ class Temperature {
#endif #endif
#if ENABLED(FILAMENT_WIDTH_SENSOR) #if ENABLED(FILAMENT_WIDTH_SENSOR)
static int16_t meas_shift_index; // Index of a delayed sample in buffer static int8_t meas_shift_index; // Index of a delayed sample in buffer
#endif #endif
#if HAS_AUTO_FAN #if HAS_AUTO_FAN
@ -255,7 +255,7 @@ class Temperature {
#endif #endif
#if ENABLED(FILAMENT_WIDTH_SENSOR) #if ENABLED(FILAMENT_WIDTH_SENSOR)
static int current_raw_filwidth; //Holds measured filament diameter - one extruder only static uint16_t current_raw_filwidth; // Measured filament diameter - one extruder only
#endif #endif
#if ENABLED(PROBING_HEATERS_OFF) #if ENABLED(PROBING_HEATERS_OFF)