From 5f6371c53d3374cc91fc53f5682b52c98136a775 Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Fri, 1 Jul 2016 15:37:16 -0400 Subject: [PATCH] M220: add support for feedrate override percentage. Similar to M221 which sets a variable flow rate percentage, add support for M220 which sets a percentage modifier for the feedrate, F. It seems a little disturbing that the flow rate modifies the next G1 command and does not touch the buffered commands, but this seems like the only reasonable thing to do since the M221 setting could be embedded in the source gcode for some use cases. Perhaps an "immediate" setting using P1 could be considered later if needed. --- dda.c | 9 +++++++++ dda.h | 1 + gcode_process.c | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/dda.c b/dda.c index 435fcdb..d3d5e56 100644 --- a/dda.c +++ b/dda.c @@ -112,6 +112,8 @@ void dda_init(void) { startpoint.F = next_target.target.F = SEARCH_FEEDRATE_Z; if (startpoint.e_multiplier == 0) startpoint.e_multiplier = next_target.target.e_multiplier = 256; + if (startpoint.f_multiplier == 0) + startpoint.f_multiplier = next_target.target.f_multiplier = 256; } /*! Distribute a new startpoint to DDA's internal structures without any movement. @@ -177,6 +179,13 @@ void dda_create(DDA *dda, const TARGET *target) { dda->endpoint.axis[X], dda->endpoint.axis[Y], dda->endpoint.axis[Z], dda->endpoint.F); + // Apply feedrate multiplier. + if (dda->endpoint.f_multiplier != 256) { + dda->endpoint.F *= dda->endpoint.f_multiplier; + dda->endpoint.F += 128; + dda->endpoint.F /= 256; + } + #ifdef LOOKAHEAD // Set the start and stop speeds to zero for now = full stops between // moves. Also fallback if lookahead calculations fail to finish in time. diff --git a/dda.h b/dda.h index b4b2cdc..47e2907 100644 --- a/dda.h +++ b/dda.h @@ -42,6 +42,7 @@ typedef struct { uint32_t F; uint16_t e_multiplier; + uint16_t f_multiplier; uint8_t e_relative :1; ///< bool: e axis relative? Overrides all_relative } TARGET; diff --git a/gcode_process.c b/gcode_process.c index 1cb50be..21f8f1e 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -793,6 +793,14 @@ void process_gcode_command() { #endif break; + case 220: + //? --- M220: Set speed factor override percentage --- + if ( ! next_target.seen_S) + break; + // Scale 100% = 256 + next_target.target.f_multiplier = (next_target.S * 64 + 12) / 25; + break; + case 221: //? --- M221: Control the extruders flow --- if ( ! next_target.seen_S)