Commit Graph

181 Commits

Author SHA1 Message Date
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
Wurstnase 39cababb07 dda.c: don't apply feedrate multiplier when searching endstops.
With M220 we can increase the step rate while printing. But when
using this feature it could cause unexpected behaviour while
homing.
2016-11-08 21:21:34 +01:00
Phil Hord 5f6371c53d M220: add support for feedrate override percentage.
Similar to M221 which sets a variable flow rate percentage, add
support for M220 which sets a percentage modifier for the
feedrate, F.

It seems a little disturbing that the flow rate modifies the next
G1 command and does not touch the buffered commands, but this
seems like the only reasonable thing to do since the M221 setting
could be embedded in the source gcode for some use cases.  Perhaps
an "immediate" setting using P1 could be considered later if
needed.
2016-07-09 14:18:06 +02:00
Phil Hord 6679dd6562 dda_create(): treat 'target' as const and input only.
`target` is an input to dda_create, but we don't modify it.  We
copy it into dda->endpoint and modify that instead, if needed.
Make `target` const so this treatment is explicit.

Rely on dda->endpoint to hold our "target" data so any decisions
we make leading up to using it will be correctly reflected in our
math.
2016-07-09 14:17:51 +02:00
Phil Hord 51321910bc M221: use 256 for 100% flow internally for faster math
The flow rate is given as a percentage which is kept as
100 = 100% internally. But this means we must divide by 100 for
every movement which can be expensive.  Convert the value to
256 = 100% so the compiler can optimize the division to a
byte-shift.

Also, avoid the math altogether in the normal case where the
flow rate is already 100% and no change is required.

Note: This also requires an increase in the size of e_multiplier
to 16 bits so values >= 100% can be stored.  Previously flow
rates only up to 255% (2.5x) were supported which may have
surprised some users.  Now the flow rate can be as high as
10000% (100x), at least internally.
2016-07-09 11:42:16 +02:00
wurstnase 9b010e65ee Introduce M221 aka flow-control.
Now it is possible to control the extruders flow.

  M221 S100 = 100% of the extruders steps
  M221 S90  = 90% of the extruders steps

M221 is also used in other firmwares for this. Also a lot of
hosts, like Octoprint and Pronterface using this M-Code for
this behaviour.
2016-07-09 11:42:16 +02:00
Markus Hitter 6cce9d173a DDA: extruders aren't subject to kinematics.
As such, move extruder handling out of dda_kinematics.c into
dda.c.
2016-07-09 11:42:16 +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
Phil Hord 803ff6e8b3 fix ACCELERATION_REPRAP build (moved/extra vars)
REPRAP style acceleration broke quite a while ago, but no one noticed.
Maybe it's not being used, and therefore also not tested. But it should
at least compile while it remains an option.

The compiler complains that dda->n is not defined and that current_id is
never used.  The first bug goes back to f0b9daeea0 in late 2013.

In the interest of supporting exploratory accelerations, fix this to
build when ACCELERATION_REPRAP is chosen.
2016-06-22 19:28:38 -04:00
Phil Hord b317ba086c corexy: Fix new_dda_startpoint for corexy
Add a function axes_um_to_steps to convert from um to steps on all axes
respecting current kinematics setting.

Extend code_stepper_axescode_axes_to_stepper_axes to convert all axes,
including E-axis for consistency.

It seems like axes_um_to_steps could be simplified to something like
"apply_kinematics_axes()" which would just do the transformation math
in-place on some axes[] to move from 'Cartesian' to 'target-kinematics'.
Then the original um_to_steps and delta_um code could remain untouched
since 2014.  But I'm not sure how this will work with scara or delta
configurations. I'm fairly certain they only work from absolute positions
anyway.

Fixes #216.
2016-05-31 15:19:50 -04:00
Phil Hord 90d519af5f dda_clock(): guard against *dda changes in interrupts
dda_clock() might be interrupted by dda_step(), and dda_step might
use or modify variables also being used in dda_clock().  It is
possible for dda to be modified when a new dda becomes live during
our dda_clock().  Check the dda->id to ensure it has not changed on
us before we actually write new calculated values into the dda.

Note by Traumflug: copied some of the explanation in the commit
message directly into the code.
2016-05-21 15:46:10 +02:00
Phil Hord 1eefb28a19 dda_clock(): modify dda->n only in atomic code
dda_clock() might be interrupted by dda_step(), and dda_step might
use or modify variables also being used in dda_clock. In particular
dda->c is modified in both functions but it is done atomically in
dda_clock() to prevent dda_step() from interrupting during the
write.  But dda->n is also modified in both places and it is not
protected in dda_clock().

Move updates to dda->n to the atomic section along with dda->c.

Note by Traumflug: good catch! It even makes the binary 14 bytes
smaller, so likely faster.
2016-05-21 15:45:49 +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
Markus Hitter 82374b8e24 Rename Z_LATE_ENABLE to Z_AUTODISABLE and refine description.
Also turn it on by default for the Mendel printer.

Also add the forgotten Mendel90 printer.
2016-03-27 20:23:05 +02:00
Wurstnase 57afef9fdd Add Z late enable.
Until this commit, the Z axis is disabled after each move and
only enabled when the Z axis will move. Now you can enable this
as a feature. Some printer axes are too heavy or have a high
pitch which are not self locking. In that case simply do nothing.
It's now off by default.
2016-03-27 20:14:04 +02:00
Markus Hitter 5d8e866501 Move interrupt busy detection from dda_clock() to clock tick ISR.
The reason is, interrupts can't be re-entered on ARM, so we need
a different mechanism.
2015-08-12 14:26:37 +02:00
Markus Hitter 7be5212f06 ARM: introduce sei() and cli().
No test, because it's tricky to test, but it compiles and the
firmware still works as before.
2015-08-12 14:26:36 +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
Yiannis Mandravellos fb249214f0 dda.c: fix overflow for large steps/meter values.
The trick is to use doubles earlier. As these calculations are
optimised out anyways, binary size and performance is kept.

Verified to have an identical outcome on a few common steps/mm and
acceleration cases.
2015-06-06 12:04:52 +02:00
Markus Hitter 9dd7426f9d DDA: on short schedules, repeat step routine immediately ...
... instead of trying to fire an interrupt as quickly as possible.
This affects ACCELERATION_TEMPORAL only. It almost doubles the
achievable step rate. Measured maximum step rate (X axis only,
100 mm moves) is 40'000 steps/s on a 16 MHz electronics, so
approx. 50'000 steps/s on a 20 MHz controller, which is even
a bit faster than the ACCELERATION_RAMPING algorithm.

Tests with temporary test code were run and judging by these
tests, clock interrupts are now very reliable up to the point
where processing speed is simply exhaused.

Performance with ACCELERATION_RAMPING: this costs 10 bytes
binary size and exactly 2 clock cycles per step interrupt or
0.6% performance even. We could avoid this with a lot
of #ifdefs, but considering ACCELERATION_TEMPORAL will one
day be the default acceleration, skip these #ifdefs, also
for better code readability.

$ cd testcases
$ ./run-in-simulavr.sh short-moves.gcode smooth-curves.gcode triangle-odd.gcode
    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH  : 20528 bytes         144%        67%        33%      16%
    RAM    :  2188 bytes         214%       107%        54%      27%
    EEPROM :    32 bytes           4%         2%         2%       1%

short-moves.gcode statistics:
LED on occurences: 838.
LED on time minimum: 304 clock cycles.
LED on time maximum: 715 clock cycles.
LED on time average: 310.717 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 8585.
LED on time minimum: 309 clock cycles.
LED on time maximum: 712 clock cycles.
LED on time average: 360.051 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 304 clock cycles.
LED on time maximum: 710 clock cycles.
LED on time average: 332.32 clock cycles.
2015-04-21 02:51:32 +02:00
Markus Hitter 7dda91ab56 dda.c: put code for ACCELERATION_TEMPORAL in dda_step() together.
Performance for ACCELERATION_RAMPING unchanged:

$ cd testcases
$ ./run-in-simulavr.sh short-moves.gcode smooth-curves.gcode triangle-odd.gcode
[...]
    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH  : 20518 bytes         144%        67%        33%      16%
    RAM    :  2188 bytes         214%       107%        54%      27%
    EEPROM :    32 bytes           4%         2%         2%       1%

short-moves.gcode statistics:
LED on occurences: 838.
LED on time minimum: 302 clock cycles.
LED on time maximum: 713 clock cycles.
LED on time average: 308.72 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 8585.
LED on time minimum: 307 clock cycles.
LED on time maximum: 710 clock cycles.
LED on time average: 358.051 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 302 clock cycles.
LED on time maximum: 708 clock cycles.
LED on time average: 330.322 clock cycles.
2015-04-21 02:51:32 +02:00
Markus Hitter 8b88334b06 Rename setTimer() to timer_set() for more consistency.
Pure cosmetical change.

Performance check:

$ cd testcases
$ ./run-in-simulavr.sh short-moves.gcode smooth-curves.gcode triangle-odd.gcode
[...]
    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH  : 20518 bytes         144%        67%        33%      16%
    RAM    :  2188 bytes         214%       107%        54%      27%
    EEPROM :    32 bytes           4%         2%         2%       1%

short-moves.gcode statistics:
LED on occurences: 838.
LED on time minimum: 302 clock cycles.
LED on time maximum: 713 clock cycles.
LED on time average: 308.72 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 8585.
LED on time minimum: 307 clock cycles.
LED on time maximum: 710 clock cycles.
LED on time average: 358.051 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 302 clock cycles.
LED on time maximum: 708 clock cycles.
LED on time average: 330.322 clock cycles.
2015-04-21 02:51:32 +02:00
Markus Hitter a6be2f9584 dda.c: add forgotten variable declaration.
Forgotten in commit 74808610c7,
"DDA: Move axis calculations into loops, part 5.".

This and the previous commit makes ACCELERATION_TEMPORAL building
(and working!) again.
2015-04-21 02:51:31 +02:00
Markus Hitter a303f1ba3e dda.c: complete the rename from all_step to last_step.
Next time, please at least try to compile the code section in
question when explicitely changing the section. In this case,
with ACCELERATION_TEMPORAL enabled. It didn't build.

Was broken with commit 95926a3f113809bde8ff0c84b94c55c73e398f67,
"DDA: Rename confusing variable name.".
2015-04-21 02:51:31 +02:00
Markus Hitter 1cd21251d2 Get rid of STEP_INTERRUPT_INTERRUPTIBLE.
It was certainly a good idea, but also always a suspect of
malfunctions and as such, almost never used. Newer code
organisation moves most of the code behind it to dda_clock()
anyways, so it also became mostly obsolete.

Rest In Peace, STEP_INTERRUPT_INTERRUPTIBLE, you were matter
of quite a number of interesting discussions and investigations.

Changes for Configtool by jbernardis <jeff.bernardis@gmail.com>
2015-04-21 02:11:01 +02:00
Markus Hitter 4c34674b6e dda.c/.h: reduce debounce counting variable.
As we can always only move towards one end of an axis, one common
variable to count debouncing is sufficient.

Binary size 12 bytes smaller (and faster).
2015-01-09 13:11:06 +01:00
Markus Hitter f577431aac home.c, dda.c: consider endstops on both axis ends when homing.
Previously, when backing off of X_MIN, X_MAX was also checked,
which of course was already open, so it signals endstop release
even while X_MIN is still closed. The issue exposed only when
endstops on both ends of an axis were defined, a more rare situation.

Essentially the fix simply makes a distinct endstop check case
for each side of each axis.

This even makes binary size 40 bytes smaller for the standard case.
2015-01-09 13:11:01 +01:00
Markus Hitter cca2994dd8 dda.c: fix debug statement position.
It's always a good idea to read a structure _after_ filling it :-)
2014-12-27 14:47:58 +01:00
Markus Hitter 9fe9c919a4 dda.c: add some TODOs about duplicate and redundant code. 2014-12-26 19:41:38 +01:00
Markus Hitter ab25efbe81 dda.c: abs32() is obsolete now.
It's obsolete, because it's used for signed ints, only.
2014-12-26 19:41:37 +01:00
Markus Hitter 30dd1f4535 CoreXY: separate out bot axes distance calculations.
This also introduces dda_kinematics.c/.h and a KINEMATICS definition,
which allows to do different distance calculations depending on the
bot kinematics in use. So far only KINEMATICS_STRAIGHT, which matches
what we had before, but other kinematics types are present in
comments already.
2014-12-26 19:41:37 +01:00
Markus Hitter 7d2dbaa481 CoreXY, dda.c: use signed delta_steps to simplify dda->delta_um[] calc.
Saves another 8 bytes binary size.
2014-12-26 19:41:37 +01:00
Markus Hitter cca464260b CoreXY, dda.c: use our now signed delta_steps to set direction.
This nicely makes the binary 36 bytes smaller.
2014-12-26 19:41:37 +01:00
Markus Hitter 12f01a783a CoreXY, dda.c: calculate delta steps separately.
This will allow us to use it's sign to set direction.

No binary size increase, optimizer can handle this.
2014-12-26 19:41:37 +01:00
Markus Hitter 41bf99c1aa CoreXY, dda.c: separate bot axes from extruder axes. 2014-12-26 19:41:37 +01:00
Markus Hitter a36b96357e CoreXY, dda.c: start by making steps an array.
Goal is to calculate steps in a separate function to allow different
methods of steps calculation, which is neccessary for supporting
different kinematics types. Accordingly we have to calculate steps
for all axes before setting directions and such stuff.
2014-12-26 19:41:37 +01:00
Markus Hitter c7b022fb3e dda.c: some whitespace cleaning. 2014-10-18 21:02:17 +02:00
Markus Hitter 6c5809f0fa DDA: finally, don't bit-shift dda->c.
This was the goal: to not bit-shift when calling setTimer(). Binary
size another 40 bytes off, about 1.2 % better performance:

    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH : 20136 bytes          141%       66%        32%       16%
    RAM   :  2318 bytes          227%      114%        57%       29%
    EEPROM:    32 bytes            4%        2%         2%        1%

short-moves.gcode statistics:
LED on occurences: 888.
LED on time minimum: 302 clock cycles.
LED on time maximum: 718 clock cycles.
LED on time average: 311.258 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 9124.
LED on time minimum: 307 clock cycles.
LED on time maximum: 708 clock cycles.
LED on time average: 357.417 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 302 clock cycles.
LED on time maximum: 708 clock cycles.
LED on time average: 330.322 clock cycles.
2014-08-31 19:11:49 +02:00
Markus Hitter e098a96bac DDA: don't bit-shift move_c.
Next babystep, tiny enhancement: 8 bytes less binary size.
2014-08-31 19:11:30 +02:00
Markus Hitter b9c38051cc DDA: don't bit-shift dda->c_min.
Another babystep. First results: binary 4 bytes smaller. Yikes!
Ha ha.
2014-08-31 19:11:19 +02:00
Markus Hitter 6880f05f7e DDA: don't bit-shift dda->end_c either.
Next babystep. All changes in ACCELERATION_REPRAP, which isn't
part of current test procedures, so let's cross fingers it was
done right.
2014-08-31 19:11:12 +02:00
Markus Hitter 2541eaf335 DDA: don't bit-shift c_limit, c_limit_calc either.
Admittedly it looks like advancing in babysteps, but really
catching every bit shifting instance isn't trivial, sometimes
these shifts are already embedded in other calculations.

Still no binary size or performance change.
2014-08-31 19:11:04 +02:00
Markus Hitter 4fa755daef dda.c: don't bit-shift c0.
While this shifting meant to increase accuracy, there's no actual
use of it, other than that this value gets shifted back and forth.
Let's start to get rid of it.

Performance stays exactly the same:

    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH : 20188 bytes          141%       66%        32%       16%
    RAM   :  2318 bytes          227%      114%        57%       29%
    EEPROM:    32 bytes            4%        2%         2%        1%

short-moves.gcode statistics:
LED on occurences: 888.
LED on time minimum: 306 clock cycles.
LED on time maximum: 722 clock cycles.
LED on time average: 315.253 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 9124.
LED on time minimum: 311 clock cycles.
LED on time maximum: 712 clock cycles.
LED on time average: 361.416 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 306 clock cycles.
LED on time maximum: 712 clock cycles.
LED on time average: 334.319 clock cycles.
2014-08-31 19:10:56 +02:00
Markus Hitter 4f0a00c1a6 DDA: calculate acceleration for the actual fast axis.
This finally brings Z axis up to speed.

So far we always assumed the fastest axis to have the same steps/mm
as the X axis. In cases where this wasn't true, the movement
wouldn't do sufficient acceleration steps and, accordingly,
not reach the expected maximum speed. This was particularly visible
on a typical Mendel printer, where the Z axis would reach only a
6th of the commanded speed in some configurations.
2014-08-31 19:10:31 +02:00
Markus Hitter 5ee2aebbed DDA: remember number of the fast axis. 2014-08-31 19:10:23 +02: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
Phil Hord 24f5416bba DDA: Rename confusing variable name.
'all_time' sounds like forever to me, but this variable really
tracks the last time we hit one of "all the axes".  It sticks
out more now in looping, so rename it to make sense.
2014-08-31 19:09:24 +02:00
Phil Hord bc4cf20341 Trivial cleanups.
Fix some formatting and hide a couple of variables when they're
not being used.
2014-08-31 19:09:15 +02:00
Phil Hord f9f068596d DDA: Move axis calculations into loops, part 9 (last part).
Clean up code to reduce duplication by consolidating code into
loops for per-axis actions.

Part 9 is, finally use this set_direction() thing. As a dessert
topping, it reduces binary size by another 122 bytes.

    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH : 19988 bytes          140%       66%        32%       16%
    RAM   :  2302 bytes          225%      113%        57%       29%
    EEPROM:    32 bytes            4%        2%         2%        1%
2014-08-31 19:09:07 +02:00
Markus Hitter 96e9ae4dab dda.h: comment on these direction flags and other things. 2014-08-31 19:08:57 +02:00