Commit Graph

93 Commits

Author SHA1 Message Date
Phil Hord f7ba1e467b Force 32-bit math in abs()
In AVR the labs() function takes a 32-bit signed int parameter. On
the PC it's at least 64-bits and maybe more.  When we have a 32-bit
unsigned value we're taking the labs() of, coercing it to 32-bits
first turns our high-bit into a sign, but coercing it to 64-bits
does not.  This causes all our negative values to appear to be
really big positive ones.

Create a new function abs32() which always coerces its argument to
a int32_t first before return the abs value.  Use that function
whereved needed in dda.c.

This fixes a problem on the simulator which caused negative
direction movements to "never" end.
2013-12-06 19:24:58 +01:00
Markus Hitter fa1a7d4ef7 dda.c: deal with endstop hits while still accelerating.
Also, move_state.step_no must be read atomically.
2013-12-06 19:24:58 +01:00
Markus Hitter 5ee9a0bd3c dda.c: re-enable the hack with overly large rampup steps.
Until we have accurate rampup steps calculations, this hack is
neccessary for endstop searches.
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 2f81386a7a dda.c: simplify start conditions calculation. 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 c1a6c244b3 dda.c: re-gain look-ahead compatibility.
We're here! Incredible high step rates as well as smooth
movements due to look-ahead.
2013-12-06 19:24:58 +01:00
Markus Hitter f0b9daeea0 dda.c/.h: move n and c back into the dda structure.
This is a preparation for starting a move from non-zero speeds,
which is needed for look-ahead. Keeping both variables in
move_state and doing the calculations in dda_start() is possible
in principle, but might not fit the tight time budget we have when
going from one movement to the next at high step rates.

To deal with this, we have to pre-calculate n and c, so we have
to move it back into the DDA structure. It was there a year ago
already, but moved into move_state to save RAM (move_state exists
only once, dda as often as there are movement queue entries).
2013-12-06 19:24:58 +01:00
Markus Hitter 4190d6ffb9 Fix endstop stop condition for clock-based acceleration.
This required a strategy change, since move_state.n is no longer
decreasing in steps of 1.
2013-12-06 19:24:58 +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
Phil Hord c695f1e4f7 Remove stale reference to endstops_stop
This was accidentally left out of the change at 13ec2d75.
2013-11-11 19:03:36 +01:00
Markus Hitter 5df8eeaacf dda.c: fix ACCELERATION_RAMPING #ifdefs. 2013-10-27 20:09:28 +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 3343cfc753 dda.c: more notes on rampup_steps calculation. 2013-10-27 20:01:51 +01:00
Markus Hitter a97c65b940 dda.c: update last_dda also when idle. 2013-10-27 20:01:51 +01:00
Markus Hitter ccec75d9f8 dda.c: allow protected re-entry for time based stepper calculations.
This becomes more important when acceleration is calculated
there, too.
2013-10-27 20:01:51 +01:00
Markus Hitter 13ec2d7521 Move endstop handling into a time-based procedure.
Before, endstops were checked on every step, wasting precious time.
Checking them 500 times a second should be more than sufficient.

Additionally, an endstop stop now properly decelerates the movement.
This is one important step towards handling accidental endstop hits
gracefully, as it avoids step losses in such situations.
2013-10-27 20:01:10 +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 5d6de1761b Enable internal pullups for endstops on demand, only.
The binary size impact is moderate, like 18 bytes plus
4 bytes per endstop defined.

The story is a follows:

The endstop logic can be used to use a touch probe with PCB
milling. Connect the (conductive) PCB surface to GND, the
spindle/mill bit to the signal line, turn the internal pullups
on and there you go.

However, doing so with pullups always enabled and while milling
under (conductive) water showed polished mill and drill bits to
become matte after a few hours of usage. Obviously, this small
0.5 mA current from the pullup resistors going through the
rotating mill bit is sufficient to get some spark erosion going.
That's bad, as spark erosion happening also means tools become
dull faster than neccessary.

With this patch, pullups are turned on while being used, only,
so this sparc erosion should go away.
2012-12-03 19:48:13 +01:00
Ben Gamari 677ebfcccd dda: Fix signed-ness mismatch in handling of dda->e_delta 2012-08-04 22:07:43 +02:00
Markus Hitter 674014cc70 dda.c: remove two, now obsolete warnings. 2012-08-04 22:07:34 +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 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 3d1ebf1186 Review power supply timeout.
- Move the variable from dda.c to pinio.c.

- Reset the timeout on each power on, to guarantee a minimum PSU on time.
2012-07-16 20:13:12 +02:00
Markus Hitter ac22a57329 dda.c: enable update_current_position() for the new E relative handling. 2012-05-11 13:50:49 +02:00
Markus Hitter 9dda3349be Revert the new relative handling for X, Y and Z.
These were commits 9dbfa7217e0de8b140846ab480d6b4a7fc9b6791 and
2b596cb05e621ed822071486f812eb334328267a.

There are several reasons why this new approach didn't work out well:

- The machine coordinate system is lost on relative movements.
  OK, we could keep tracking it, but this would mean even more
  code, so even more chances for bugs.

- With the lost coordinate system, no software endstops are possible.

- Neither of X, Y, Z will ever overflow.

- If a movement planner would appear one day, he'd have to handle
  relative movements as well. Even more code duplication.
2012-05-11 13:50:47 +02:00
Markus Hitter e5cc5ab066 dda.c: Fix a number of minor things, detected by Phord.
These were mistakes introduced with the last commit.
Thanks, Phord!
2012-05-11 13:50:35 +02:00
Markus Hitter 5f9ae5b087 Implement M82/M83 and handle relative movements entirely different.
Instead of converting them to absolute first, then back to
relative and having all the fuzz with working on the queue's
start vs. working at the queue's end, mark a movement as relative
and use this directly.
2012-05-11 13:50:33 +02:00
Markus Hitter 25b72b4ea3 dda.c: remove the hack to set a minimum delay.
This in no longer needed, as the timer handles very short delays
now properly.
2012-03-04 19:03:31 +01:00
Markus Hitter 07fcff1661 dda.c: initialize dda.c properly. 2012-03-04 19:03:20 +01:00
Markus Hitter 1996cb4167 dda.c: axis_to_step = ' ' is no longer needed.
The need for this was a result of failing code in timer.c, which
was fixed in recent commits.
2012-03-04 19:03:07 +01:00
Markus Hitter 962209dceb Teach ACCELERATION_TEMPORAL to respect maximum feedrates. 2012-03-04 19:02:57 +01:00
Markus Hitter e8db35ec76 dda.c: get rid of a unused variable warning. 2012-03-04 19:02:48 +01:00
Markus Hitter fd91ee7e8b dda.c: re-introduce ACCELERATION_TEMPORAL.
The implementation is slightly different this time, as it's not
using these famous bresenham algorithms. The intention is to
allow axis-independent movements, as it's required for
EMC-quality look-ahead.
2012-03-04 19:02:17 +01:00
Markus Hitter 53490bb318 Get rid of defered enabling of the step interrupt again.
This makes the code cleaner and the reduction of code
probably easily compensates for keeping global interrupts
enabled for a bit longer. Talked to macscifi about this.

Saves about 300 bytes of binary size.
2011-11-21 09:54:38 +01:00
Markus Hitter fcd11a6f24 dda.c: get rid of did_step.
We want to stop stepping as there are no steps left, not one step later.

Accordingly, we get rid of a small pause between two movements and
also have to decelerate one step earlier.
2011-11-21 09:54:35 +01:00
Markus Hitter 1ee4668e21 dda.c: also reset startpoint_steps.E on relative extruder movements.
Thanks to bgamari for identifying this bug.
2011-11-17 13:49:08 +01:00
Markus Hitter 64b1a23cd3 dda.c: fix a typo in update_current_position(). 2011-11-17 13:48:48 +01:00
Markus Hitter 4e5f51f01e Store distances in the TARGET strucure in micrometers for all axes.
This extends the previous commit from X to Y, Z and E.
2011-11-17 13:48:36 +01:00
Markus Hitter c96ea0c773 Store distances in the TARGET structure always in micrometers.
This is a intrusive patch and for now, it's done for the X axis only.
To make comparison with the former approach easier ...

The advantages of this change:

- Converting from mm to steps in gcode_parse.c and back in dda.c
  wastes cycles and accuracy.

- In dda.c, UM_PER_STEP simply goes away, so distance calculations
  work now with STEPS_PER_MM > 500 just fine. 1/16 microstepping
  on threaded rods (Z axis) becomes possible.

- Distance calculations (feedrate, acceleration, ...) become much
  simpler.

- A wide range of STEPS_PER_M can now be handled at reasonable
  (4 decimal digit) accuracy with a simple macro. Formerly,
  we were limited to 500 steps/mm, now we can do 4'096 steps/mm
  and could easily raise this another digit.

Disadvantages:

- STEPS_PER_MM is gone in config.h, using STEPS_PER_M is required,
  because the preprocessor refuses to compare numbers with decimal
  points in them.

- The DDA has to store the position in steps anyways to avoid
  rounding errors.
2011-11-17 13:48:26 +01:00
Markus Hitter 2f8a257a0d dda.c: make update_position() work with an empty queue. 2011-10-23 19:52:00 +02:00
Markus Hitter 7a458486ed dda.c: reset ramping after an endstop stop.
As the new homing code ramps up, but not down, we have to reset
move_state.c before starting the next move.
2011-10-23 19:51:55 +02:00
Markus Hitter 2f04a9e58c Update current_position only as needed.
This saves almost 200 bytes and 100 runs of
update_current_position() per second.
2011-10-23 19:51:54 +02:00
Markus Hitter df693c0113 config.h/dda.c: make endstop debouncing steps configurable. 2011-10-23 19:51:46 +02:00
Ben Gamari 45124316e3 Rework endstop homing.
The DDA is now used for motion control.

Note from Traumflug: thanks a lot for this excellent patch, Ben.
2011-10-23 19:51:40 +02:00
Markus Hitter b45969e57a Introduce stepper_enable() and stepper_disable().
This allows to heat up with disables steppers, even if all steppers
share a common enable pin.
2011-10-05 14:13:21 +02:00
Markus Hitter 47d8dedf24 dda.c: move dda->*_steps and dda->*_counter into move_state as well.
Now we're easily back into business with an 8-line buffer queue
on an '168.
2011-05-16 22:09:12 +02:00
Markus Hitter ed77abba31 Move dda->step_no into move_state as well. 2011-05-16 22:09:10 +02:00
Markus Hitter bebb619054 dda.c, RAMPING: 16 bits for move_state.n are sufficient. 2011-05-16 00:16:00 +02:00