From: Michael Moon Date: Mon, 11 Mar 2013 10:24:34 +0000 (+1100) Subject: Extruder: clarify handling of relative/absolute mode on incoming gcode X-Git-Url: https://git.hcoop.net/clinton/Smoothieware.git/commitdiff_plain/f8dc00432e2f2288ee9fa9805f8ecb7805134a0d Extruder: clarify handling of relative/absolute mode on incoming gcode --- diff --git a/src/modules/tools/extruder/Extruder.cpp b/src/modules/tools/extruder/Extruder.cpp index b7d2c955..83c0e399 100644 --- a/src/modules/tools/extruder/Extruder.cpp +++ b/src/modules/tools/extruder/Extruder.cpp @@ -189,8 +189,17 @@ void Extruder::on_gcode_execute(void* argument){ // Extrusion length from 'G' Gcode if( gcode->has_letter('E' )){ // Get relative extrusion distance depending on mode ( in absolute mode we must substract target_position ) - double relative_extrusion_distance = gcode->get_value('E'); - if( this->absolute_mode == true ){ relative_extrusion_distance = relative_extrusion_distance - this->target_position; } + double extrusion_distance = gcode->get_value('E'); + double relative_extrusion_distance = extrusion_distance; + if (this->absolute_mode) + { + relative_extrusion_distance -= this->target_position; + this->target_position = extrusion_distance; + } + else + { + this->target_position += relative_extrusion_distance; + } // If the robot is moving, we follow it's movement, otherwise, we move alone if( fabs(gcode->millimeters_of_travel) < 0.0001 ){ // With floating numbers, we can have 0 != 0 ... beeeh. For more info see : http://upload.wikimedia.org/wikipedia/commons/0/0a/Cain_Henri_Vidal_Tuileries.jpg