Skip to content

Commit

Permalink
Option to disable all volumetric extrusion
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 20, 2017
1 parent e6f46f3 commit 4359810
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -121,7 +121,7 @@ script:
- opt_enable NUM_SERVOS Z_ENDSTOP_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE
- opt_set NUM_SERVOS 1
- opt_enable AUTO_BED_LEVELING_3POINT DEBUG_LEVELING_FEATURE EEPROM_SETTINGS EEPROM_CHITCHAT
- opt_enable_adv EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES AUTOTEMP G38_PROBE_TARGET
- opt_enable_adv NO_VOLUMETRICS EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES AUTOTEMP G38_PROBE_TARGET
- build_marlin
#
# Test MESH_BED_LEVELING feature, with LCD
Expand Down
19 changes: 13 additions & 6 deletions Marlin/Configuration_adv.h
Expand Up @@ -1376,13 +1376,20 @@
#define EXTENDED_CAPABILITIES_REPORT

/**
* Volumetric extrusion default state
* Activate to make volumetric extrusion the default method,
* with DEFAULT_NOMINAL_FILAMENT_DIA as the default diameter.
*
* M200 D0 to disable, M200 Dn to set a new diameter.
* Disable all Volumetric extrusion options
*/
//#define VOLUMETRIC_DEFAULT_ON
//#define NO_VOLUMETRICS

#if DISABLED(NO_VOLUMETRICS)
/**
* Volumetric extrusion default state
* Activate to make volumetric extrusion the default method,
* with DEFAULT_NOMINAL_FILAMENT_DIA as the default diameter.
*
* M200 D0 to disable, M200 Dn to set a new diameter.
*/
//#define VOLUMETRIC_DEFAULT_ON
#endif

/**
* Enable this option for a leaner build of Marlin that removes all
Expand Down
45 changes: 26 additions & 19 deletions Marlin/Marlin_main.cpp
Expand Up @@ -8669,25 +8669,29 @@ inline void gcode_M121() { endstops.enable_globally(false); }

#endif // HAS_COLOR_LEDS

/**
* M200: Set filament diameter and set E axis units to cubic units
*
* T<extruder> - Optional extruder number. Current extruder if omitted.
* D<linear> - Diameter of the filament. Use "D0" to switch back to linear units on the E axis.
*/
inline void gcode_M200() {
#if DISABLED(NO_VOLUMETRICS)

/**
* M200: Set filament diameter and set E axis units to cubic units
*
* T<extruder> - Optional extruder number. Current extruder if omitted.
* D<linear> - Diameter of the filament. Use "D0" to switch back to linear units on the E axis.
*/
inline void gcode_M200() {

if (get_target_extruder_from_command(200)) return;
if (get_target_extruder_from_command(200)) return;

if (parser.seen('D')) {
// setting any extruder filament size disables volumetric on the assumption that
// slicers either generate in extruder values as cubic mm or as as filament feeds
// for all extruders
if ( (parser.volumetric_enabled = (parser.value_linear_units() != 0.0)) )
planner.set_filament_size(target_extruder, parser.value_linear_units());
if (parser.seen('D')) {
// setting any extruder filament size disables volumetric on the assumption that
// slicers either generate in extruder values as cubic mm or as as filament feeds
// for all extruders
if ( (parser.volumetric_enabled = (parser.value_linear_units() != 0.0)) )
planner.set_filament_size(target_extruder, parser.value_linear_units());
}
planner.calculate_volumetric_multipliers();
}
planner.calculate_volumetric_multipliers();
}

#endif // !NO_VOLUMETRICS

/**
* M201: Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000)
Expand Down Expand Up @@ -12036,9 +12040,12 @@ void process_parsed_command() {
#endif
#endif

case 200: // M200: Set filament diameter, E to cubic units
gcode_M200();
break;
#if DISABLED(NO_VOLUMETRICS)
case 200: // M200: Set filament diameter, E to cubic units
gcode_M200();
break;
#endif

case 201: // M201: Set max acceleration for print moves (units/s^2)
gcode_M201();
break;
Expand Down
8 changes: 6 additions & 2 deletions Marlin/SanityCheck.h
Expand Up @@ -901,8 +901,12 @@ static_assert(1 >= 0
/**
* Filament Width Sensor
*/
#if ENABLED(FILAMENT_WIDTH_SENSOR) && !HAS_FILAMENT_WIDTH_SENSOR
#error "FILAMENT_WIDTH_SENSOR requires a FILWIDTH_PIN to be defined."
#if ENABLED(FILAMENT_WIDTH_SENSOR)
#if !HAS_FILAMENT_WIDTH_SENSOR
#error "FILAMENT_WIDTH_SENSOR requires a FILWIDTH_PIN to be defined."
#elif ENABLED(NO_VOLUMETRICS)
#error "FILAMENT_WIDTH_SENSOR requires NO_VOLUMETRICS to be disabled."
#endif
#endif

/**
Expand Down
123 changes: 72 additions & 51 deletions Marlin/configuration_store.cpp
Expand Up @@ -238,7 +238,9 @@ void MarlinSettings::postprocess() {
thermalManager.updatePID();
#endif

planner.calculate_volumetric_multipliers();
#if DISABLED(NO_VOLUMETRICS)
planner.calculate_volumetric_multipliers();
#endif

#if HAS_HOME_OFFSET || ENABLED(DUAL_X_CARRIAGE)
// Software endstops depend on home_offset
Expand Down Expand Up @@ -566,13 +568,20 @@ void MarlinSettings::postprocess() {
EEPROM_WRITE(swap_retract_recover_length);
EEPROM_WRITE(swap_retract_recover_feedrate_mm_s);

EEPROM_WRITE(parser.volumetric_enabled);
//
// Volumetric & Filament Size
//
#if DISABLED(NO_VOLUMETRICS)

// Save filament sizes
for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
if (q < COUNT(planner.filament_size)) dummy = planner.filament_size[q];
EEPROM_WRITE(dummy);
}
EEPROM_WRITE(parser.volumetric_enabled);

// Save filament sizes
for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
if (q < COUNT(planner.filament_size)) dummy = planner.filament_size[q];
EEPROM_WRITE(dummy);
}

#endif // !NO_VOLUMETRICS

// Save TMC2130 or TMC2208 Configuration, and placeholder values
uint16_t val;
Expand Down Expand Up @@ -1053,12 +1062,16 @@ void MarlinSettings::postprocess() {
//
// Volumetric & Filament Size
//
#if DISABLED(NO_VOLUMETRICS)

EEPROM_READ(parser.volumetric_enabled);
for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
EEPROM_READ(dummy);
if (q < COUNT(planner.filament_size)) planner.filament_size[q] = dummy;
}
EEPROM_READ(parser.volumetric_enabled);

for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
EEPROM_READ(dummy);
if (q < COUNT(planner.filament_size)) planner.filament_size[q] = dummy;
}

#endif

//
// TMC2130 Stepper Current
Expand Down Expand Up @@ -1502,15 +1515,19 @@ void MarlinSettings::reset() {
swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
#endif // FWRETRACT

parser.volumetric_enabled =
#if ENABLED(VOLUMETRIC_DEFAULT_ON)
true
#else
false
#endif
;
for (uint8_t q = 0; q < COUNT(planner.filament_size); q++)
planner.filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
#if DISABLED(NO_VOLUMETRICS)

parser.volumetric_enabled =
#if ENABLED(VOLUMETRIC_DEFAULT_ON)
true
#else
false
#endif
;
for (uint8_t q = 0; q < COUNT(planner.filament_size); q++)
planner.filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;

#endif

endstops.enable_globally(
#if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
Expand Down Expand Up @@ -1648,46 +1665,50 @@ void MarlinSettings::reset() {

SERIAL_EOL();

/**
* Volumetric extrusion M200
*/
if (!forReplay) {
CONFIG_ECHO_START;
SERIAL_ECHOPGM("Filament settings:");
if (parser.volumetric_enabled)
SERIAL_EOL();
else
SERIAL_ECHOLNPGM(" Disabled");
}
#if DISABLED(NO_VOLUMETRICS)

/**
* Volumetric extrusion M200
*/
if (!forReplay) {
CONFIG_ECHO_START;
SERIAL_ECHOPGM("Filament settings:");
if (parser.volumetric_enabled)
SERIAL_EOL();
else
SERIAL_ECHOLNPGM(" Disabled");
}

CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" M200 D", LINEAR_UNIT(planner.filament_size[0]));
SERIAL_EOL();
#if EXTRUDERS > 1
CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" M200 T1 D", LINEAR_UNIT(planner.filament_size[1]));
SERIAL_ECHOPAIR(" M200 D", LINEAR_UNIT(planner.filament_size[0]));
SERIAL_EOL();
#if EXTRUDERS > 2
#if EXTRUDERS > 1
CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" M200 T2 D", LINEAR_UNIT(planner.filament_size[2]));
SERIAL_ECHOPAIR(" M200 T1 D", LINEAR_UNIT(planner.filament_size[1]));
SERIAL_EOL();
#if EXTRUDERS > 3
#if EXTRUDERS > 2
CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" M200 T3 D", LINEAR_UNIT(planner.filament_size[3]));
SERIAL_ECHOPAIR(" M200 T2 D", LINEAR_UNIT(planner.filament_size[2]));
SERIAL_EOL();
#if EXTRUDERS > 4
#if EXTRUDERS > 3
CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" M200 T4 D", LINEAR_UNIT(planner.filament_size[4]));
SERIAL_ECHOPAIR(" M200 T3 D", LINEAR_UNIT(planner.filament_size[3]));
SERIAL_EOL();
#endif // EXTRUDERS > 4
#endif // EXTRUDERS > 3
#endif // EXTRUDERS > 2
#endif // EXTRUDERS > 1
#if EXTRUDERS > 4
CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" M200 T4 D", LINEAR_UNIT(planner.filament_size[4]));
SERIAL_EOL();
#endif // EXTRUDERS > 4
#endif // EXTRUDERS > 3
#endif // EXTRUDERS > 2
#endif // EXTRUDERS > 1

if (!parser.volumetric_enabled) {
CONFIG_ECHO_START;
SERIAL_ECHOLNPGM(" M200 D0");
}
if (!parser.volumetric_enabled) {
CONFIG_ECHO_START;
SERIAL_ECHOLNPGM(" M200 D0");
}

#endif

if (!forReplay) {
CONFIG_ECHO_START;
Expand Down
49 changes: 28 additions & 21 deletions Marlin/planner.cpp
Expand Up @@ -94,10 +94,13 @@ float Planner::max_feedrate_mm_s[XYZE_N], // Max speeds in mm per second

int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder

float Planner::e_factor[EXTRUDERS], // The flow percentage and volumetric multiplier combine to scale E movement
Planner::filament_size[EXTRUDERS], // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
Planner::volumetric_area_nominal = CIRCLE_AREA((DEFAULT_NOMINAL_FILAMENT_DIA) * 0.5), // Nominal cross-sectional area
Planner::volumetric_multiplier[EXTRUDERS]; // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
float Planner::e_factor[EXTRUDERS]; // The flow percentage and volumetric multiplier combine to scale E movement

#if DISABLED(NO_VOLUMETRICS)
float Planner::filament_size[EXTRUDERS], // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
Planner::volumetric_area_nominal = CIRCLE_AREA((DEFAULT_NOMINAL_FILAMENT_DIA) * 0.5), // Nominal cross-sectional area
Planner::volumetric_multiplier[EXTRUDERS]; // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
#endif

uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
Expand Down Expand Up @@ -550,25 +553,29 @@ void Planner::check_axes_activity() {
#endif
}

/**
* Get a volumetric multiplier from a filament diameter.
* This is the reciprocal of the circular cross-section area.
* Return 1.0 with volumetric off or a diameter of 0.0.
*/
inline float calculate_volumetric_multiplier(const float &diameter) {
return (parser.volumetric_enabled && diameter) ? 1.0 / CIRCLE_AREA(diameter * 0.5) : 1.0;
}
#if DISABLED(NO_VOLUMETRICS)

/**
* Convert the filament sizes into volumetric multipliers.
* The multiplier converts a given E value into a length.
*/
void Planner::calculate_volumetric_multipliers() {
for (uint8_t i = 0; i < COUNT(filament_size); i++) {
volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
refresh_e_factor(i);
/**
* Get a volumetric multiplier from a filament diameter.
* This is the reciprocal of the circular cross-section area.
* Return 1.0 with volumetric off or a diameter of 0.0.
*/
inline float calculate_volumetric_multiplier(const float &diameter) {
return (parser.volumetric_enabled && diameter) ? 1.0 / CIRCLE_AREA(diameter * 0.5) : 1.0;
}
}

/**
* Convert the filament sizes into volumetric multipliers.
* The multiplier converts a given E value into a length.
*/
void Planner::calculate_volumetric_multipliers() {
for (uint8_t i = 0; i < COUNT(filament_size); i++) {
volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
refresh_e_factor(i);
}
}

#endif // !NO_VOLUMETRICS

#if ENABLED(FILAMENT_WIDTH_SENSOR)
/**
Expand Down

0 comments on commit 4359810

Please sign in to comment.