Commit Graph

45 Commits

Author SHA1 Message Date
Phil Hord f0fa5f9f3e dda_lookahead.c: reduce size of ATOMIC section.
We calculate a safe join speed in dda_join_moves using data from
two source DDA movements. We ensure the DDA values we use are sane
by atomically copying them to local variables before beginning our
calculation. But later we discard all our results if the DDA went
live in the meantime, as evidenced by changes in `DDA->live` or
`DDA->id`.

Since we will not use the results of our calculations if either of
these change, we can safely reference all the other DDA values
non-atomically. Change the ATOMIC section to protect only the
`DDA->id` values at the start.

Added by Traumflug: this costs a negligible 4 bytes binary size:

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  18082 bytes      127%       59%       29%       15%
     Data:   2176 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%
2016-12-09 22:51:05 +01:00
Wurstnase c33791333c dda_lookahead.c: remove unneeded assignments.
Gcc optimizes them out anyway. No functional change. No surprise,
same binary size.
2016-12-09 19:59:03 +01:00
Markus Hitter 6d95620f32 DDA: don't queue up nullmoves.
Nullmoves are movements which don't actually move a stepper. For
example because it's a velocity change only or the movement is
shorter than a single motor step.

Not queueing them up removes the necessity to check for them,
which reduces code in critical areas. It also removes the
necessity to run dda_start() twice to get past a nullmove.

Best of this is, it also makes lookahead perform better. Before,
a nullmove just changing speed interrupted the lookahead chain,
now it no longer does. See straight-speeds.gcode and
...-Fsep.gcode, which produced different timings before, now
results are identical.

Also update the function description for dda_create().

Performance increase is impressive: another 75 clock cycles off
the slowest step, only 36 bytes binary size increase:

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19652 bytes      138%       64%       31%       16%
     Data:   2175 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%

  short-moves.gcode statistics:
  LED on occurences: 888.
  LED on time minimum: 280 clock cycles.
  LED on time maximum: 458 clock cycles.
  LED on time average: 284.653 clock cycles.

  smooth-curves.gcode statistics:
  LED on occurences: 23648.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 501 clock cycles.
  LED on time average: 307.275 clock cycles.

  triangle-odd.gcode statistics:
  LED on occurences: 1636.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 458 clock cycles.
  LED on time average: 297.625 clock cycles.

Performance of straight-speeds{-Fsep}.gcode before:

  straight-speeds.gcode statistics:
  LED on occurences: 32000.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 586 clock cycles.
  LED on time average: 298.75 clock cycles.

  straight-speeds-Fsep.gcode statistics:
  LED on occurences: 32000.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 672 clock cycles.
  LED on time average: 298.79 clock cycles.

Now:

  straight-speeds.gcode statistics:
  LED on occurences: 32000.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 501 clock cycles.
  LED on time average: 298.703 clock cycles.

  straight-speeds-Fsep.gcode statistics:
  LED on occurences: 32000.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 501 clock cycles.
  LED on time average: 298.703 clock cycles.

There we save even 171 clock cycles :-)
2016-11-27 22:16:56 +01:00
Wurstnase 47dc3aed89 dda_lookahead.c: one more debug variable defined out by default.
Traumflug's note: if one uses #define LOOKAHEAD_DEBUG at line 177,
  one should use the same symbol in line 321. Edited the commit to
  do so.

This reduces binary size by 38 bytes and RAM usage by 4 bytes.
2016-11-20 15:18:37 +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 dc5c9656ed dda_lookahead.c: remove use_lookahead.
Use of this variable is gone 2013. No functional change, no
binary size change.
2016-10-21 21:55:11 +02:00
Markus Hitter bed5dcb210 dda_lookahead.c/.h: more debugging code removal/wrapping.
Program size -76 bytes,
Data size unchanged.
2016-09-06 21:50:33 +02:00
Wurstnase 0e7165f22f dda_lookahead.c/.h: #ifdef's around some debug-variables.
Move debug.h from .c to .h so debug-vars are available when DEBUG
is defined in debug.h.

Program -78 Bytes
Data -8 Bytes

No functional change.
2016-09-06 21:41:41 +02:00
wurstnase 705e4563db DDA: X is not critical anymore.
It's prepared here:

  https://github.com/Traumflug/Teacup_Firmware/commit/294f0eda26

And gone here:

  https://github.com/Traumflug/Teacup_Firmware/commit/4f0a00c1a

Anyhow, we have a calculation with X in dda_lookahead.c

Traumflugs review note: true, at least until we get distinct
acceleration on each axis.
2016-07-02 22:07:27 +02:00
Markus Hitter 9b2c5e61c6 dda_lookahead.c: replace Windows EOL by the usual Unix EOL.
No functional change.
2016-04-26 17:41:21 +02:00
Markus Hitter 0d91b44436 dda_lookahead.c: remove redundant macro.
No functional change.
2016-04-26 17:41:07 +02:00
Markus Hitter c9056e376d dda_lookahead.c: remove two obsolete #includes.
No functional change.
2016-04-26 17:40:57 +02:00
Markus Hitter e633222cd3 Make message/text sending aware of the sending destination.
Point of this change is to allow using these functions for
writing to the display, too, without duplicating all the code.

To reduce confusion, functions were renamed (they're no longer
'serial', after all:

  serwrite_xxx() -> write_xxx()
  sersendf_P()   -> sendf_P()

To avoid changing all the existing code, a couple of macros
with the old names are provided. They might even be handy as
convenience macros.

Nicely, this addition costs no additional RAM. Not surprising, it
costs quite some binary size, 278 bytes. Sizes now:

Program:  24058 bytes      168%       79%       38%       19%
   Data:   1525 bytes      149%       75%       38%       19%
 EEPROM:     32 bytes        4%        2%        2%        1%

Regarding USB Serial: code was adjusted without testing on
hardware.
2016-04-26 15:23:15 +02:00
Phil Hord edae0dd31d Reduce lookahead "error" to "notice"
The marlin firmware reportedly reports "Error" instead of "!!", indicating
a machine failure which is followed by a full power-down.  The Octoprint
GCode-sender assumes a reported Error means the print has failed and
the machine turned off.

In Teacup we report an "Error" when lookahead was too slow to join
movements, but this is interpreted as an emergency-stop by Octoprint who
then stops the job and leaves the printer idle with all the heaters running.

Change this "Error" to a "Notice" to avoid this problem.  Add a comment
prefix while we're at it to fit the de facto standard better.

See http://reprap.org/wiki/G-code
2015-11-18 16:07:35 -05:00
Markus Hitter 5a8d51cb19 ARM: get dda_maths.c, dda_kinematics.c and dda.c in.
All in one chunk, because it's all hardware-independent and doing
them one by one would end up on not more than some typing
exercises.

Compiles fine. For testing, remove if (DEBUG... for M114 in
gcode_process.c. Then one can see how the queue fills up when
sending movements and M114 repeatedly. This time with actual
coordinates.

No stepper movements, yet, because set_timer() is still empty.
2015-08-12 14:26:37 +02:00
Markus Hitter 4e30501868 dda_lookahead.c: remove unused code. 2015-07-30 23:14:01 +02:00
Phil Hord 22b640697b Replace SIMULATOR with __AVR__ in several places.
Previously some features were excluded based on whether SIMULATOR
was defined. But in fact these should have been included when __AVR__
was defined. These used to be the same thing, but now with ARM coming
into the picture, they are not. Fix the situation so AVR includes are
truly only used when __AVR__ is defined.

The _crc16_update function appears to be specific to AVR; I've kept the
alternate implementation limited to AVR in that case in crc.c. I think
this is the right thing to do, but I am not sure. Maybe ARM has some
equivalent function in their libraries.
2015-07-29 21:05:38 +02:00
Markus Hitter 9fe9c919a4 dda.c: add some TODOs about duplicate and redundant code. 2014-12-26 19:41:38 +01:00
Markus Hitter 69e0b0d15e dda_lookahead.c: loop up speed factor calculation, too.
This saves 250 bytes over the previous version, totalling to a
savings of 162 bytes.

... and it's easier to extend beyond 4 axes now, of course.
2014-12-26 19:41:38 +01:00
Markus Hitter 4596dffe10 dda_lookahead.c: put MAX_JERK_{XYZE} into an array.
This costs 88 bytes binary size for now, but will us allow to
loop up a nice section of code.
2014-12-26 19:41:38 +01:00
Markus Hitter 87a0706ff9 dda_lookahead.c: loop up currF, too.
Even more savings this time, 146 bytes binary size.
2014-12-26 19:41:38 +01:00
Markus Hitter b3eba1d062 dda_lookahead.c: loop up prevF calculation.
This saves a whopping 98 bytes binary size.
2014-12-26 19:41:38 +01:00
David Forrest 5b5c44b523 dda_lookahead.c: Eliminate debug crossF variable compile warning.
Fix:
  dda_lookahead.c:327:17: warning: 'crossF' may be used
  uninitialized in this function [-Wmaybe-uninitialized]
       sersendf_P(PSTR("Initial crossing speed: %lu\n"), crossF);
                 ^
2014-08-31 19:06:43 +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 e2f793c2b3 DDA: Convert more axis variables to arrays.
Many places in the code use individual variables for int/uint values
for X, Y, Z, and E.  A tip from a comment suggests making these into
arrays for scalability in the future. Replace the discrete variables
with arrays so the code can be simplified in the future.
2014-08-31 19:03:31 +02:00
Markus Hitter 3da2363ac5 DDA: remember the fast axis micrometers and save their reconstruction.
No surprise, this saves a whopping 600 bytes.
2014-03-04 19:55:45 +01:00
Roland Brochard 297aa28dfd Lookahead: refactored code to compute everything in dda steps. 2014-03-04 19:55:36 +01:00
Markus Hitter 730c1836ad dda_lookahead.c: base ramping calculations on the fast axis.
Previously, ramps were calculated with the combined speed,
which can differ from the speed of the fast axis by factor 2.

This solves part 2 of issue #68.
2014-03-04 19:55:12 +01:00
Markus Hitter 42ad12fba3 DDA: store distance of each movement.
This is required to calculate speeds of individual axes. So far only
in dda_find_crossing_speed(), but soon also in dda_join_moves().
2014-03-04 19:54:41 +01:00
Markus Hitter d10c0f3041 dda.c: clear /all/ lookahead variables when starting.
Catched it! :-)

This was causing occasional step losses when a movement with
zero crossF followed a pair with high crossF.
2014-03-04 19:54:23 +01:00
Markus Hitter 9715b7702d dda_lookahead.c: remember movement distance to avoid recalculation. 2014-03-04 19:52:54 +01:00
Markus Hitter da5339d163 DDA: use the already calculated distance for crossing speed calculation. 2014-03-04 19:52:42 +01:00
Markus Hitter 3ac26f0cab DDA: move dda_find_crossing_speed() to dda.c.
This is a preparation towards going through the existing movement
queue backwards with dda_join_moves() to allow higher feedrates
for lots of short movements.
2014-03-04 19:52:29 +01:00
Phil Hord 88b6101e9a DDA: reduce code duplication and simplify.
There are three locations in the code that repeat a pattern of
"If z=0 then use 2d-approx(dx,dy), else if x==0 && y==0 then use dz,
else use 3d-approx".

Teach approx_distance_3 to detect these conditions for us and apply
the same logic.  Replace the three call locations with a simple call
to approx_distance_3.

Binary size for the LOOKAHEAD case drops by almost 400 bytes:

  old:  FLASH : 21242 bytes          149%       70%        34%       17%
  new:  FLASH : 20844 bytes          146%       68%        33%       17%

The size for non-LOOKAHEAD drops by 40 bytes:

  old:  FLASH : 16592 bytes          116%       55%        27%       13%
  new:  FLASH : 16552 bytes          116%       54%        27%       13%

We can actually do a little better if we consider the zero-ness of all
three axes, but this does make the code a little bit bigger. Another
change will consider that option. This change simply tries to mimic
the existing functionality.
2014-03-04 19:51:56 +01:00
Markus Hitter ed9f56a9d8 look-ahead: move jerk definitions into config.h templates. 2014-03-04 19:29:28 +01:00
Markus Hitter b2063e1182 look-ahead: change crossing speed calculation algorithm.
The new one solely looks at speed differences of individual axes.
This means individual jerks for each axis (good!) and relative
simple maths (also good!).

For details and maths, see comments in the code and
https://github.com/Traumflug/Teacup_Firmware/issues/45 .
2014-03-04 19:29:20 +01:00
Markus Hitter 1b5b40e61d dda_lookahead.c: move crossing speed calculation into a dedicated function.
This is mostly a preparation for reverse walks through the movement queue,
where crossing speed calculation is done only once, while actually used
speeds can be raised successively with repeated walks.
2014-03-04 19:28:48 +01:00
Phil Hord ab65ba6c95 Rename delta -> delta_um to avoid collision. 2013-12-06 19:24:58 +01:00
Phil Hord 452e2e5cd9 Restore simulation build target.
This code was accidentally removed long ago in a botched merge. This
patch recovers it and makes it build again. I've done minimal testing
and some necessary cleanup. It compiles and runs, but it probably still
has a few dust bunnies here and there.

I added registers and pin definitions to simulator.h and
simulator/simulator.c which I needed to match my Gen7-based config.
Other configs or non-AVR ports will need to define more or different
registers. Some registers are 16-bits, some are 8-bit, and some are just
constant values (enums). A more clever solution would read in the
chip-specific header and produce saner definitions which covered all
GPIOs. But this commit just takes the quick and easy path to support my
own hardware.

Most of this code originated in these commits:

	commit cbf41dd4ad
	Author: Stephan Walter <stephan@walter.name>
	Date:   Mon Oct 18 20:28:08 2010 +0200

	    document simulation

	commit 3028b297f3
	Author: Stephan Walter <stephan@walter.name>
	Date:   Mon Oct 18 20:15:59 2010 +0200

	    Add simulation code: use "make sim"

Additional tweaks:

Revert va_args processing for AVR, but keep 'int' generalization
for simulation. gcc wasn't lying. The sim really aborts without this.

Remove delay(us) from simulator (obsolete).

Improve the README.sim to demonstrate working pronterface connection
to sim. Also fix the build instructions.

Appease all stock configs.

Stub out intercom and shush usb_serial when building simulator.

Pretend to be all chip-types for config appeasement.

Replace sim_timer with AVR-simulator timer:

The original sim_timer and sim_clock provided direct replacements
for timer/clock.c in the main code. But when the main code changed,
simcode did not. The main clock.c was dropped and merged into timer.c.
Also, the timer.c now has movement calculation code in it in some
cases (ACCELERATION_TEMPORAL) and it would be wrong to teach the
simulator to do the same thing. Instead, teach the simulator to
emulate the AVR Timer1 functionality, reacting to values written to
OCR1A and OCR1B timer comparison registers.

Whenever OCR1A/B are changed, the sim_setTimer function needs to be
called. It is called automatically after a timer event, so changes
within the timer ISRs do not need to bother with this.

A C++ class could make this requirement go away by noticing the
assignment. On the other hand, a chip-agnostic timer.c would help
make the main code more portable. The latter cleanup is probably
better for us in the long run.
2013-12-06 19:24:58 +01:00
Markus Hitter da77b678e3 look-ahead: take F_end into account on acceleration calculations. 2013-12-06 19:24:58 +01:00
Markus Hitter 83433cb071 look-ahead: take F_start into account on acceleration calculations. 2013-12-06 19:24:58 +01:00
Markus Hitter fe985a18d3 dda_lookahead.c: simplify bailout condition tests.
We have the nullmove flag already and the current move can't be
a nullmove, because in this case we wouldn't enter the function.
2013-10-27 20:01:51 +01:00
Markus Hitter da085670f4 dda_lookahead.c: use the new ATOMIC macros here as well. 2013-07-21 23:28:50 +02: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 e04b69b9c6 Add Cyberwizzards lookahead. Thanks a lot, Cyberwizzard.
For now only the two new files, tweaked a bit in the #ifdef
area to let them compile without LOOKAHEAD being defined.
2013-07-11 22:02:02 +02:00