From e79c7c47592597b3a2992b5f85b569f766f9ecb4 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sun, 4 Jul 2010 17:48:48 +0200 Subject: [PATCH] Major overhaul of machine.h. All those calculations were confusing complex and made for one type of machine, only. --- mendel/gcode.c | 32 ++++++------- mendel/machine.h | 118 +++++++++++++++++++---------------------------- mendel/mendel.c | 2 +- 3 files changed, 65 insertions(+), 87 deletions(-) diff --git a/mendel/gcode.c b/mendel/gcode.c index 6748913..d8bceba 100644 --- a/mendel/gcode.c +++ b/mendel/gcode.c @@ -391,7 +391,7 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { // G0 - rapid, unsynchronised motion // since it would be a major hassle to force the dda to not synchronise, just provide a fast feedrate and hope it's close enough to what host expects case 0: - gcmd->target.F = FEEDRATE_FAST_XY; + gcmd->target.F = MAXIMUM_FEEDRATE_X; enqueue(&gcmd->target); break; @@ -442,15 +442,15 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { Home XY first */ // hit endstops, no acceleration- we don't care about skipped steps - startpoint.F = FEEDRATE_FAST_XY; - SpecialMoveXY(-250L * STEPS_PER_MM_X, -250L * STEPS_PER_MM_Y, FEEDRATE_FAST_XY); + startpoint.F = MAXIMUM_FEEDRATE_X; + SpecialMoveXY(-250L * STEPS_PER_MM_X, -250L * STEPS_PER_MM_Y, MAXIMUM_FEEDRATE_X); startpoint.X = startpoint.Y = 0; // move forward a bit - SpecialMoveXY(5 * STEPS_PER_MM_X, 5 * STEPS_PER_MM_Y, FEEDRATE_SLOW_XY); + SpecialMoveXY(5 * STEPS_PER_MM_X, 5 * STEPS_PER_MM_Y, SEARCH_FEEDRATE_X); // move back in to endstops slowly - SpecialMoveXY(-20 * STEPS_PER_MM_X, -20 * STEPS_PER_MM_Y, FEEDRATE_SLOW_XY); + SpecialMoveXY(-20 * STEPS_PER_MM_X, -20 * STEPS_PER_MM_Y, SEARCH_FEEDRATE_X); // wait for queue to complete for (;!queue_empty();); @@ -462,15 +462,15 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { Home Z */ // hit endstop, no acceleration- we don't care about skipped steps - startpoint.F = FEEDRATE_FAST_Z; - SpecialMoveZ(-250L * STEPS_PER_MM_Z, FEEDRATE_FAST_Z); + startpoint.F = MAXIMUM_FEEDRATE_Z; + SpecialMoveZ(-250L * STEPS_PER_MM_Z, MAXIMUM_FEEDRATE_Z); startpoint.Z = 0; // move forward a bit - SpecialMoveZ(5 * STEPS_PER_MM_Z, FEEDRATE_SLOW_Z); + SpecialMoveZ(5 * STEPS_PER_MM_Z, SEARCH_FEEDRATE_Z); // move back into endstop slowly - SpecialMoveZ(-20L * STEPS_PER_MM_Z, FEEDRATE_SLOW_Z); + SpecialMoveZ(-20L * STEPS_PER_MM_Z, SEARCH_FEEDRATE_Z); // wait for queue to complete for (;queue_empty();); @@ -488,9 +488,9 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { Home F */ - // F has been left at FEEDRATE_SLOW_Z by the last move, this is a usable "home" + // F has been left at SEARCH_FEEDRATE_Z by the last move, this is a usable "home" // uncomment the following or substitute if you prefer a different default feedrate - // startpoint.F = FEEDRATE_SLOW_XY + // startpoint.F = SEARCH_FEEDRATE_Z break; @@ -509,7 +509,7 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { startpoint.X = startpoint.Y = startpoint.Z = startpoint.E = current_position.X = current_position.Y = current_position.Z = current_position.E = 0; startpoint.F = - current_position.F = FEEDRATE_SLOW_Z; + current_position.F = SEARCH_FEEDRATE_Z; break; // unknown gcode: spit an error @@ -538,8 +538,8 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { do { // backup feedrate, move E very quickly then restore feedrate uint32_t f = startpoint.F; - startpoint.F = FEEDRATE_FAST_E; - SpecialMoveE(E_STARTSTOP_STEPS, FEEDRATE_FAST_E); + startpoint.F = MAXIMUM_FEEDRATE_E; + SpecialMoveE(E_STARTSTOP_STEPS, MAXIMUM_FEEDRATE_E); startpoint.F = f; } while (0); break; @@ -551,8 +551,8 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { do { // backup feedrate, move E very quickly then restore feedrate uint32_t f = startpoint.F; - startpoint.F = FEEDRATE_FAST_E; - SpecialMoveE(-E_STARTSTOP_STEPS, FEEDRATE_FAST_E); + startpoint.F = MAXIMUM_FEEDRATE_E; + SpecialMoveE(-E_STARTSTOP_STEPS, MAXIMUM_FEEDRATE_E); startpoint.F = f; } while (0); break; diff --git a/mendel/machine.h b/mendel/machine.h index 2c91c6c..067391e 100644 --- a/mendel/machine.h +++ b/mendel/machine.h @@ -1,85 +1,56 @@ #ifndef _MACHINE_H #define _MACHINE_H -/* - move buffer size, in number of moves - note that each move takes a fair chunk of ram (69 bytes as of this writing) so don't make the buffer too big - a bigger serial readbuffer may help more than increasing this unless your gcodes are more than 70 characters long on average. - however, a larger movebuffer will probably help with lots of short consecutive moves, as each move takes a bunch of math (hence time) to set up -*/ -#define MOVEBUFFER_SIZE 8 +// -------------------------------------------------------------------------- +// values reflecting the gearing of your machine +// all numbers are integers, so no decimals, please :-) -/* - axis calculations, adjust as necessary -*/ - -// XY can have lots of precision and still move speedily, so microstepping is helpful -#define X_STEPS_PER_REV 3200.0 -#define Y_STEPS_PER_REV X_STEPS_PER_REV - -// we need far more speed than precision on Z due to the threaded rod drive, maybe just half stepping -#define Z_STEPS_PER_REV 400.0 - -#define X_COG_CIRCUMFERENCE (4.77 * 16.0) -#define Y_COG_CIRCUMFERENCE X_COG_CIRCUMFERENCE -// also try: -// #define XY_COG_RADIUS 9.5 -// #define XY_COG_CIRCUMFERENCE (XY_COG_RADIUS * PI * 2) - -// this is the ratio between number of teeth on the Z motor gear, and teeth on the Z leadscrew base gear. -#define Z_GEAR_RATIO 1.0 - -// we need more torque and smoothness at very low speeds on E, maximum microstepping -#define E_STEPS_PER_REV 3200.0 -#define EXTRUDER_SHAFT_RADIUS 5.0 -#define EXTRUDER_INLET_DIAMETER 3.0 -#define EXTRUDER_NOZZLE_DIAMETER 0.8 - -// these feedrates are used during homing and G0 rapid moves -#define FEEDRATE_FAST_XY 6000 -#define FEEDRATE_SLOW_XY 300 - -#define FEEDRATE_FAST_Z 6000 -#define FEEDRATE_SLOW_Z 300 - -#define FEEDRATE_FAST_E 1200 - -// this is how many steps to suck back the filament by when we stop -#define E_STARTSTOP_STEPS 20 - -// extruder settings -#define TEMP_HYSTERESIS 20 -#define TEMP_RESIDENCY_TIME 60 - -/* - calculated values - you shouldn't need to touch these - however feel free to put in your own values if they can be more precise than the calculated approximations, remembering that they must end up being integers- floating point by preprocessor only thanks! -*/ - -#define STEPS_PER_MM_X ((uint32_t) ((X_STEPS_PER_REV / X_COG_CIRCUMFERENCE) + 0.5)) -#define STEPS_PER_MM_Y ((uint32_t) ((Y_STEPS_PER_REV / Y_COG_CIRCUMFERENCE) + 0.5)) -#define STEPS_PER_MM_Z ((uint32_t) ((Z_STEPS_PER_REV * Z_GEAR_RATIO) + 0.5)) +// calculate these values appropriate for your machine +#define STEPS_PER_MM_X 320 +#define STEPS_PER_MM_Y 320 +#define STEPS_PER_MM_Z 320 // http://blog.arcol.hu/?p=157 may help with this next one -// I haven't tuned this at all- it's just a placeholder until I read the above carefully enough -// does this refer to filament or extrudate? extrudate depends on XY distance vs E distance.. hm lets go with filament -// #define STEPS_PER_MM_E ((uint32_t) ((E_STEPS_PER_REV / (EXTRUDER_SHAFT_RADIUS * PI * EXTRUDER_INLET_DIAMETER / EXTRUDER_NOZZLE_DIAMETER)) + 0.5)) +#define STEPS_PER_MM_E 320 -#define STEPS_PER_MM_E ((uint32_t) ((E_STEPS_PER_REV * EXTRUDER_NOZZLE_DIAMETER / EXTRUDER_SHAFT_RADIUS / PI / EXTRUDER_INLET_DIAMETER) + 0.5)) +// this is how many steps to suck back the filament by when we stop +#define E_STARTSTOP_STEPS 20 + +// -------------------------------------------------------------------------- +// values depending on the capabilities of your stepper motors and other mechanics +// again, all numbers are integers + +// used for G0 rapid moves and as a cap for all other feedrates +#define MAXIMUM_FEEDRATE_X 200 +#define MAXIMUM_FEEDRATE_Y 200 +#define MAXIMUM_FEEDRATE_Z 200 +#define MAXIMUM_FEEDRATE_E 200 + +// used when searching endstops and similar +#define SEARCH_FEEDRATE_X 50 +#define SEARCH_FEEDRATE_Y 50 +#define SEARCH_FEEDRATE_Z 50 +#define SEARCH_FEEDRATE_E 50 + +// extruder settings +#define TEMP_HYSTERESIS 20 +#define TEMP_RESIDENCY_TIME 60 + +// -------------------------------------------------------------------------- +// you shouldn't need to edit something below this line // same as above with 25.4 scale factor -#define STEPS_PER_IN_X ((uint32_t) ((25.4 * X_STEPS_PER_REV / X_COG_CIRCUMFERENCE) + 0.5)) -#define STEPS_PER_IN_Y ((uint32_t) ((25.4 * Y_STEPS_PER_REV / Y_COG_CIRCUMFERENCE) + 0.5)) -#define STEPS_PER_IN_Z ((uint32_t) ((25.4 * Z_STEPS_PER_REV * Z_GEAR_RATIO) + 0.5)) -#define STEPS_PER_IN_E ((uint32_t) ((25.4 * E_STEPS_PER_REV * EXTRUDER_NOZZLE_DIAMETER / (EXTRUDER_SHAFT_RADIUS * PI * EXTRUDER_INLET_DIAMETER)) + 0.5)) +#define STEPS_PER_IN_X ((uint32_t) ((25.4 * STEPS_PER_MM_X) + 0.5)) +#define STEPS_PER_IN_Y ((uint32_t) ((25.4 * STEPS_PER_MM_Y) + 0.5)) +#define STEPS_PER_IN_Z ((uint32_t) ((25.4 * STEPS_PER_MM_Z) + 0.5)) +#define STEPS_PER_IN_E ((uint32_t) ((25.4 * STEPS_PER_MM_E) + 0.5)) // inverse, used in distance calculation during DDA setup -#define UM_PER_STEP_X ((uint32_t) ((1000.0 / STEPS_PER_MM_X) + 0.5)) -#define UM_PER_STEP_Y ((uint32_t) ((1000.0 / STEPS_PER_MM_Y) + 0.5)) -#define UM_PER_STEP_Z ((uint32_t) ((1000.0 / STEPS_PER_MM_Z) + 0.5)) -#define UM_PER_STEP_E ((uint32_t) ((1000.0 / STEPS_PER_MM_E) + 0.5)) +#define UM_PER_STEP_X ((uint32_t) ((1000.0 / STEPS_PER_MM_X) + 0.5)) +#define UM_PER_STEP_Y ((uint32_t) ((1000.0 / STEPS_PER_MM_Y) + 0.5)) +#define UM_PER_STEP_Z ((uint32_t) ((1000.0 / STEPS_PER_MM_Z) + 0.5)) +#define UM_PER_STEP_E ((uint32_t) ((1000.0 / STEPS_PER_MM_E) + 0.5)) -// should be the same for all machines! ;) -#define PI 3.1415926535 /* firmware build options @@ -92,4 +63,11 @@ // Xon/Xoff flow control. Should be redundant // #define XONXOFF +/* + move buffer size, in number of moves + note that each move takes a fair chunk of ram (69 bytes as of this writing) so don't make the buffer too big - a bigger serial readbuffer may help more than increasing this unless your gcodes are more than 70 characters long on average. + however, a larger movebuffer will probably help with lots of short consecutive moves, as each move takes a bunch of math (hence time) to set up +*/ +#define MOVEBUFFER_SIZE 8 + #endif /* _MACHINE_H */ diff --git a/mendel/mendel.c b/mendel/mendel.c index 55b24be..0b59f00 100644 --- a/mendel/mendel.c +++ b/mendel/mendel.c @@ -95,7 +95,7 @@ void init(void) { temp_init(); // set up default feedrate - current_position.F = startpoint.F = next_target.target.F = FEEDRATE_SLOW_Z; + current_position.F = startpoint.F = next_target.target.F = SEARCH_FEEDRATE_Z; // enable interrupts sei();