Commit Graph

23 Commits

Author SHA1 Message Date
Phil Hord 77d8583cca Add dynamic 3-point bed-leveling support
Adds G29 commands to register bed level points.  When three points
are registered, the plane of the bed is calculated and dynamic bed
leveling takes effect.

Add a warning if bed-leveling is enabled when MAX_JERK_Z is zero.
In this case lookahead will always fail when bed-leveling is active
since the Z-axis is not allowed to move during lookahead.
2018-08-20 10:38:10 -07:00
Nico Tonnhofer 56c2238fef dda.c/dda_maths: add int_f_sqrt for controller with FPU
very fast sqrt in hardware
also accurate dda->c for high steps/mm without overflowing
2017-03-03 18:54:57 +01:00
wurstnase 5b11a39155 DDA: make lookahead independent of X.
We calculate all steps from the fastest axis now. So X and Y
steps_per_m don't have to be the same anymore.

Traumflug's: another 16 bytes program size off on AVR, same size
on LPC1114.
2016-11-14 21:43:54 +01:00
wurstnase 2b1f3371c7 DDA: get rid of fast_spm.
We need the fastest axis instead of its steps.

Eleminates also an overflow when ACCELERATION > 596.

We save 118 bytes program and 2 bytes data.

Reviewer Traumflug's note: I see 100 bytes program and 32 bytes
RAM saving on ATmegas here. 16 and 32 on the LPC 1114. Either way:
great stuff!
2016-11-14 21:36:00 +01:00
Markus Hitter 294f0eda26 DDA: have an acceleration constant for each axis individually.
For now, keep behaviour identical, like still use STEPS_PER_M_X.
This is about to change soon.
2014-08-31 19:10:14 +02:00
David Forrest 2496a95c6f dda_maths.h: Add comment on units of C0. 2014-08-31 19:06:34 +02:00
Markus Hitter 9a08675576 Rename all these new PROGMEM variables to end in _P.
Should be done for temptable in ThermistorTable.h, too, but this
would mess up an existing users' configuration.

This tries to put emphasis on the fact that you have to read
these values with pgm_read_*() instead of just using the variable.
Unfortunately, gcc compiler neither inserts PROGMEM reading
instructions automatically when reading data stored in flash,
nor does it complain or warn about the missing read instructions.

As such it's very easy to accidently handle data stored in flash
just like normal data. It'll compile and work ... you just read
arbitrary data (often, but not always zeros) instead of what you
intend.
2014-08-31 19:05:25 +02:00
Phil Hord 427d6637c3 dda_maths.h: remove now obsolete um_to_steps_[xyze]. 2014-08-31 19:04:33 +02:00
Phil Hord 62bdbd86d6 DDA: convert um_to_steps_* to generic implementation.
A generic implementation here will allow callers to pass the
target axis in as a parameter so the callers can also be made more
generic.

Traumflug notes:

Split out application of the new implementation in dda.c into its
own commit.

This actually costs 128 bytes, but as we can access axes from within
a loop now, I expect to get more savings elsewhere.

Interestingly, binary size is raised by another 18 bytes if

  um_to_steps(int32_t, enum axis_e)

is changed to

  um_to_steps(enum axis_e, int32_t)

even on the 8-bit ATmega. While putting the axis number to the
front might be a bit more logical (think of additional parameters,
the axis number position would move), NXP application note
AN10963 states on page 10ff, 16-bit data should be 16-bit aligned
and 32-bit data should be 32-bit aligned for best performance.
Well, so let's do it this way.
2014-08-31 19:04:08 +02:00
Phil Hord 21e5343552 Add config.h wrapper to simplify test automation
Test code which wants to customize config.h can do so without
touching config.h itself by wrapping config.h in a macro variable
which is passed in to the compiler.  It defaults to "config.h" if
no override is provided.

This change would break makefile dependency checking since the selection
of a different header file on the command line is not noticed by make
as a build-trigger.  To solve this, we add a layer to the BUILDDIR path
so build products are now specific to the USER_CONFIG choice if it is
not "config.h".
2014-03-04 19:56:23 +01:00
Markus Hitter 6fae5a8b7c DDA: make macro ACCELERATE_RAMP_LEN_SPM() a function.
This macro is pretty expensive (700 bytes, well, stuff is now
calculated at runtime), so there's no chance to use it in multiple
places and we likely also need this in dda_lookahead.c to achieve
full 4 axis compatibility there.
2014-03-04 19:56:01 +01:00
Markus Hitter 9739382da9 dda.c: remember steps per m of the fast axis for rampup calculation.
For now this is for the initial rampup calculation, only, notably
for moving the Z axis (which else gets far to few rampup steps on
a typical mendel-like printer).

The used macro was verified with this test code (in mendel.c):

[...]
int main (void) {
  init();

  uint32_t speed, spm;
  char string[128];
  for (spm = 2000; spm < 4099000; spm <<= 1) {
    for (speed = 11; speed < 65536; speed *= 8) {
      sersendf_P(PSTR("spm = %lu  speed %lu ==> macro %lu  "),
                 spm, speed, ACCELERATE_RAMP_LEN_SPM(speed, spm));
      delay_ms(10);
      sprintf(string, "double %f\n",
              (double)speed * (double)speed / ((double)7200000 * (double)ACCELERATION / (double)spm));
      serial_writestr((uint8_t *)string);
      delay_ms(10);
    }
  }
[...]

Note: to link the test code, this linker flag is required to add
      the full printf library (which does print doubles):

  LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm
2014-03-04 19:55:53 +01:00
Markus Hitter 46548dba47 DDA: make a huge comment compact and move it to where it belongs.
Also clarify the acceleration formula.
2014-03-04 19:54:53 +01:00
Markus Hitter 3988e47467 Implement Roland Brochards' new acceleration maths clock-based.
His implementation was done on every step and as it turns out,
the very same maths works just fine in the clock interrupt.
Reason for the clock interrupt is: it allows about 3 times
higher step rates.

This strategy is not only substantially faster, but also
a bit smaller.

One funny anecdote: the acceleration initialisation value, C0,
was taken from elsewhere in the code as-is. Still it had to be
adjusted by a factor of sqrt(2) to now(!) match the physics
formulas and to get ramps reasonably matching the prediction
(and my pocket calculator). Apparently the code before
accumulated enough rounding errors to compensate for the
wrong formula.
2013-12-06 19:24:58 +01:00
Roland Brochard a80eff84f8 dda_maths.c/.h: implement an integer inverse square root algorithm.
This 1/sqrt(x) implementation is a 12 bits fixed point implementation
and a bit faster than a 32 bits divide (it takes about 11% less time
to complete) and could be even faster if one requires only 8 bits.
Also, precision starts getting poor for big values of n which are
likely to be required by small acceleration values.
2013-10-27 20:01:51 +01:00
Markus Hitter 1aca61c277 Make lookahead basically working.
This means, modify existing code to let the lookahead algorithms
do their work. It also means to remove some unused code in
dda_lookahead.c and reordering some code to make it work with
LOOKAHEAD undefined.
2013-07-11 22:02:13 +02:00
Markus Hitter 81f85b018d Move utility functions from dda.c to dda_math.c.
Simple cleanup, no functional change.
2012-08-04 22:07:24 +02:00
Markus Hitter e0959f7ce2 Make muldiv() inline instead of a #define, too. 2012-08-04 22:07:15 +02:00
Markus Hitter d49c0745d5 dda_maths.h: make um_to_steps_{xyze}() inline functions.
Size and speed is the same as with #defines, but now there is
type checking.
2012-08-04 22:06:59 +02:00
Markus Hitter 44be918d2a Introduce muldivQR().
This is a version of muldiv() with qn and rn precalculated,
so it can be avoided to re-calclulate it on every instance.

Yet another 116 bytes, unfortunately.
2012-08-04 22:01:30 +02:00
Markus Hitter 0068ed1e26 Use the new muldiv() to replace um_to_steps..().
This gets rid of overflows at micrometer to step conversion as
much as possible within 31 bits. It also opens the door to get
STEPS_PER_M configurable at runtime.

This also costs 290 bytes, unfortunately.
2012-08-04 22:01:16 +02:00
Markus Hitter a2f1412aec Make muldiv() multiplicand signed.
As Andrey correctly pointed out, we need this signed. See:
http://forums.reprap.org/read.php?147,89710,130225#msg-130225
and following posts.
2012-07-16 20:13:43 +02:00
Markus Hitter 7efb895ee3 Introduce an integer multiply-divide algorithm.
We have multiplies followed by divides all over the place and
most of them are difficult to handle regarding overflows. This
new algorithm handles this fine in all cases, as long as all
three operators and the overall result fits into 32 bits.
2012-07-16 20:13:29 +02:00