Commit Graph

3324 Commits

Author SHA1 Message Date
Kevin O'Connor 79da35d023 stepcompress: Minor code movement
Move flush() and check_expand() code to a new location so that the
stepcompress_push_X() functions can flush.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-12 22:55:27 -05:00
Kevin O'Connor 1dee1ba64e queuelogger: Add support for background log writing
Writing to the debug log can cause an unbounded delay due to disk IO.
This is particularly so on embedded machines such as the Raspberry Pi
that run on SD cards.  These log writing delays can cause problems for
the main processing threads.

The new "queuelogger" code forwards all the main thread log messages
to a queue, and a background thread writes the log messages from the
queue to the destination file.  This eliminates the IO delay from the
main threads.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-12 22:53:43 -05:00
Kevin O'Connor afecf7ce36 stepper: Default to a high direction pin meaning positive direction
Invert the default meaning of the stepper direction pin.  Instead of
treating a low value as position motion, treat a high value as
positive motion.  This matches what other firmwares do, and it matches
what common stepper motor drivers document.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-08 10:39:32 -05:00
Kevin O'Connor 5e6127869a mcu: Do not invert the direction of pullup pins by default
A pullup setting on an input pin (ie, '^') should enable the hardware
pullup resistor, but it should not invert the trigger level (ie, it
should remain trigger on high).  Those that need to change the trigger
level (ie, trigger on low) must now do that explicitly (ie, '^!').
This makes the code match what other firmwares do.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-08 09:29:38 -05:00
Kevin O'Connor 3b5b895a10 heater: Do not require target temperature be above min_extrude_temp
Only disable the extruder if the last measured temperature is below
the minimum extrude temperature setting.  Verifying the target
temperature is not necessary, and it can incorrectly prevent some
valid moves.  It's not uncommon for scripts to retract filament
immiedietly after setting the extruder temperature to zero.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-08 09:22:43 -05:00
Kevin O'Connor 345fc41482 extruder: Don't do pressure advance on velocity changes due to cornering
Due to the lookahead, small changes in the direction of the toolhead
cause minor changes in toolhead velocity.  These "cornering" velocity
changes cause the current extruder code to trigger pressure advance
and its associated pressure retract.  This causes the extruder to
rapidly "jerk" the filament.

This code change updates the extruder to detect velocity changes due
solely to cornering and avoid pressure advance.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 11:06:58 -04:00
Kevin O'Connor 93dd310add extruder: Don't assume start_v matches last end_v in pressure advance
Due to minor differences in the extrude ratio, the last end velocity
of the filament may not exactly match the next move's start velocity
of the filament.  Implement more precise calculations for pressure
advance to take this into account.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 11:06:58 -04:00
Kevin O'Connor a201385008 extruder: Consistently use extrude distance in calculations
Avoid mixing the travel distance of the head (and its associated
velocity and acceleration) with the distance the filament moves.
Instead, use the filament travel distance.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 11:04:50 -04:00
Kevin O'Connor 9d7aa1e155 toolhead: Support calculation of cornering minimum and maximum
Calculate the next "cornering" minimum and maximum for each move.  The
"cornering minimum" is the lowest speed the head will reach
immediately after this move (with no interleaving acceleration or
cruising).  The "cornering maximum" is the maximum speed the head will
reach after the cornering minimum (with no interleaving deceleration
or cruising).

These cornering calculations will be helpful in the extruder "pressure
advance" code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 10:59:36 -04:00
Kevin O'Connor 6285cc6f66 toolhead: Simplify calculation of junction_cruise
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 10:59:36 -04:00
Kevin O'Connor 8e165fecc0 toolhead: Calculate maximum junction start when adding moves
Take into account the maximum possible start speed of a move when
calculating junction_start_max.  This simplifies the lookahead logic.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-05 10:56:47 -04:00
Kevin O'Connor 7c8addc5c5 gpio: Merge gpio_adc_sample_time() into gpio_adc_sample()
Return the number of clock ticks to wait directly from
gpio_adc_sample().  This simplifies the ADC interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-02 17:36:43 -04:00
Kevin O'Connor 5419c456ac docs: Add information on the "move queue" to Firmware_Commands
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-02 13:22:35 -04:00
Kevin O'Connor 2b7ab290b8 mcu: Remove python checks for stepcompress integer overflow
Now that the C code checks for overflow, it is no longer necessary for
the python code to check.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-02 13:22:35 -04:00
Kevin O'Connor 508a934d62 stepcompress: Do 32bit integer overflow checks internally in C code
Update the stepcompress C code to check for integer overflow so that
the python code does not need to.  The new checks also handle the
possibility of a single move lasting long enough to cause an overflow.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-02 13:22:35 -04:00
Kevin O'Connor 8025921fc8 stepcompress: Invert the meaning of the min_clock flag
Use a non-zero qm->min_clock value to indicate that the command uses
the move queue and to also store the clock of when that move queue
item will be released.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-02 10:12:26 -04:00
Kevin O'Connor ff6fef927a stepcompress: Store step times using 64bit integers
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-01 19:38:37 -04:00
Kevin O'Connor 77d486f8d2 sam3x8e: Rework timer priority code to use time instead of event count
Rework the timer prioritization code so that is compares against the
current time instead of the number of repeat timers in a given
interrupt.  This makes the code slightly faster and it should provide
better protection against task starvation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:48:27 -04:00
Kevin O'Connor 233a90ce8b sam3x8e: Clear all bits of PSR register when clearing IRQ status
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:47:57 -04:00
Kevin O'Connor 41ef0bd98c stepstats: Add debugging script to calculate stats on stepper movement
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:15:38 -04:00
Kevin O'Connor f58d93c0bf graphstats: Add new helper script that generates graphs of MCU load
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:15:38 -04:00
Kevin O'Connor 8f331f08d2 extruder: Determine start step offset using last commanded position
The existing code calculates the number of steps in a move and then
spreads them out evenly throughout that move.  Change the code so that
step timing is based on where the head is commanded to be relative to
the stepper step locations.  This makes the timing more accurate - in
particular the stepper velocities will be more accurate during
cornering introduced by the lookahead code.  It also results in
slightly smoother stepper motion which results in better step
compression.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:14:28 -04:00
Kevin O'Connor f0cefebff7 cartesian.py: Determine start step offset using last commanded position
The existing code calculates the number of steps in a move and then
spreads them out evenly throughout that move.  Change the code so that
step timing is based on where the head is commanded to be relative to
the axis step locations.  This makes the timing more accurate - in
particular the axis velocities will be more accurate during cornering
introduced by the lookahead code.  It also results in slightly
smoother stepper motion which results in better step compression.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:06:19 -04:00
Kevin O'Connor 2904a0bbac cartesian: Rename step_dist to move_step_d
Don't use step_dist for the "distance along the line of movement per
step" as it's too similar to the stepper.step_dist variable.  Use the
name "move_step_d" instead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:05:52 -04:00
Kevin O'Connor 6a96e83ea9 toolhead: Store both the start and end position in the Move class
Store the start position (in addition to the existing end position) in
the Move class.  The start position can be useful to the kinematic
classes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-25 19:19:29 -04:00
Kevin O'Connor 306db9a851 build: Be sure to also include out/*.d files in Makefile
Not including the out/*.d build files can cause the build to be
incomplete.  In particular, without this fix, if the code is built for
ARM and then configured for AVR, the build can produce a corrupt AVR
binary.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-21 12:00:03 -04:00
Kevin O'Connor 93bd19a8c2 docs: Todo updates
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-19 13:35:49 -04:00
Kevin O'Connor 98ce7dc465 docs: Add Firmware_Commands.md with information on common firmware commands
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-19 13:35:49 -04:00
Kevin O'Connor 9edf60ffc6 docs: Add Protocol.md with information on host / firmware communication
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-19 13:35:49 -04:00
Kevin O'Connor 884cee27eb sched: Improve AVR optimization of reschedule_timer()
Tweak the AVR register pressure optimization in reschedule_timer() to
optimize it further.  This improves the performance of AVR timers when
there are several pending timers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-19 13:35:48 -04:00
Kevin O'Connor 0f87493487 timer: Rework AVR timer priority code to use time instead of event count
Rework the timer prioritization code so that is compares against the
current time instead of the number of repeat timers in a given
interrupt.  This makes the code slightly faster and it should provide
better protection against task starvation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-19 13:35:48 -04:00
Kevin O'Connor 8be8cb7a91 serial: Increase AVR serial receive buffer
Increase the size of the serial receive buffer.  With transmit rates
of 250000 baud, it only takes a little over a millisecond to overflow
the existing buffer.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-18 15:01:29 -04:00
Kevin O'Connor 977aabe038 stepper: Return homing offset in steps instead of an absolute position
Rename get_homed_position() to get_homed_offset() and return the
endstop position delta in steps instead of an absolute position
relative to position_endstop.  The conversion to absolute positions
can be dependent on the type of kinematics in use, so is inappropriate
to do in the low level stepper.py code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-13 10:09:56 -04:00
Kevin O'Connor da7d8dbcac docs: Add todo list to documentation
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-12 10:06:18 -04:00
Kevin O'Connor 3809e4c055 gcode: Reset current position after an endstop error
If the printer is commanded to an invalid location, reset the current
position to the last successfully commanded position.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-11 15:10:19 -04:00
Kevin O'Connor 7f8a94ff48 heater: Make it possible to disable min_extrude_temp for testing
Allow a config file to specify 'min_extrude_temp: 0' to disable the
minimum extrude temperature test.  This makes it easier to perform
testing on the avr simulator.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-11 00:21:30 -04:00
Kevin O'Connor ee56b14faa mcu: Fix endstop query timeout checking
Commit 0685802c changed the query endstop timeout to use host time
instead of the mcu clock.  However, it is possible for an endstop
homing request to be in the future which makes using the host time
inappropriate.  Revert back to using the mcu clock to determine when
to send an endstop query.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-11 00:21:24 -04:00
Kevin O'Connor ab54fcd443 stepcompress: Check for small negative numbers on sqrt() calls
It's theoretically possible for floating point truncation to cause a
math formula to return a small negative number instead of 0.  If
sqrt() is called on this small negative number it could cause a
crash.  Check for this case and return 0.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-10 11:39:26 -04:00
Kevin O'Connor 9fa0a62c8a stepcompress: Eliminate possible infinite loop in compress_bisect_add()
Commit 47f30331 converted compress_bisect_add() to use "best reach"
instead of "best add".  However, that change caused
compress_bisect_add() to behave poorly when passed in invalid data
(negative times).  Change the code to better handle invalid data.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-10 11:31:56 -04:00
Kevin O'Connor 9faa0fbd25 extruder: Support a minimum extrude temperature
Allow the config file to specify the minimum temperature for the
extruder and check for that temperature prior to moving the extruder
motor.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-30 21:36:51 -04:00
Kevin O'Connor 3167e8ddbe extruder: Remove unnecessary getsection('extruder') call
The passed in config object is already pointing to the 'extruder'
section.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-30 21:36:51 -04:00
Kevin O'Connor b53da365a1 cartesian: Enforce endstop min and max boundaries
Verify that each move command is within range of the configured
minimum and maximum for each axis.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-30 21:36:51 -04:00
Kevin O'Connor 275b386856 toolhead: Allow kinematics class to verify the move prior to queuing it
Introduce a check_move() method in the extruder and cartesian
kinematic classes.  This allows the lower level classes to verify the
contents of the move prior to queing that move.

The speed and acceleration handling for special Z and extrude only
moves are also moved from the generic toolhead class to the low-level
classes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-30 21:27:46 -04:00
Kevin O'Connor e9505697fb gcode: Keep a log of incoming gcode data and report it on a shutdown
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-30 21:27:46 -04:00
Kevin O'Connor 47f303317b stepcompress: Compress for greatest "reach" instead of greatest "add"
Search for the maximum reachable value instead of the maximum "add".
The maximum reachable value encompasses both the maximum count and a
closest step time to the last requested step time.  This allows for
more "add=0" sequences to be generated which the mcu can optimize for.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-24 11:42:06 -04:00
Kevin O'Connor 0685802cb8 homing: Support querying the current status of endstops
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-22 11:29:27 -04:00
Kevin O'Connor c8ff439722 stepper: Disable "no next step" check for some count=1 queue_step commands
It's possible for a "count=1" stepper move immediately after a
set_next_step_dir or reset_step_clock command to be valid and have an
interval less than min_stop_interval.  Make sure this case does not
result in a shutdown.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-22 11:15:17 -04:00
Kevin O'Connor a7b81dc05c toolhead: Force a firmware shutdown on an unhandled exception
Check for unhandled exceptions and force the MCU to shutdown in that
case.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-22 11:15:17 -04:00
Kevin O'Connor 0824d32319 cartesian: Minor change to clarify end stop homing direction code
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-15 12:20:16 -04:00
Kevin O'Connor 9ff5600421 docs: Clarification of some installation and config steps
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-15 12:19:30 -04:00