Skip to content

Commit

Permalink
Patch LIN_ADVANCE for style and forward-compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 6, 2016
1 parent ab19e42 commit ac3c862
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 164 deletions.
10 changes: 5 additions & 5 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,13 @@
#define D_FILAMENT 2.85
#endif

//Implementation of a linear pressure control
//Assumption: advance = k * (delta velocity)
//K=0 means advance disabled. A good value for a gregs wade extruder will be around K=75
#define LIN_ADVANCE
// Implementation of a linear pressure control
// Assumption: advance = k * (delta velocity)
// K=0 means advance disabled. A good value for a gregs wade extruder will be around K=75
//#define LIN_ADVANCE

#if ENABLED(LIN_ADVANCE)
#define LIN_K 75
#define LIN_ADVANCE_K 75
#endif

// @section extras
Expand Down
4 changes: 4 additions & 0 deletions Marlin/Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ void idle(

void manage_inactivity(bool ignore_stepper_queue = false);

#if ENABLED(DUAL_X_CARRIAGE)
extern bool extruder_duplication_enabled;
#endif

#if ENABLED(DUAL_X_CARRIAGE) && HAS_X_ENABLE && HAS_X2_ENABLE
#define enable_x() do { X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); } while (0)
#define disable_x() do { X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; } while (0)
Expand Down
14 changes: 7 additions & 7 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6155,13 +6155,13 @@ inline void gcode_M503() {
#endif // DUAL_X_CARRIAGE

#if ENABLED(LIN_ADVANCE)
/**
* M905: Set advance factor
*/
inline void gcode_M905() {
stepper.synchronize();
stepper.advance_M905();
}
/**
* M905: Set advance factor
*/
inline void gcode_M905() {
stepper.synchronize();
stepper.advance_M905();
}
#endif

/**
Expand Down
8 changes: 7 additions & 1 deletion Marlin/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,20 @@

#endif // AUTO_BED_LEVELING_FEATURE

/**
* Advance Extrusion
*/
#if ENABLED(ADVANCE) && ENABLED(LIN_ADVANCE)
#error You can enable ADVANCE or LIN_ADVANCE, but not both.
#endif

/**
* Filament Width Sensor
*/
#if ENABLED(FILAMENT_WIDTH_SENSOR) && !HAS_FILAMENT_WIDTH_SENSOR
#error FILAMENT_WIDTH_SENSOR requires a FILWIDTH_PIN to be defined.
#endif


/**
* ULTIPANEL encoder
*/
Expand Down
31 changes: 18 additions & 13 deletions Marlin/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,24 +966,28 @@ void Planner::check_axes_activity() {
// the maximum junction speed and may always be ignored for any speed reduction checks.
block->nominal_length_flag = (block->nominal_speed <= v_allowable);
block->recalculate_flag = true; // Always calculate trapezoid for new block

#ifdef LIN_ADVANCE
//bse = allsteps: A problem occures if there is a very tiny move before a retract.
//In this case, the retract and the move will be executed together. This leads to an enormus amount advance steps due to a hughe e_acceleration.
//The math is correct, but you don't want a retract move done with advance! This situation has to be filtered out.
if ((!bse || (!bsx && !bsy && !bsz)) || (stepper.get_advance_k() == 0) || (bse == allsteps)) {

// Update previous path unit_vector and nominal speed
for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = current_speed[i];
previous_nominal_speed = block->nominal_speed;

#if ENABLED(LIN_ADVANCE)

// bse == allsteps: A problem occurs when there's a very tiny move before a retract.
// In this case, the retract and the move will be executed together.
// This leads to an enormous number of advance steps due to a huge e_acceleration.
// The math is correct, but you don't want a retract move done with advance!
// So this situation is filtered out here.
if (!bse || (!bsx && !bsy && !bsz) || stepper.get_advance_k() == 0 || bse == allsteps) {
block->use_advance_lead = false;
} else {
}
else {
block->use_advance_lead = true;
block->e_speed_multiplier8 = (block->steps[E_AXIS] << 8) / block->step_event_count;
}
#endif

// Update previous path unit_vector and nominal speed
for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = current_speed[i];
previous_nominal_speed = block->nominal_speed;
#elif ENABLED(ADVANCE)

#if ENABLED(ADVANCE)
// Calculate advance rate
if (!bse || (!bsx && !bsy && !bsz)) {
block->advance_rate = 0;
Expand All @@ -1002,7 +1006,8 @@ void Planner::check_axes_activity() {
SERIAL_ECHOPGM("advance rate :");
SERIAL_ECHOLN(block->advance_rate/256.0);
*/
#endif // ADVANCE

#endif // ADVANCE or LIN_ADVANCE

calculate_trapezoid_for_block(block, block->entry_speed / block->nominal_speed, safe_speed / block->nominal_speed);

Expand Down
14 changes: 5 additions & 9 deletions Marlin/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ typedef struct {

unsigned char direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)

#if ENABLED(ADVANCE)
// Advance extrusion
#if ENABLED(LIN_ADVANCE)
bool use_advance_lead;
int e_speed_multiplier8; // Factorised by 2^8 to avoid float
#elif ENABLED(ADVANCE)
long advance_rate;
volatile long initial_advance;
volatile long final_advance;
float advance;
#endif
#ifdef LIN_ADVANCE
bool use_advance_lead;
int e_speed_multiplier8; //factorised by 2^8 to avoid float
#endif

// Fields used by the motion planner to manage acceleration
float nominal_speed; // The nominal speed for this block in mm/sec
Expand Down Expand Up @@ -169,10 +169,6 @@ class Planner {
static long axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
#endif

#if ENABLED(DUAL_X_CARRIAGE)
extern bool extruder_duplication_enabled;
#endif

public:

Planner();
Expand Down
Loading

0 comments on commit ac3c862

Please sign in to comment.