Commit Graph

1065 Commits

Author SHA1 Message Date
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
David Forrest 8ddc633531 sersend.c: Make %d, %ld, %sd print signed values. 2014-02-19 13:02:14 +01:00
Markus Hitter 1eaf711923 dda.c: review debug messages a bit. 2013-12-06 19:24:58 +01:00
Phil Hord 199d6d2bb4 Show velocity from simulator trace file
Add a tool (tools/velocity_plot.sh) to read in a simulator trace
file, calculate the velocity of the X and Y axes, and show a plot
of these velocities against time along with the X and Y positions.
2013-12-06 19:24:58 +01:00
Markus Hitter d94e3c7258 Testcases: add save file for GTKWave.
The nice thing about these save files is, they provide a display
for the data, so you simply load a .vcd, additionally read a
save file and you're ready to investigate your movement data.
2013-12-06 19:24:58 +01:00
Markus Hitter 06d496e8ca run-in-simulavr.sh: also output position in micrometers. 2013-12-06 19:24:58 +01:00
Markus Hitter f1873b4360 run-in-simulavr.sh: also record position.
So far only in steps.
2013-12-06 19:24:58 +01:00
Markus Hitter 3ad9ad5594 run-in-simulavr.sh: fix bitfield conversion.
No major thing, even numbers had the last bit set.
2013-12-06 19:24:58 +01:00
Markus Hitter c25547da15 Add a testcase for moves shorter than the acceleration ramps. 2013-12-06 19:24:58 +01:00
Markus Hitter f92b59365e Testcases review:
- comment on why the case exists,

- add an M2 at the end to later allow automatic simulation stop,

- move comments to the end to avoid filling the serial buffer with
  stuff unrelated to movements,

- make sure there's a line ending at the end of the file and

- use Windows line endings (they're more difficult to handle).
2013-12-06 19:24:58 +01:00
Markus Hitter 46526ecdda Add testcase for nullmoves.
Moves which have no movement intention, e.g. pure feedrate changes,
and moves too small to cause a single step, are a bit tricky to
handle with lookahead. Essentially, they should be joined with the
next movement, without queueing them up.
2013-12-06 19:24:58 +01:00
Markus Hitter c594af3e19 dda.c: don't set timer twice when going from one move to the next.
This is a bug which existed, well, basically forever. Nobody noticed
until precision timings could be recorded with SimulAVR.
2013-12-06 19:24:58 +01:00
Markus Hitter 68cc213a70 dda_maths.c: pick a nugget from @phord's distance calculation rework. 2013-12-06 19:24:58 +01:00
Markus Hitter 8a476e2fba Makefile: get rid of the config.h check.
This doesn't work well for developers, because config.h.default is
rewritten all the time when switching branches.
2013-12-06 19:24:58 +01:00
Markus Hitter f37a65ca36 dda_queue.c: run every queued thing through dda_create().
This allows dda_create() to track things queued but not being a movement.
Important for lookahead.
2013-12-06 19:24:58 +01:00
Phil Hord ddd8988727 dda_create(): store prev_dda locally.
This obviously requires less place on the stack and accordingly a
few CPU cycles less, but more importantly, it lets decide
dda_start() whether a previous movement is to be taken into account
or not.

To make this decision more reliable, add a flag for movements done.
Else it could happen we'd try to join with a movement done long
before.
2013-12-06 19:24:58 +01:00
Markus Hitter ec9e84a068 gcode_parse.c: assume G1 only for stuff which might actually move.
Previously, even comments were run through dda_create(), quite a waste
of time.
2013-12-06 19:24:58 +01:00
Phil Hord 96495fb9bb simulator: Make time-scale=0 a cmdline option
Teach the simulator to run with no delays when time-scale=0.

Let the user specify the time-scale on the command line.
2013-12-06 19:24:58 +01:00
Phil Hord c7b43782ce datalog: add a tip showing gnuplot usage
Add a comment to the datalog output showing how it can be viewed with
gnuplot.  It would be trivial to add this as a .plot script, but it's
even easier in the datalog output.
2013-12-06 19:24:58 +01:00
Phil Hord 46bbc09118 Turn dead-code removal back on when not simulavr 2013-12-06 19:24:58 +01:00
Markus Hitter fd5fe676f4 run-in-simulator.sh: express velocities in mm/min, too.
Uh, this bloats the resulting VCD file by 50% ... ;-)
2013-12-06 19:24:58 +01:00
Markus Hitter 5c0808732c run-in-simulator.sh: run (only) selected files. 2013-12-06 19:24:58 +01:00
Markus Hitter e559b59b54 run-in-simulator.sh: use stdin/stdout for the data file, too. 2013-12-06 19:24:58 +01:00
Markus Hitter 005a935adc run-in-simulavr.sh: also rewrite VCD file to add speed values.
This is quite handy, as you can see accurate speed ramps in
GTKWave now.
2013-12-06 19:24:58 +01:00
Markus Hitter 6e4bdc43ca Add a draft of a script running testcases in SimulAVR.
This script also asks SimulAVR to generate pin traces of the X
and Y axis and even processes this data into a data file with
time, position and current speed of each axis.

Missing:

- Acceleration calculation.

- LOTS of polish.
2013-12-06 19:24:58 +01:00
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