Commit Graph

835 Commits

Author SHA1 Message Date
Markus Hitter b2e22c6d3b Add another testcase, add lookahead-warmup.
Lookahead-warmup = two lines of G-code which take just long enough
to allow the intended movements to be added with look-ahead.
2013-12-06 19:24:58 +01:00
Markus Hitter 71ae941a09 Add simulation info for SimulAVR.
This shouldn't change the running binary at all, so it shouldn't
harm. However, it allows to run Teacup inside SimulAVR and accessing
Teacups' serial line through the console/terminal.

For detailed instructions, see http://reprap.org/wiki/SimulAVR .
2013-12-06 19:24:58 +01:00
Phil Hord ab65ba6c95 Rename delta -> delta_um to avoid collision. 2013-12-06 19:24:58 +01:00
Phil Hord 3f07a47c06 pinio.h: Fix bug in macro definition
Including a semicolon in a macro function causes problems
when the "function" is called inside an if statement.  Fix
four cases in pinio.h where this error exists but currently
is not harming the code.
2013-12-06 19:24:58 +01:00
Johannes Schriewer (Dunkelstern) 1fb9f8ccd5 Missing member variable for lookahead in DDA struct. 2013-12-06 19:24:58 +01:00
Markus Hitter c8b0da53c1 timer.c: we never managed to recover from an emergency stop ...
... other than by pressing the reset button. Accordingly, save
these 2 clock cycles at step interrupt time.
2013-12-06 19:24:58 +01:00
Phil Hord cfa4857550 simulator: cmdline switches for output options
Teach simulator several command line options to control console output
of info messages, gcode traces, data_recorder output, etc.

Also move gcode output to sim_gcode instead of sending directly to
datarecorder.
2013-12-06 19:24:58 +01:00
Phil Hord 8874397b45 Make data logging optional (internal)
If the recorder is initialized with a filename, write trace data
to that file.  But if it is not initialized, don't complain and
don't write the data anywhere.
2013-12-06 19:24:58 +01:00
Phil Hord 36747e5703 Teach simulator to process gcode files directly
The simulator runs as a device simulator complete with serial port
so it can communicate with printer software like pronterface. But
often we just want to stream it a file of gcode commands and get
some output.  Teach the simulator to take a regular file as input
and process it as a file of gcode commands if it is not a device.
2013-12-06 19:24:58 +01:00
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
Phil Hord c86a51bd5c Add gnuplot script to explore simulator output
research/datalog.plot is a gnuplot script to plot pin outputs like
a logic analyzer and x/y/z positions as well. It's quite rudimentary
but it does recognize some keyboard commands to pan and zoom.

Be careful with keyboard repeat getting too far ahead of you.
2013-12-06 19:24:58 +01:00
Phil Hord daec29f69c Simulator: slow to 1/10th real-time
Reduce the simulated timer to 1/10 actual time.  There is no need
for the simulator to run at full speed for now, and some PCs may
not be able to attain real-time speed anyway due to PC clock
speed, scheduler slack or OS differences.

Maybe the simulated timer interrupt is not needed at all and some
cooperative timer interrupt could be used instead.  Such a setup
may even run faster as it could also run >1.0x time when there is
nothing to do.  This bears investigation later.  For now, the
simulated timer interrupt seems more realistic and possibly valuable.
2013-12-06 19:24:58 +01:00
Phil Hord cf015623e3 simulator: Add position to datalog.out
Cleanup datalog output a bit.
  * Add close/flush on exit in case we have pending data
  * Use hash for comment characters to be compatible with gnuplot
  * Report x/y/z/e position in array
2013-12-06 19:24:58 +01:00
Phil Hord 1db17acc03 Simulator: don't try to schedule zero time. 2013-12-06 19:24:58 +01:00
Phil Hord 2b8a5d3b5a simulator: record g-codes in datalog
Add comment stream to datalog output so we can store g-codes and
other events that occur during simulation.
2013-12-06 19:24:58 +01:00
Phil Hord 18c68b5fe4 simulator: Add nano-timer to datalog 2013-12-06 19:24:58 +01:00
Phil Hord 3ff7e86728 Simulator cleanup 2013-12-06 19:24:58 +01:00
Markus Hitter c5871d0303 gcode_process.c: show endstop status in clear text.
This costs 40 bytes, but should be a significant enhancement on
usability.
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 28cc8d3f84 Makefiles: auto-dependencies cleanup.
Dependency automation seems a bit confused in these makefiles.
Clean it up following ancient sage wisdom here:
http://mad-scientist.net/make/autodep.html

In short, use -MMD to generate dependency files for each .o target,
and then use a sed script to extend that to avoiding "missing file"
dependencies when headers are renamed/removed.

Also, make everything dependent on makefiles other than our
autodependency (*.P) makefiles.

Make the BUILDDIR an order-only prerequisite for our targets so any
changed file therein does not cause all other files to appear to be
out of date.
2013-12-06 19:24:58 +01:00
Phil Hord d8f61faaac Split Makefile-SIM out from Makefile-AVR.
Also, some makefile cleanup:

 - Remove obsolete 'depend' target.
 - Move AVR-specific targets to AVR makefile.
 - Add TARGET variable to identify target to make and to clean.
 - Tidy up dependency make.
2013-12-06 19:24:58 +01:00
Phil Hord 18ea439788 simulator: fix timer overflow problem
Next-interrupt-time calculations were made in 16-bit registers but
moved to 32-bit ones for convenience.  But they forgot to round off
at 16-bits.  Force the round-off so we do not wait forever.
2013-12-06 19:24:58 +01:00
Phil Hord 1e2824d56b WIP: Add simulator data-logging.
Record simulation run-time data in file 'datalog.out' so it
can be analyzed after-the-fact or during the run.

This feature is evolving. Eventually it should be compatible with
some logic analyzer GUIs such as gtkwave or even gnuplot.
2013-12-06 19:24:58 +01:00
Phil Hord a81f35022a Add debug pin-tracing code for investigation. 2013-12-06 19:24:58 +01:00
Phil Hord b65efe9b03 Move argc/argv processing deeper into simulator.
Less magic == more better.
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
Markus Hitter 921348c474 config.ramps-v1.3.h: enable extruder axis.
Spotted by @itscipher:

http://forums.reprap.org/read.php?147,272712,273344

Thank you for the contribution!
2013-11-29 11:14:24 +01:00
Markus Hitter ff9fdafa3c Add another testcase, triangle-odd.gcode.
This was found to expose a bug, see Github issue #67.
2013-11-28 23:43:10 +01:00
Markus Hitter 0eecdf895b Temperature tables: add missing const qualifiers.
Spotted and fixed by wrtlprnft, thanks for the contribution.
2013-11-16 17:31:28 +01:00
Markus Hitter d0bea9b51a Add another look-ahead testcase. 2013-11-11 19:03:52 +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
Phil Hord 498779d7ab gcode-process.c: fix HEATER_EXTRUDER reference.
A rare combination of factors makes this code assume HEATER_EXTRUDER
always exists, when that is not necessarily so.  Add the normal
guard around it.
2013-11-11 19:02:52 +01:00
Markus Hitter 89c85181f7 Add a testcase for look-ahead (smooth curves). 2013-11-11 19:00:31 +01:00
Markus Hitter 59e461104b Add a testcase with excessive digits left to the decimal.
Currently, Teacup can't handle this.
2013-11-11 12:25:17 +01:00
Markus Hitter 00af5bd266 dda_queue.c: fix no longer true comment. 2013-11-08 21:38:04 +01:00
Markus Hitter 1ab42ee8eb Move the branch accel_clock into the attic.
This was a very interesting approach, but for the forseeable
future it's unlikely the code will replace the current one.

However, many parts of it were already moved to the experimental
branch. It turns out the approach with recalculating acceleration
at a constant time interval is exactly right, but works much more
precisely when keeping maths step-based.
2013-10-27 20:31: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 ed6a66c25d timer.c: the concept of a "new move" was abandoned long time ago.
This doesn't matter much, as the timer overflows 300 times/second
worst case, so the very first step of a series of moves is
delayed never more than 30 milliseconds. Hardly recognizeable
by a human.

Saves a nice 40 bytes and improves max step rate by several percent.
2013-10-27 20:01:51 +01:00
Markus Hitter 0c100fe5f8 According to avr-libc documentation, ISR() handles SREG its self. 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