From a873541ef6b23100dc6dec15e6195e87cef6fce5 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 8 Aug 2012 17:56:39 +0100 Subject: [PATCH 1/9] Marlin.pde: include comment for emacs mode Emacs by default doesn't recognise a ".pde" file as C++ source code. Add the annotation to the top of the file to make it work. Signed-off-by: Ian Jackson --- Marlin/Marlin.pde | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 73f1f4126b..f38920b44c 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -1,3 +1,5 @@ +/* -*- c++ -*- */ + /* Reprap firmware based on Sprinter and grbl. Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm From 71404eef293f1c93ba081a458120b45e5a48f566 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 8 Aug 2012 18:32:51 +0100 Subject: [PATCH 2/9] .gitignore: Add *~, *.orig, *.rej, move to root directory Move the .gitignore out of the Marlin subdirectory so it applies to the whole tree, and add some missing patterns. Signed-off-by: Ian Jackson --- .gitignore | 5 +++++ Marlin/.gitignore | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .gitignore delete mode 100644 Marlin/.gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..0a12acfd7c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.o +applet/ +*~ +*.orig +*.rej diff --git a/Marlin/.gitignore b/Marlin/.gitignore deleted file mode 100644 index 37a3c9b84d..0000000000 --- a/Marlin/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.o -applet/ From 0c35facc946fda47b18b3d28b7d9e832b6c41ae6 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 1 Aug 2012 21:31:38 +0100 Subject: [PATCH 3/9] Makefile: support V=1 Often it can be useful to see the actual commands being run by make. Other projects (eg, the Linux kernel) support this with a "V=1" make parameter. Do the same here. Signed-off-by: Ian Jackson --- Marlin/Makefile | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/Marlin/Makefile b/Marlin/Makefile index fe77a2afd7..a85111d58e 100644 --- a/Marlin/Makefile +++ b/Marlin/Makefile @@ -170,6 +170,14 @@ ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) ALL_CXXFLAGS = -mmcu=$(MCU) $(CXXFLAGS) ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS) +# set V=1 (eg, "make V=1") to print the full commands etc. +ifneq ($V,1) + Pecho=@echo + P=@ +else + Pecho=@: + P= +endif # Default target. all: sizeafter @@ -178,7 +186,7 @@ build: applet elf hex # Creates the object directory applet: - @mkdir -p applet + $P mkdir -p applet # the .cpp for Marlin depends on the .pde #applet/$(TARGET).cpp: $(TARGET).pde @@ -189,10 +197,10 @@ applet/%.cpp: %.pde $(MAKEFILE) # Here is the "preprocessing". # It creates a .cpp file based with the same name as the .pde file. # On top of the new .cpp file comes the WProgram.h header. - @echo " WR $@" - @echo '#include "WProgram.h"' > $@ - @echo '#include "$<"' >>$@ - @echo '#include "$(ARDUINO)/main.cpp"' >> $@ + $(Pecho) " WR $@" + $P echo '#include "WProgram.h"' > $@ + $P echo '#include "$<"' >>$@ + $P echo '#include "$(ARDUINO)/main.cpp"' >> $@ elf: applet/$(TARGET).elf hex: applet/$(TARGET).hex @@ -215,10 +223,10 @@ endif HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex ELFSIZE = $(SIZE) applet/$(TARGET).elf sizebefore: - @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi + $P if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi sizeafter: build - @if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi + $P if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. @@ -241,8 +249,8 @@ extcoff: $(TARGET).elf .PRECIOUS: .o .elf.hex: - @echo " COPY $@" - @$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + $(Pecho) " COPY $@" + $P $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ .elf.eep: -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ @@ -258,29 +266,29 @@ extcoff: $(TARGET).elf # Link: create ELF output file from library. applet/$(TARGET).elf: applet/$(TARGET).cpp applet/core.a Configuration.h - @echo " CXX $@" - @$(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS) + $(Pecho) " CXX $@" + $P $(CC) $(ALL_CXXFLAGS) -Wl,--gc-sections -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS) applet/core.a: $(OBJ) - @for i in $(OBJ); do echo " AR $$i"; $(AR) rcs applet/core.a $$i; done + $P for i in $(OBJ); do echo " AR $$i"; $(AR) rcs applet/core.a $$i; done applet/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE) - @echo " CC $@" - @$(CC) -MMD -c $(ALL_CFLAGS) $< -o $@ + $(Pecho) " CC $@" + $P $(CC) -MMD -c $(ALL_CFLAGS) $< -o $@ applet/%.o: %.cpp Configuration.h Configuration_adv.h $(MAKEFILE) - @echo " CXX $@" - @$(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@ + $(Pecho) " CXX $@" + $P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@ # Target: clean project. clean: - @echo " RM applet/*" - @$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \ + $(Pecho) " RM applet/*" + $P $(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \ applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp applet/core.a \ $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) - @echo " RMDIR applet/" - @rm -rf applet + $(Pecho) " RMDIR applet/" + $P rm -rf applet .PHONY: all build elf hex eep lss sym program coff extcoff clean depend applet_files sizebefore sizeafter From 3f15b7c7b863abfa2c6cb157a7f220ab9627d776 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 9 Aug 2012 19:03:12 +0100 Subject: [PATCH 4/9] Makefile: Better display of size (device memory usage) Run avr-size with the --mcu=... -C option as well. That reports how much actual device program and data memory is used along with a percentage fullness. Signed-off-by: Ian Jackson --- Marlin/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Marlin/Makefile b/Marlin/Makefile index a85111d58e..940bb168b7 100644 --- a/Marlin/Makefile +++ b/Marlin/Makefile @@ -221,7 +221,8 @@ endif # Display size of file. HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex -ELFSIZE = $(SIZE) applet/$(TARGET).elf +ELFSIZE = $(SIZE) --mcu=$(MCU) -C applet/$(TARGET).elf; \ + $(SIZE) applet/$(TARGET).elf sizebefore: $P if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi From faccb358508d49d0bef35dc0521043f04508bcc3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 9 Aug 2012 18:15:32 +0100 Subject: [PATCH 5/9] software_endstops: use *_MIN_POS and *_MAX_POS for arcs If [XYZ]_HOME_POS and [XYZ]_MIN_POS aren't 0, these corrections are wrong. Use the same logic as in Marlin.pde:prepare_move: ie, clamp to [XYZ]_{MIN,MAX}_POS. While we're here, put this cut-and-paste code in a function clamp_to_software_endstops. Signed-off-by: Ian Jackson --- Marlin/Marlin.h | 1 + Marlin/Marlin.pde | 20 +++++++++++++------- Marlin/motion_control.cpp | 12 +----------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 4123634442..75b57d0b91 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -169,6 +169,7 @@ bool IsStopped(); void enquecommand(const char *cmd); //put an ascii command at the end of the current buffer. void prepare_arc_move(char isclockwise); +void clamp_to_software_endstops(float target[3]); #ifdef FAST_PWM_FAN void setPwmFrequency(uint8_t pin, int val); diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index f38920b44c..5268a3de35 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -1541,19 +1541,25 @@ void get_arc_coordinates() } } -void prepare_move() +void clamp_to_software_endstops(float target[3]) { if (min_software_endstops) { - if (destination[X_AXIS] < X_MIN_POS) destination[X_AXIS] = X_MIN_POS; - if (destination[Y_AXIS] < Y_MIN_POS) destination[Y_AXIS] = Y_MIN_POS; - if (destination[Z_AXIS] < Z_MIN_POS) destination[Z_AXIS] = Z_MIN_POS; + if (target[X_AXIS] < X_MIN_POS) target[X_AXIS] = X_MIN_POS; + if (target[Y_AXIS] < Y_MIN_POS) target[Y_AXIS] = Y_MIN_POS; + if (target[Z_AXIS] < Z_MIN_POS) target[Z_AXIS] = Z_MIN_POS; } if (max_software_endstops) { - if (destination[X_AXIS] > X_MAX_POS) destination[X_AXIS] = X_MAX_POS; - if (destination[Y_AXIS] > Y_MAX_POS) destination[Y_AXIS] = Y_MAX_POS; - if (destination[Z_AXIS] > Z_MAX_POS) destination[Z_AXIS] = Z_MAX_POS; + if (target[X_AXIS] > X_MAX_POS) target[X_AXIS] = X_MAX_POS; + if (target[Y_AXIS] > Y_MAX_POS) target[Y_AXIS] = Y_MAX_POS; + if (target[Z_AXIS] > Z_MAX_POS) target[Z_AXIS] = Z_MAX_POS; } +} + +void prepare_move() +{ + clamp_to_software_endstops(destination); + previous_millis_cmd = millis(); plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder); for(int8_t i=0; i < NUM_AXIS; i++) { diff --git a/Marlin/motion_control.cpp b/Marlin/motion_control.cpp index f11d8c8b8e..76609054ff 100644 --- a/Marlin/motion_control.cpp +++ b/Marlin/motion_control.cpp @@ -125,17 +125,7 @@ void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8 arc_target[axis_linear] += linear_per_segment; arc_target[E_AXIS] += extruder_per_segment; - if (min_software_endstops) { - if (arc_target[X_AXIS] < X_HOME_POS) arc_target[X_AXIS] = X_HOME_POS; - if (arc_target[Y_AXIS] < Y_HOME_POS) arc_target[Y_AXIS] = Y_HOME_POS; - if (arc_target[Z_AXIS] < Z_HOME_POS) arc_target[Z_AXIS] = Z_HOME_POS; - } - - if (max_software_endstops) { - if (arc_target[X_AXIS] > X_MAX_LENGTH) arc_target[X_AXIS] = X_MAX_LENGTH; - if (arc_target[Y_AXIS] > Y_MAX_LENGTH) arc_target[Y_AXIS] = Y_MAX_LENGTH; - if (arc_target[Z_AXIS] > Z_MAX_LENGTH) arc_target[Z_AXIS] = Z_MAX_LENGTH; - } + clamp_to_software_endstops(arc_target); plan_buffer_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], arc_target[E_AXIS], feed_rate, extruder); } From 957e966d2d5fb1884adb1f982ad01d39d547eb36 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 1 Aug 2012 21:12:14 +0100 Subject: [PATCH 6/9] M206: always use homing ("homeing") offsets Previously the parameters set in M206 would only be used if a G82 command was sent with specific axis home values. This limits its usefulness. Really, we should have a way to adjust the XYZ homing of a machine in the eeprom. So as the first stage of this, make M206 affect every home command. The values set using M206 are now added to the configuration variables [XYZ]_HOME_POS. This is achieved by replacing all uses of [XYZ]_HOME_POS in the code by a new home_pos[] which includes the adjustment. We also have to adjust the uses of [XYZ]_{MIN,MAX}_POS similarly - see below. To allow axis_is_at_home to be written as a function taking an axis index rather than a macro taking an axis letter, we provide constant arrays in program memory containing the values of [XYZ]_{MIN,MAX,HOME}_POS from the compiled-in configuration. This is done with some helper macros to deal with the declaration (XYZ_CONSTS_FROM_CONFIG) and definition of the inline function which does the program memory access. We also introduce the overloaded function read_pgm_any, whose instances are produced with DEFINE_PGM_READ_ANY, which allows the access functions to automatically produce the correct type. The type- and pointer-massaging code in the access function boils down, when compiled, to a simple program memory access. A question arises: if the M206 offset is set, should this adjustment to the home position shift or change the possible range of movement permitted by the software endstops ? The documentation in Configuration.h describes these limits as: // Travel limits after homing Since this is a file containing physical limits, and actual suggested values for these configuration parameters appear to include a certain amount of slop, I've taken the view that these should be regarded as nominal physical distances from the limit switches, and that the permissible travel should be unaffected by M206. So for example with the (rather unrealistic) #define X_HOME_DIR -1 #define X_MIN_POS -20 #define X_HOME_POS 0 #define X_MAX_POS 100 no matter the setting of M206 X, the machine would be permitted to move from 20mm "beyond" the limit switch trigger point in the negative X direction and 100mm away from the limit switch in the positive X direction, for a total travel of 120mm. With M206 X-10 that would be considered to correspond to X coordinates -30 to +90. With M206 X+10 that would be considered to correspond to X coordinates -10 to +110. fixes #200 (in ErikZalm/Marlin). Signed-off-by: Ian Jackson --- Marlin/Marlin.h | 2 ++ Marlin/Marlin.pde | 44 ++++++++++++++++++++++++++++++++++---------- README.md | 1 + 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 75b57d0b91..b465d8535a 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -184,6 +184,8 @@ extern float homing_feedrate[]; extern bool axis_relative_modes[]; extern float current_position[NUM_AXIS] ; extern float add_homeing[3]; +extern float min_pos[3]; +extern float max_pos[3]; extern unsigned char FanSpeed; // Handling multiple extruders pins diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 5268a3de35..d11b51c7c9 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -143,6 +143,8 @@ volatile bool feedmultiplychanged=false; volatile int extrudemultiply=100; //100->1 200->2 float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 }; float add_homeing[3]={0,0,0}; +float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }; +float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }; uint8_t active_extruder = 0; unsigned char FanSpeed=0; @@ -543,6 +545,28 @@ bool code_seen(char code) return (strchr_pointer != NULL); //Return True if a character was found } +#define DEFINE_PGM_READ_ANY(type, reader) \ + static inline type pgm_read_any(const type *p) \ + { return pgm_read_##reader##_near(p); } + +DEFINE_PGM_READ_ANY(float, float); + +#define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \ +static const PROGMEM type array##_P[3] = \ + { X_##CONFIG, Y_##CONFIG, Z_##CONFIG }; \ +static inline type array(int axis) \ + { return pgm_read_any(&array##_P[axis]); } + +XYZ_CONSTS_FROM_CONFIG(float, base_min_pos, MIN_POS); +XYZ_CONSTS_FROM_CONFIG(float, base_max_pos, MAX_POS); +XYZ_CONSTS_FROM_CONFIG(float, base_home_pos, HOME_POS); + +static void axis_is_at_home(int axis) { + current_position[axis] = base_home_pos(axis) + add_homeing[axis]; + min_pos[axis] = base_min_pos(axis) + add_homeing[axis]; + max_pos[axis] = base_max_pos(axis) + add_homeing[axis]; +} + #define HOMEAXIS(LETTER) \ if ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))\ { \ @@ -564,8 +588,8 @@ bool code_seen(char code) plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \ st_synchronize();\ \ - current_position[LETTER##_AXIS] = LETTER##_HOME_POS;\ - destination[LETTER##_AXIS] = current_position[LETTER##_AXIS];\ + axis_is_at_home(LETTER##_AXIS); \ + destination[LETTER##_AXIS] = current_position[LETTER##_AXIS]; \ feedrate = 0.0;\ endstops_hit_on_purpose();\ } @@ -678,8 +702,8 @@ void process_commands() plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); - current_position[X_AXIS] = X_HOME_POS; - current_position[Y_AXIS] = Y_HOME_POS; + axis_is_at_home(X_AXIS); + axis_is_at_home(Y_AXIS); plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); destination[X_AXIS] = current_position[X_AXIS]; destination[Y_AXIS] = current_position[Y_AXIS]; @@ -1544,15 +1568,15 @@ void get_arc_coordinates() void clamp_to_software_endstops(float target[3]) { if (min_software_endstops) { - if (target[X_AXIS] < X_MIN_POS) target[X_AXIS] = X_MIN_POS; - if (target[Y_AXIS] < Y_MIN_POS) target[Y_AXIS] = Y_MIN_POS; - if (target[Z_AXIS] < Z_MIN_POS) target[Z_AXIS] = Z_MIN_POS; + if (target[X_AXIS] < min_pos[X_AXIS]) target[X_AXIS] = min_pos[X_AXIS]; + if (target[Y_AXIS] < min_pos[Y_AXIS]) target[Y_AXIS] = min_pos[Y_AXIS]; + if (target[Z_AXIS] < min_pos[Z_AXIS]) target[Z_AXIS] = min_pos[Z_AXIS]; } if (max_software_endstops) { - if (target[X_AXIS] > X_MAX_POS) target[X_AXIS] = X_MAX_POS; - if (target[Y_AXIS] > Y_MAX_POS) target[Y_AXIS] = Y_MAX_POS; - if (target[Z_AXIS] > Z_MAX_POS) target[Z_AXIS] = Z_MAX_POS; + if (target[X_AXIS] > max_pos[X_AXIS]) target[X_AXIS] = max_pos[X_AXIS]; + if (target[Y_AXIS] > max_pos[Y_AXIS]) target[Y_AXIS] = max_pos[Y_AXIS]; + if (target[Z_AXIS] > max_pos[Z_AXIS]) target[Z_AXIS] = max_pos[Z_AXIS]; } } diff --git a/README.md b/README.md index 86dd93de95..fb2c18968c 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ Movement variables: * M202 - Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000) Unused in Marlin!! * 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 +* M206 - set home offsets. This sets the X,Y,Z coordinates of the endstops (and is added to the {X,Y,Z}_HOME_POS configuration options (and is also added to the coordinates, if any, provided to G82, as with earlier firmware) * M220 - set build speed mulitplying S:factor in percent ; aka "realtime tuneing in the gcode". So you can slow down if you have islands in one height-range, and speed up otherwise. * M221 - set the extrude multiplying S:factor in percent * M400 - Finish all buffered moves. From 7bb326d389cd5a9f14a99bf0fa8275712fe4b380 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 4 Aug 2012 16:13:25 +0100 Subject: [PATCH 7/9] eeprom: provide smaller code for SERIAL_ECHOPAIR SERIAL_ECHOPAIR implies, eventually, two calls to MYSERIAL.print. One of these has FORCE_INLINE for a per-character loop, and both involve constructing a method call rather than a simple function call. Produce better and smaller code by providing three specialised functions serial_echopair. This saves 672 bytes of program memory (with EEPROM_SETTINGS and SDSUPPORT enabled). Signed-off-by: Ian Jackson --- Marlin/Marlin.h | 6 +++++- Marlin/Marlin.pde | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index b465d8535a..208ac33033 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -84,7 +84,11 @@ const char echomagic[] PROGMEM ="echo:"; #define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x) #define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x) -#define SERIAL_ECHOPAIR(name,value) {SERIAL_ECHOPGM(name);SERIAL_ECHO(value);} +#define SERIAL_ECHOPAIR(name,value) (serial_echopair_P(PSTR(name),(value))) + +void serial_echopair_P(const char *s_P, float v); +void serial_echopair_P(const char *s_P, double v); +void serial_echopair_P(const char *s_P, unsigned long v); //things to write to serial from Programmemory. saves 400 to 2k of RAM. diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index d11b51c7c9..22e3e64ed8 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -203,6 +203,13 @@ bool Stopped=false; void get_arc_coordinates(); +void serial_echopair_P(const char *s_P, float v) + { serialprintPGM(s_P); SERIAL_ECHO(v); } +void serial_echopair_P(const char *s_P, double v) + { serialprintPGM(s_P); SERIAL_ECHO(v); } +void serial_echopair_P(const char *s_P, unsigned long v) + { serialprintPGM(s_P); SERIAL_ECHO(v); } + extern "C"{ extern unsigned int __bss_end; extern unsigned int __heap_start; From 1dba212e18fbb80976462387744d400235c9841d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 8 Aug 2012 18:30:34 +0100 Subject: [PATCH 8/9] HOMEAXIS: make into a function Replace the large macro HOMEAXIS with a function. This avoids the compiler generating three copies of largely identical code. The saving is 724 bytes of program memory. We make use of XYZ_CONSTS_FROM_CONFIG to provide convenient array-shaped access to MAX_LENGTH, HOME_RETRACT_MM and HOME_DIR. Signed-off-by: Ian Jackson --- Marlin/Marlin.pde | 61 ++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 22e3e64ed8..8ed36a5c01 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -557,6 +557,7 @@ bool code_seen(char code) { return pgm_read_##reader##_near(p); } DEFINE_PGM_READ_ANY(float, float); +DEFINE_PGM_READ_ANY(signed char, byte); #define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \ static const PROGMEM type array##_P[3] = \ @@ -567,6 +568,9 @@ static inline type array(int axis) \ XYZ_CONSTS_FROM_CONFIG(float, base_min_pos, MIN_POS); XYZ_CONSTS_FROM_CONFIG(float, base_max_pos, MAX_POS); XYZ_CONSTS_FROM_CONFIG(float, base_home_pos, HOME_POS); +XYZ_CONSTS_FROM_CONFIG(float, max_length, MAX_LENGTH); +XYZ_CONSTS_FROM_CONFIG(float, home_retract_mm, HOME_RETRACT_MM); +XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR); static void axis_is_at_home(int axis) { current_position[axis] = base_home_pos(axis) + add_homeing[axis]; @@ -574,32 +578,39 @@ static void axis_is_at_home(int axis) { max_pos[axis] = base_max_pos(axis) + add_homeing[axis]; } -#define HOMEAXIS(LETTER) \ - if ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))\ - { \ - current_position[LETTER##_AXIS] = 0; \ - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); \ - destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \ - feedrate = homing_feedrate[LETTER##_AXIS]; \ - plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \ - st_synchronize();\ - \ - current_position[LETTER##_AXIS] = 0;\ - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\ - destination[LETTER##_AXIS] = -LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\ - plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \ - st_synchronize();\ - \ - destination[LETTER##_AXIS] = 2*LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\ - feedrate = homing_feedrate[LETTER##_AXIS]/2 ; \ - plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \ - st_synchronize();\ - \ - axis_is_at_home(LETTER##_AXIS); \ - destination[LETTER##_AXIS] = current_position[LETTER##_AXIS]; \ - feedrate = 0.0;\ - endstops_hit_on_purpose();\ +static void homeaxis(int axis) { +#define HOMEAXIS_DO(LETTER) \ + ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1)) + + if (axis==X_AXIS ? HOMEAXIS_DO(X) : + axis==Y_AXIS ? HOMEAXIS_DO(Y) : + axis==Z_AXIS ? HOMEAXIS_DO(Z) : + 0) { + current_position[axis] = 0; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + destination[axis] = 1.5 * max_length(axis) * home_dir(axis); + feedrate = homing_feedrate[axis]; + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + + current_position[axis] = 0; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + destination[axis] = -home_retract_mm(axis) * home_dir(axis); + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + + destination[axis] = 2*home_retract_mm(axis) * home_dir(axis); + feedrate = homing_feedrate[axis]/2 ; + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + + axis_is_at_home(axis); + destination[axis] = current_position[axis]; + feedrate = 0.0; + endstops_hit_on_purpose(); } +} +#define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS) void process_commands() { From adee81170d74d3b704d0c4bad7852c0ac8099be1 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 1 Aug 2012 21:18:08 +0100 Subject: [PATCH 9/9] M206: save values in eeprom Really, we should have a way to adjust the XYZ homing of a machine in the eeprom. So as the second stage of this, make the M206 home offset parameters subject to the M500/M501/M502/M503 eeprom commands. Bump the eeprom version to "V06". Signed-off-by: Ian Jackson --- Marlin/EEPROMwrite.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Marlin/EEPROMwrite.h b/Marlin/EEPROMwrite.h index 96e2ec9856..f07716085d 100644 --- a/Marlin/EEPROMwrite.h +++ b/Marlin/EEPROMwrite.h @@ -38,7 +38,7 @@ template int EEPROM_readAnything(int &ee, T& value) // the default values are used whenever there is a change to the data, to prevent // wrong data being written to the variables. // ALSO: always make sure the variables in the Store and retrieve sections are in the same order. -#define EEPROM_VERSION "V05" +#define EEPROM_VERSION "V06" inline void EEPROM_StoreSettings() { @@ -57,6 +57,7 @@ inline void EEPROM_StoreSettings() EEPROM_writeAnything(i,max_xy_jerk); EEPROM_writeAnything(i,max_z_jerk); EEPROM_writeAnything(i,max_e_jerk); + EEPROM_writeAnything(i,add_homeing); #ifdef PIDTEMP EEPROM_writeAnything(i,Kp); EEPROM_writeAnything(i,Ki); @@ -119,6 +120,13 @@ inline void EEPROM_printSettings() SERIAL_ECHOPAIR(" Z" ,max_z_jerk); SERIAL_ECHOPAIR(" E" ,max_e_jerk); SERIAL_ECHOLN(""); + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("Home offset (mm):"); + SERIAL_ECHO_START; + SERIAL_ECHOPAIR(" M206 X",add_homeing[0] ); + SERIAL_ECHOPAIR(" Y" ,add_homeing[1] ); + SERIAL_ECHOPAIR(" Z" ,add_homeing[2] ); + SERIAL_ECHOLN(""); #ifdef PIDTEMP SERIAL_ECHO_START; SERIAL_ECHOLNPGM("PID settings:"); @@ -153,6 +161,7 @@ inline void EEPROM_RetrieveSettings(bool def=false) EEPROM_readAnything(i,max_xy_jerk); EEPROM_readAnything(i,max_z_jerk); EEPROM_readAnything(i,max_e_jerk); + EEPROM_readAnything(i,add_homeing); #ifndef PIDTEMP float Kp,Ki,Kd; #endif @@ -183,6 +192,7 @@ inline void EEPROM_RetrieveSettings(bool def=false) max_xy_jerk=DEFAULT_XYJERK; max_z_jerk=DEFAULT_ZJERK; max_e_jerk=DEFAULT_EJERK; + add_homeing[0] = add_homeing[1] = add_homeing[2] = 0; SERIAL_ECHO_START; SERIAL_ECHOLN("Using Default settings:"); }