From f8e170a44bca32500c6c809b8a61f2721a4a13bf Mon Sep 17 00:00:00 2001 From: Bernhard Date: Sun, 27 Nov 2011 14:57:12 +0100 Subject: [PATCH 1/6] planner optimization by inline functions --- Marlin/planner.cpp | 23 +++++++---------------- Marlin/planner.h | 29 ++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index bb2e2a672..2367e313a 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -93,13 +93,17 @@ static float previous_nominal_speed; // Nominal speed of previous path line segm bool autotemp_enabled=false; #endif + +//=========================================================================== +//=================semi-private variables, used in inline functions ===== +//=========================================================================== +block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instfructions +volatile unsigned char block_buffer_head; // Index of the next block to be pushed +volatile unsigned char block_buffer_tail; // Index of the block to process now //=========================================================================== //=============================private variables ============================ //=========================================================================== -static block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instfructions -static volatile unsigned char block_buffer_head; // Index of the next block to be pushed -static volatile unsigned char block_buffer_tail; // Index of the block to process now // Used for the frequency limit static unsigned char old_direction_bits = 0; // Old direction bits. Used for speed calculations @@ -364,20 +368,7 @@ void plan_init() { } -void plan_discard_current_block() { - if (block_buffer_head != block_buffer_tail) { - block_buffer_tail = (block_buffer_tail + 1) & (BLOCK_BUFFER_SIZE - 1); - } -} -block_t *plan_get_current_block() { - if (block_buffer_head == block_buffer_tail) { - return(NULL); - } - block_t *block = &block_buffer[block_buffer_tail]; - block->busy = true; - return(block); -} #ifdef AUTOTEMP void getHighESpeed() diff --git a/Marlin/planner.h b/Marlin/planner.h index 9aa121aca..7bae9a1c9 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -72,12 +72,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa void plan_set_position(const float &x, const float &y, const float &z, const float &e); void plan_set_e_position(const float &e); -// Called when the current block is no longer needed. Discards the block and makes the memory -// availible for new blocks. -void plan_discard_current_block(); -// Gets the current block. Returns NULL if buffer empty -block_t *plan_get_current_block(); void check_axes_activity(); uint8_t movesplanned(); //return the nr of buffered moves @@ -102,4 +97,28 @@ extern unsigned long axis_steps_per_sqr_second[NUM_AXIS]; extern float autotemp_factor; #endif + +/////semi-private stuff +#include + +extern block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instfructions +extern volatile unsigned char block_buffer_head; // Index of the next block to be pushed +extern volatile unsigned char block_buffer_tail; +// Called when the current block is no longer needed. Discards the block and makes the memory +// availible for new blocks. +inline void plan_discard_current_block() { + if (block_buffer_head != block_buffer_tail) { + block_buffer_tail = (block_buffer_tail + 1) & (BLOCK_BUFFER_SIZE - 1); + } +} + +// Gets the current block. Returns NULL if buffer empty +inline block_t *plan_get_current_block() { + if (block_buffer_head == block_buffer_tail) { + return(NULL); + } + block_t *block = &block_buffer[block_buffer_tail]; + block->busy = true; + return(block); +} #endif From 26a1de1e448cd254f6d69a2a7098c290933d269e Mon Sep 17 00:00:00 2001 From: Bernhard Date: Sun, 27 Nov 2011 16:04:58 +0100 Subject: [PATCH 2/6] force inline --- Marlin/EEPROMwrite.h | 4 ++-- Marlin/Marlin.h | 4 +++- Marlin/cardreader.h | 48 ++++++++++++++++++++++---------------------- Marlin/planner.cpp | 8 +++++--- Marlin/planner.h | 7 +++++-- Marlin/temperature.h | 30 +++++++++++++-------------- Marlin/ultralcd.h | 6 +++--- Marlin/watchdog.h | 4 ++-- 8 files changed, 59 insertions(+), 52 deletions(-) diff --git a/Marlin/EEPROMwrite.h b/Marlin/EEPROMwrite.h index 3d559c026..08b344af6 100644 --- a/Marlin/EEPROMwrite.h +++ b/Marlin/EEPROMwrite.h @@ -38,7 +38,7 @@ template int EEPROM_readAnything(int &ee, T& value) // ALSO: always make sure the variables in the Store and retrieve sections are in the same order. #define EEPROM_VERSION "V04" -inline void StoreSettings() +FORCE_INLINE void StoreSettings() { #ifdef EEPROM_SETTINGS char ver[4]= "000"; @@ -71,7 +71,7 @@ inline void StoreSettings() #endif //EEPROM_SETTINGS } -inline void RetrieveSettings(bool def=false) +FORCE_INLINE void RetrieveSettings(bool def=false) { // if def=true, the default values will be used #ifdef EEPROM_SETTINGS int i=EEPROM_OFFSET; diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index acfc3c2fa..20032a685 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -8,6 +8,8 @@ #include #include "Configuration.h" + +#define FORCE_INLINE __attribute__((always_inline)) inline //#define SERIAL_ECHO(x) Serial << "echo: " << x; //#define SERIAL_ECHOLN(x) Serial << "echo: "<=filesize ;}; - inline int16_t get() { sdpos = file.curPosition();return (int16_t)file.read();}; - inline void setIndex(long index) {sdpos = index;file.seekSet(index);}; - inline uint8_t percentDone(){if(!sdprinting) return 0; if(filesize) return sdpos*100/filesize; else return 0;}; - inline char* getWorkDirName(){workDir.getFilename(filename);return filename;}; + FORCE_INLINE bool eof() { return sdpos>=filesize ;}; + FORCE_INLINE int16_t get() { sdpos = file.curPosition();return (int16_t)file.read();}; + FORCE_INLINE void setIndex(long index) {sdpos = index;file.seekSet(index);}; + FORCE_INLINE uint8_t percentDone(){if(!sdprinting) return 0; if(filesize) return sdpos*100/filesize; else return 0;}; + FORCE_INLINE char* getWorkDirName(){workDir.getFilename(filename);return filename;}; public: bool saving; @@ -69,31 +69,31 @@ private: class CardReader { public: - inline CardReader(){}; + FORCE_INLINE CardReader(){}; - inline static void initsd(){}; - inline static void write_command(char *buf){}; + FORCE_INLINE static void initsd(){}; + FORCE_INLINE static void write_command(char *buf){}; - inline static void checkautostart(bool x) {}; + FORCE_INLINE static void checkautostart(bool x) {}; - inline static void openFile(char* name,bool read){}; - inline static void closefile() {}; - inline static void release(){}; - inline static void startFileprint(){}; - inline static void startFilewrite(char *name){}; - inline static void pauseSDPrint(){}; - inline static void getStatus(){}; + FORCE_INLINE static void openFile(char* name,bool read){}; + FORCE_INLINE static void closefile() {}; + FORCE_INLINE static void release(){}; + FORCE_INLINE static void startFileprint(){}; + FORCE_INLINE static void startFilewrite(char *name){}; + FORCE_INLINE static void pauseSDPrint(){}; + FORCE_INLINE static void getStatus(){}; - inline static void selectFile(char* name){}; - inline static void getfilename(const uint8_t nr){}; - inline static uint8_t getnrfilenames(){return 0;}; + FORCE_INLINE static void selectFile(char* name){}; + FORCE_INLINE static void getfilename(const uint8_t nr){}; + FORCE_INLINE static uint8_t getnrfilenames(){return 0;}; - inline static void ls() {}; - inline static bool eof() {return true;}; - inline static char get() {return 0;}; - inline static void setIndex(){}; - inline uint8_t percentDone(){return 0;}; + FORCE_INLINE static void ls() {}; + FORCE_INLINE static bool eof() {return true;}; + FORCE_INLINE static char get() {return 0;}; + FORCE_INLINE static void setIndex(){}; + FORCE_INLINE uint8_t percentDone(){return 0;}; }; #endif //SDSUPPORT #endif \ No newline at end of file diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 2367e313a..2c2ba3f77 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -132,7 +132,8 @@ static int8_t prev_block_index(int8_t block_index) { // Calculates the distance (not time) it takes to accelerate from initial_rate to target_rate using the // given acceleration: -inline float estimate_acceleration_distance(float initial_rate, float target_rate, float acceleration) { +FORCE_INLINE float estimate_acceleration_distance(float initial_rate, float target_rate, float acceleration) +{ if (acceleration!=0) { return((target_rate*target_rate-initial_rate*initial_rate)/ (2.0*acceleration)); @@ -147,7 +148,8 @@ inline float estimate_acceleration_distance(float initial_rate, float target_rat // a total travel of distance. This can be used to compute the intersection point between acceleration and // deceleration in the cases where the trapezoid has no plateau (i.e. never reaches maximum speed) -inline float intersection_distance(float initial_rate, float final_rate, float acceleration, float distance) { +FORCE_INLINE float intersection_distance(float initial_rate, float final_rate, float acceleration, float distance) +{ if (acceleration!=0) { return((2.0*acceleration*distance-initial_rate*initial_rate+final_rate*final_rate)/ (4.0*acceleration) ); @@ -211,7 +213,7 @@ void calculate_trapezoid_for_block(block_t *block, float entry_factor, float exi // Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the // acceleration within the allotted distance. -inline float max_allowable_speed(float acceleration, float target_velocity, float distance) { +FORCE_INLINE float max_allowable_speed(float acceleration, float target_velocity, float distance) { return sqrt(target_velocity*target_velocity-2*acceleration*distance); } diff --git a/Marlin/planner.h b/Marlin/planner.h index 7bae9a1c9..e17580dad 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -25,6 +25,7 @@ #define planner_h #include "Configuration.h" +#include "Marlin.h" // This struct is used when buffering the setup for each linear movement "nominal" values are as specified in // the source g-code and may never actually be reached if acceleration management is active. @@ -106,14 +107,16 @@ extern volatile unsigned char block_buffer_head; // Index of the next extern volatile unsigned char block_buffer_tail; // Called when the current block is no longer needed. Discards the block and makes the memory // availible for new blocks. -inline void plan_discard_current_block() { +FORCE_INLINE void plan_discard_current_block() +{ if (block_buffer_head != block_buffer_tail) { block_buffer_tail = (block_buffer_tail + 1) & (BLOCK_BUFFER_SIZE - 1); } } // Gets the current block. Returns NULL if buffer empty -inline block_t *plan_get_current_block() { +FORCE_INLINE block_t *plan_get_current_block() +{ if (block_buffer_head == block_buffer_tail) { return(NULL); } diff --git a/Marlin/temperature.h b/Marlin/temperature.h index 0f0de985f..9057c1c90 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -59,31 +59,31 @@ extern float Kp,Ki,Kd,Kc; //inline so that there is no performance decrease. //deg=degreeCelsius -inline float degHotend0(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);}; -inline float degHotend1(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);}; -inline float degBed() { return analog2tempBed(current_raw[TEMPSENSOR_BED]);}; +FORCE_INLINE float degHotend0(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);}; +FORCE_INLINE float degHotend1(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);}; +FORCE_INLINE float degBed() { return analog2tempBed(current_raw[TEMPSENSOR_BED]);}; -inline float degTargetHotend0() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);}; -inline float degTargetHotend1() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);}; -inline float degTargetBed() { return analog2tempBed(target_raw[TEMPSENSOR_BED]);}; +FORCE_INLINE float degTargetHotend0() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);}; +FORCE_INLINE float degTargetHotend1() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);}; +FORCE_INLINE float degTargetBed() { return analog2tempBed(target_raw[TEMPSENSOR_BED]);}; -inline void setTargetHotend0(const float &celsius) +FORCE_INLINE void setTargetHotend0(const float &celsius) { target_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius); #ifdef PIDTEMP pid_setpoint = celsius; #endif //PIDTEMP }; -inline void setTargetHotend1(const float &celsius) { target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);}; -inline void setTargetBed(const float &celsius) { target_raw[TEMPSENSOR_BED ]=temp2analogBed(celsius);}; +FORCE_INLINE void setTargetHotend1(const float &celsius) { target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);}; +FORCE_INLINE void setTargetBed(const float &celsius) { target_raw[TEMPSENSOR_BED ]=temp2analogBed(celsius);}; -inline bool isHeatingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];}; -inline bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];}; -inline bool isHeatingBed() {return target_raw[TEMPSENSOR_BED] > current_raw[TEMPSENSOR_BED];}; +FORCE_INLINE bool isHeatingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];}; +FORCE_INLINE bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];}; +FORCE_INLINE bool isHeatingBed() {return target_raw[TEMPSENSOR_BED] > current_raw[TEMPSENSOR_BED];}; -inline bool isCoolingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];}; -inline bool isCoolingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];}; -inline bool isCoolingBed() {return target_raw[TEMPSENSOR_BED] < current_raw[TEMPSENSOR_BED];}; +FORCE_INLINE bool isCoolingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];}; +FORCE_INLINE bool isCoolingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];}; +FORCE_INLINE bool isCoolingBed() {return target_raw[TEMPSENSOR_BED] < current_raw[TEMPSENSOR_BED];}; void disable_heater(); void setWatch(); diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h index 85a8df74c..887dc04f2 100644 --- a/Marlin/ultralcd.h +++ b/Marlin/ultralcd.h @@ -79,7 +79,7 @@ bool tune; private: - inline void updateActiveLines(const uint8_t &maxlines,volatile int &encoderpos) + FORCE_INLINE void updateActiveLines(const uint8_t &maxlines,volatile int &encoderpos) { if(linechanging) return; // an item is changint its value, do not switch lines hence lastlineoffset=lineoffset; @@ -119,7 +119,7 @@ } } - inline void clearIfNecessary() + FORCE_INLINE void clearIfNecessary() { if(lastlineoffset!=lineoffset ||force_lcd_update) { @@ -143,7 +143,7 @@ #define LCD_STATUS #define LCD_MESSAGE(x) #define LCD_MESSAGEPGM(x) - inline void lcd_status() {}; + FORCE_INLINE void lcd_status() {}; #endif #ifndef ULTIPANEL diff --git a/Marlin/watchdog.h b/Marlin/watchdog.h index 44ee9de35..1d4148827 100644 --- a/Marlin/watchdog.h +++ b/Marlin/watchdog.h @@ -9,8 +9,8 @@ void wd_reset(); #else - inline void wd_init() {}; - inline void wd_reset() {}; + FORCE_INLINE void wd_init() {}; + FORCE_INLINE void wd_reset() {}; #endif #endif From b128d25f27142381c3f035d1754e28c4a4bb1bf1 Mon Sep 17 00:00:00 2001 From: Bernhard Date: Sun, 27 Nov 2011 16:45:00 +0100 Subject: [PATCH 3/6] overlooked some inlines.. --- Marlin/stepper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 491b6e7f2..03ea11be7 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -224,7 +224,7 @@ void st_wake_up() { ENABLE_STEPPER_DRIVER_INTERRUPT(); } -inline unsigned short calc_timer(unsigned short step_rate) { +FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) { unsigned short timer; if(step_rate > MAX_STEP_FREQUENCY) step_rate = MAX_STEP_FREQUENCY; @@ -261,7 +261,7 @@ inline unsigned short calc_timer(unsigned short step_rate) { // Initializes the trapezoid generator from the current block. Called whenever a new // block begins. -inline void trapezoid_generator_reset() { +FORCE_INLINE void trapezoid_generator_reset() { #ifdef ADVANCE advance = current_block->initial_advance; final_advance = current_block->final_advance; From 6aecf80278c8b3e5eab716592f314554efbca0ea Mon Sep 17 00:00:00 2001 From: Bernhard Date: Sun, 27 Nov 2011 16:45:19 +0100 Subject: [PATCH 4/6] add autotemp support to the lcd --- Marlin/ultralcd.pde | 143 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 141 insertions(+), 2 deletions(-) diff --git a/Marlin/ultralcd.pde b/Marlin/ultralcd.pde index a90a6c66d..a4bb640b7 100644 --- a/Marlin/ultralcd.pde +++ b/Marlin/ultralcd.pde @@ -660,7 +660,12 @@ void MainMenu::showTune() // enum { - ItemCT_exit, ItemCT_nozzle, ItemCT_fan, + ItemCT_exit,ItemCT_nozzle, +#ifdef AUTOTEMP + ItemCT_autotempactive, + ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact, +#endif + ItemCT_fan, ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C }; @@ -708,7 +713,128 @@ void MainMenu::showControlTemp() } } }break; - + #ifdef AUTOTEMP + case ItemCT_autotempmin: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" \002 Min:"); + lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max)); + } + + if((activeline==line) ) + { + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=intround(autotemp_max); + } + else + { + autotemp_max=encoderpos; + encoderpos=activeline*lcdslow; + beepshort(); + } + BLOCK; + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>260) encoderpos=260; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + } + }break; + case ItemCT_autotempmax: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" \002 Max:"); + lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max)); + } + + if((activeline==line) ) + { + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=intround(autotemp_max); + } + else + { + autotemp_max=encoderpos; + encoderpos=activeline*lcdslow; + beepshort(); + } + BLOCK; + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>260) encoderpos=260; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + } + }break; + case ItemCT_autotempfact: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" \002 Fact:"); + lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor)); + } + + if((activeline==line) ) + { + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=intround(autotemp_factor*100); + } + else + { + autotemp_max=encoderpos; + encoderpos=activeline*lcdslow; + beepshort(); + } + BLOCK; + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>99) encoderpos=99; + lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.)); + } + } + }break; + case ItemCT_autotempactive: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" Autotemp:"); + lcd.setCursor(13,line); + if(autotemp_enabled) + lcdprintPGM("On"); + else + lcdprintPGM("Off"); + } + + if((activeline==line) ) + { + if(CLICKED) + { + autotemp_enabled=!autotemp_enabled; + BLOCK; + } + } + }break; + #endif //autotemp case ItemCT_fan: { if(force_lcd_update) @@ -1620,6 +1746,19 @@ char *ftostr31(const float &x) return conv; } +char *ftostr32(const float &x) +{ + int xx=x*100; + conv[0]=(xx>=0)?'+':'-'; + xx=abs(xx); + conv[1]=(xx/100)%10+'0'; + conv[2]='.'; + conv[3]=(xx/10)%10+'0'; + conv[4]=(xx)%10+'0'; + conv[6]=0; + return conv; +} + char *itostr31(const int &xx) { conv[0]=(xx>=0)?'+':'-'; From d2f034ba84192093bcbe96eae1bd835e407bed79 Mon Sep 17 00:00:00 2001 From: Bernhard Date: Sun, 27 Nov 2011 16:53:11 +0100 Subject: [PATCH 5/6] lcd message from gcode, m117 --- Marlin/Marlin.pde | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index d765d222b..9cf499809 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -94,6 +94,7 @@ // M92 - Set axis_steps_per_unit - same syntax as G92 // M114 - Output current position to serial port // M115 - Capabilities string +// M117 - display message // M119 - Output Endstop status to serial port // M140 - Set bed target temp // M190 - Wait for bed current temp to reach target temp. @@ -850,6 +851,9 @@ inline void process_commands() case 115: // M115 SerialprintPGM("FIRMWARE_NAME:Marlin; Sprinter/grbl mashup for gen6 FIRMWARE_URL:http://www.mendel-parts.com PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1"); break; + case 117: // M117 display message + LCD_MESSAGE(cmdbuffer[bufindr]+5); + break; case 114: // M114 SERIAL_PROTOCOLPGM("X:"); SERIAL_PROTOCOL(current_position[X_AXIS]); From 2d9a7156555e0cdd969b44cc7c4d3c8a18875cfe Mon Sep 17 00:00:00 2001 From: Bernhard Date: Sun, 27 Nov 2011 17:27:17 +0100 Subject: [PATCH 6/6] first naive attempt to have a offset in the homeing procedure. Does not enable to move into regions not allowed by endstops. --- Marlin/Marlin.h | 1 + Marlin/Marlin.pde | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 20032a685..69a0cf3e2 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -112,5 +112,6 @@ void prepare_arc_move(char isclockwise); extern float homing_feedrate[]; extern bool axis_relative_modes[]; extern float current_position[NUM_AXIS] ; +extern float add_homeing[3]; #endif diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 9cf499809..6a07cf989 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -104,6 +104,7 @@ // M203 - Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec // M204 - Set default acceleration: S normal moves T filament only moves (M204 S3000 T7000) im mm/sec^2 also sets minimum segment time in ms (B20000) to prevent buffer underruns and M20 minimum feedrate // M205 - advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk +// M206 - set additional homeing offset // M220 - set speed factor override percentage S:factor in percent // M301 - Set PID parameters P I and D // M400 - Finish all moves @@ -131,7 +132,7 @@ volatile int feedmultiply=100; //100->1 200->2 int saved_feedmultiply; volatile bool feedmultiplychanged=false; float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0}; - +float add_homeing[3]={0,0,0}; //=========================================================================== //=============================private variables============================= @@ -536,19 +537,23 @@ inline void process_commands() } feedrate = 0.0; home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))); - + if((home_all_axis) || (code_seen(axis_codes[X_AXIS]))) { HOMEAXIS(X); + current_position[0]=code_value()+add_homeing[0]; } if((home_all_axis) || (code_seen(axis_codes[Y_AXIS]))) { HOMEAXIS(Y); + current_position[1]=code_value()+add_homeing[1]; } if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) { HOMEAXIS(Z); + current_position[2]=code_value()+add_homeing[2]; } + feedrate = saved_feedrate; feedmultiply = saved_feedmultiply; previous_millis_cmd = millis(); @@ -565,7 +570,7 @@ inline void process_commands() st_synchronize(); for(int8_t i=0; i < NUM_AXIS; i++) { if(code_seen(axis_codes[i])) { - current_position[i] = code_value(); + current_position[i] = code_value()+add_homeing[i]; if(i == E_AXIS) { plan_set_e_position(current_position[E_AXIS]); } @@ -934,6 +939,12 @@ inline void process_commands() if(code_seen('Z')) max_z_jerk = code_value() ; } break; + case 206: // M206 additional homeing offset + for(int8_t i=0; i < 3; i++) + { + if(code_seen(axis_codes[i])) add_homeing[i] = code_value(); + } + break; case 220: // M220 S- set speed factor override percentage { if(code_seen('S'))