diff --git a/config.default.h b/config.default.h index e8a20e9..00987eb 100644 --- a/config.default.h +++ b/config.default.h @@ -44,6 +44,19 @@ #define MOTHERBOARD +/** \def KINEMATICS + + This defines the type of kinematics your printer uses. That's essential! + + Valid values (see dda_kinematics.h): + + KINEMATICS_STRAIGHT Motors move axis directions directly. This is the + traditional type, found in many printers, including + Mendel, Prusa i3, Mendel90, Ormerod, Mantis. +*/ +#define KINEMATICS KINEMATICS_STRAIGHT + + /** \def STEPS_PER_M steps per meter ( = steps per mm * 1000 ) diff --git a/dda.c b/dda.c index 70cd176..9e149f4 100644 --- a/dda.c +++ b/dda.c @@ -13,6 +13,7 @@ #include "dda_maths.h" #include "preprocessor_math.h" +#include "dda_kinematics.h" #include "dda_lookahead.h" #include "timer.h" #include "serial.h" @@ -191,12 +192,10 @@ void dda_create(DDA *dda, TARGET *target) { dda->id = idcnt++; #endif + code_axes_to_stepper_axes(&startpoint, target, delta_um, steps); for (i = X; i < E; i++) { int32_t delta_steps; - delta_um[i] = (uint32_t)abs32(target->axis[i] - startpoint.axis[i]); - - steps[i] = um_to_steps(target->axis[i], i); delta_steps = steps[i] - startpoint_steps.axis[i]; dda->delta[i] = (uint32_t)abs32(delta_steps); startpoint_steps.axis[i] = steps[i]; @@ -217,8 +216,8 @@ void dda_create(DDA *dda, TARGET *target) { int32_t delta_steps; delta_um[E] = (uint32_t)abs32(target->axis[E] - startpoint.axis[E]); - steps[E] = um_to_steps(target->axis[E], E); + delta_steps = steps[E] - startpoint_steps.axis[E]; dda->delta[E] = (uint32_t)abs32(delta_steps); startpoint_steps.axis[E] = steps[E]; diff --git a/dda_kinematics.c b/dda_kinematics.c new file mode 100644 index 0000000..ebaf8eb --- /dev/null +++ b/dda_kinematics.c @@ -0,0 +1,20 @@ +#include "dda_kinematics.h" + +/** \file G-code axis system to stepper motor axis system conversion. +*/ + +#include + +#include "dda_maths.h" + + +void +carthesian_to_carthesian(TARGET *startpoint, TARGET *target, + axes_uint32_t delta_um, axes_int32_t steps) { + enum axis_e i; + + for (i = X; i < E; i++) { + delta_um[i] = (uint32_t)labs(target->axis[i] - startpoint->axis[i]); + steps[i] = um_to_steps(target->axis[i], i); + } +} diff --git a/dda_kinematics.h b/dda_kinematics.h new file mode 100644 index 0000000..96345e3 --- /dev/null +++ b/dda_kinematics.h @@ -0,0 +1,41 @@ +#ifndef _DDA_KINEMATICS_H +#define _DDA_KINEMATICS_H + +#include + +#include "dda.h" + +#define KINEMATICS_STRAIGHT 1 +//#define KINEMATICS_COREXY 2 +//#define KINEMATICS_SCARA 3 + +#include "config_wrapper.h" + + +void carthesian_to_carthesian(TARGET *startpoint, TARGET *target, + axes_uint32_t delta_um, axes_int32_t steps); + +//void carthesian_to_corexy(TARGET *startpoint, TARGET *target, +// axes_uint32_t delta_um, axes_int32_t steps); + +//void carthesian_to_scara(TARGET *startpoint, TARGET *target, +// axes_uint32_t delta_um, axes_int32_t steps); + +static void code_axes_to_stepper_axes(TARGET *, TARGET *, axes_uint32_t, + axes_int32_t) + __attribute__ ((always_inline)); +inline void code_axes_to_stepper_axes(TARGET *startpoint, TARGET *target, + axes_uint32_t delta_um, + axes_int32_t steps) { + #if KINEMATICS == KINEMATICS_STRAIGHT + carthesian_to_carthesian(startpoint, target, delta_um, steps); +// #elif KINEMATICS == KINEMATICS_COREXY +// carthesian_to_corexy(startpoint, target, delta_um, steps); +// #elif KINEMATICS == KINEMATICS_SCARA +// return carthesian_to_scara(startpoint, target, delta_um, steps); + #else + #error KINEMATICS not defined or unknown, edit your config.h. + #endif +} + +#endif /* _DDA_KINEMATICS_H */