Commit Graph

222 Commits

Author SHA1 Message Date
Kevin O'Connor 9bb8b0c622 toolhead: Don't raise exception from force_shutdown
Catch and ignore any exceptions when trying to shutdown the printer in
toolhead.force_shutdown() - there's a good chance an exception will be
raised as this method is often called after an invalid internal state
is found.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-16 13:15:25 -04:00
Kevin O'Connor df6d3107f2 stepper: Fix set_min_stop_interval() calculation
The previous calculation was only valid if the stepper is always
commanded to a position that is an exact multiple of the
step_distance.  The safety check was programmed with a value too large
for other commanded positions, which could result in "No next step"
errors.  Fix by changing the calculation to use the worst case
scenario.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-16 13:15:09 -04:00
Kevin O'Connor cbdc54843d gcode: Catch common gcode parameter errors
Don't force a firmware shutdown on a simple gcode parse error.
Instead, report the error back to the user and otherwise ignore the
command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-16 13:13:36 -04:00
Kevin O'Connor d2027cb4a9 serialhdl: Catch SerialException as well as OSError on serial open
Catch the right exceptions so that a retry is possible when attempting
to open the serial port.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-16 12:49:15 -04:00
Kevin O'Connor e60779bfe1 heater: Force set_pwm of zero when target_temp is zero
Fix a corner case where a residual in the PID could cause a non-zero
pwm request even when the target_temp is zero.  (Which could lead to a
firmware "Missed scheduling of next pwm event" shutdown.)

Simplify the logic for suppressing duplicate pwm updates and make sure
a zero target_temp always results in a zero pwm update on the
following set_pwm calculation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-16 12:49:15 -04:00
Kevin O'Connor f66b1ac450 heater: Add support for AD595 type sensors
Add support for sensor chips that produce a voltage that linearly
scales with temperature.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-13 00:48:30 -04:00
Kevin O'Connor ff6a96665a heater: Rename thermistor_type config name to sensor_type
Rename the thermistor_type and thermistor_pin config variables to
sensor_type and sensor_pin.  This is in preparation for support of
sensors beyond thermistors.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-13 00:46:33 -04:00
Kevin O'Connor 4388a294a4 heater: Handle case where min adc value is less than max adc value
When using a sensor that isn't a thermisistor, the maximum and minimum
adc values may be swapped - handle that case.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-13 00:44:53 -04:00
Kevin O'Connor d21b9280f0 klippy: Eliminate high-level build_config phase
Now that the mcu objects can be created prior to connecting to the
mcu, it is no longer necessary to separate the init and build_config
phases in the high-level code.  Move the mcu objection creation from
the build_config phase to the init phase and eliminate the
build_config phase.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-13 00:38:17 -04:00
Kevin O'Connor 92649332ce mcu: Delay setting of mcu_stepper.min_stop_interval
Create a separate callback for setting the min_stop_interval.

Also, move the setting of the stepper max_error from the stepper
configs to the mcu config and rename it to max_stepper_error.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-13 00:38:17 -04:00
Kevin O'Connor be91c1229f gcode: Eliminate build_config() method
Lookup the printer components during the set_printer_ready() callback.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-13 00:38:17 -04:00
Kevin O'Connor 168cb95bd5 mcu: Allow each oid object to define its own build_config() method
Create a build_config() method on each oid object and call it just
after connecting to the MCU.  Move code that requires a connected
state from the oid init to its new build_config method.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-13 00:38:17 -04:00
Kevin O'Connor 1d796a4e24 mcu: Support config mechanism for translating seconds to clock ticks
Introduce a TICKS() macro during config parsing that will translate
time in seconds to time in clock ticks.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-13 00:38:17 -04:00
Kevin O'Connor 8e6d5efdac pins: Simplify pin map alias setup
Use map_pins() to obtain the pin mapping - don't export
mcu_to_pins().  The functionality of mcu_to_pins() can be obtained by
calling map_pins() with name=None.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-13 00:38:15 -04:00
Kevin O'Connor a38437f378 stepper: Introduce stepper_get_position command and remove from endstop.c
Move the logic to calculate and report the stepper's current position
from endstop.c to stepper.c.  This localizes the stepper code into
stepper.c.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-09 14:54:52 -05:00
Kevin O'Connor d5fc594317 mcu: Support inverted PWM pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-09 00:46:53 -05:00
Kevin O'Connor 64407dc5d2 klippy: Support FIRMWARE_RESTART command
Add initial support for micro-controller resets via the Arduino reset
mechanism.  Also, automatically attempt a firmware restart if the
printer CRC does not match.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-08 23:02:31 -05:00
Kevin O'Connor b0329465ec serialhdl: Make sure to close the serial port on disconnect()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-08 23:02:31 -05:00
Kevin O'Connor 0f70b420f2 mcu: Improve error messages on failure to config printer
Don't report a CRC mismatch if a shutdown or other failure occurs
during config - instead report the appropriate details.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-08 21:44:17 -05:00
Kevin O'Connor 21c4dea0e6 serialhdl: Detect timeout in SerialReader.send_with_response()
Raise an error if the response is never received.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-08 21:25:54 -05:00
Kevin O'Connor bcaf818c0e fan: Default to using software PWM
Not all hardware has PWM support and there is no compelling reason to
use hardware PWM for fans.  Change the default to use software PWM.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-08 20:23:09 -05:00
Kevin O'Connor c19af4fb2b serialhdl: Load the mcu's 64bit clock at start of connection
Store a full 64bit uptime in the mcu and query it at the start of each
connection.  This ensures the host's 64bit clock is always in synch
with the mcu's clock.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-03 22:02:27 -05:00
Kevin O'Connor f53897758d heater: Support max_power setting for heaters
Change the mcu PWM value from an integer (0-255) to a float (0. - 1.).
Add support for limiting the maximum power (as measured over a
sufficiently long duration) to a particular heater.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-03 20:00:16 -05:00
Kevin O'Connor 54002c4391 extruder: Pressure advance lookahead time should start after decel
The pressure advance lookahead time should start after any full
deceleration moves.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-03 14:20:41 -05:00
Kevin O'Connor 6a53eaefc0 extruder: Allow configuration of pressure advance lookahead time
Instead of defaulting the pressure advance lookahead time to be the
same as the pressure_advance variable, allow it to be configured.
Default the new config setting (pressure_advance_lookahead_time) to
10ms.

Also, make the setting more accurate if a future move is accelerating
in the middle of the lookahead window.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-22 15:20:22 -05:00
Kevin O'Connor 4bc114336c delta: Simplify maximum stepper velocity and accel checks
Simplify the mechanism for limiting stepper speed (introduced in
commit bdfdf7ef) - split the extreme end of the build envelope into
two zones and use the same speeds for all moves that traverse any part
of one of those zones.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-21 11:18:56 -05:00
Kevin O'Connor 47f1d377f5 heater: Enforce min/max_temp in heater.set_temp()
Raise an error if the user requests a temperate outside the configured
min/max_temp range.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-21 10:48:42 -05:00
Kevin O'Connor 566699f68a toolhead: Fix error in lookahead logic
Commit c24b7a7e reworked the way lookahead was done and it introduced
a bug when a full acceleration move is immiedietly followed by a full
deceleration move.  In that situation, depending on when the lookahead
queue was flushed, it was possible to call move.move() without calling
move.set_junction().  This resulted in a "Move instance has no
attribute 'accel_t'" internal error.

Simplify and fix the logic for checking full accel moves followed by
full decel moves.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-20 12:50:12 -05:00
Kevin O'Connor 29ba92a551 delta: Use position_endstop for position_max
There's no reason for the user to specify position_max - it can be
inferred on deltas from the endstop positions.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-19 11:00:46 -05:00
Kevin O'Connor bdfdf7ef55 delta: Cap maximum stepper velocity and acceleration
Some XY moves at the extreme end of the build envelope could cause
excessive axis stepper movement.  Check for any moves that could
possibly result in a stepper movement of more than 3 times the XY
movement and cap the move's acceleration and speed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-13 21:47:10 -05:00
Kevin O'Connor 9f65ae72c3 delta: Rework boundary checks
Calculate and store the maximum xy2 value for the given z level each
time the head moves to a new z level.  This simplifies the boundary
check for common XY moves.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-13 17:51:13 -05:00
Kevin O'Connor 3434ea540c klippy: Log the type of cpu the host is running on
Report in the log the host CPU type and count.  This helps distinguish
between different rpi versions when debugging the log from a problem
report.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-12 19:14:26 -05:00
Kevin O'Connor 29131c873a gcode: Attempt to shutdown heaters and fans prior to a RESTART
If the user requests a restart and the machine appears to be otherwise
functioning normally, then attempt to stop the heaters and fans prior
to restarting the host.  This prevents the firmware from going into a
shutdown state when the heater is on and the host restarts.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-12 18:48:21 -05:00
Kevin O'Connor ab1eb70d1c toolhead: Rework lookahead flush to be more stable during high cpu
Change the lookahead queue so that it attempts to buffer at least
buffer_time_high amount of moves when first starting a print.  This
helps ensure the buffer is normally always full.

If the buffer falls below buffer_time_low then it is either due to the
end of a print or because octoprint/klippy is unable to keep up.
Change the code so that in this case the lookahead queue will attempt
to gather buffer_time_high amount of moves before restarting movement.

Update the default buffer_time_low to 1 second and buffer_time_high to
2 seconds.  With the above changes a smaller buffer_time_high and a
larger buffer_time_low are more practical.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-12 17:20:40 -05:00
Kevin O'Connor 71256f9456 toolhead: Flush lookahead buffer by time
Use a minimum time window as a heuristic for determining when to try
to lazily flush the lookahead buffer.  In the common case this will
result in more moves processed for each flush and thus reduce the
overall cost of the lookahead processing.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-12 17:20:40 -05:00
Kevin O'Connor 6179839215 toolhead: Separate motor off timer from main flush timer
Move the motor off time checking to its own code.  This simplifies the
main flush handler.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-12 17:20:40 -05:00
Kevin O'Connor 0ca96e543c toolhead: Increase maximum stepper halt velocity
Do a better job of calculating the maximum halt velocity for the
stepper motors.  The maximum cornering velocity is related to both the
maximum acceleration and the junction_deviation, so both should be in
the formula.  Tests show that "math.sqrt(8. * self.junction_deviation
* self.max_accel)" very closely fits the maximum on cartesian robots.

This fixes potential "no next step" shutdowns that could occur on
some print moves.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-12 17:20:40 -05:00
Kevin O'Connor acb0b8f599 klippy: Fix omission causing gcode dump to not function
Fix bug that broke the gcode command dump after a shutdown.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-12 17:19:58 -05:00
Kevin O'Connor 20d0936fa2 reactor: Use the system monotonic clock instead of the normal system clock
The normal system clock can have sudden jumps if the system clock is
changed.  Use the system monotonic clock to avoid these sudden changes
in time.

It appears the Raspbian OS (which is used by OctoPi) is setup to
update the system clock upon network connectivity.  This could cause
sudden system clock changes which could lead to Klippy processing
errors.  Using the monotonic clock eliminates these issues.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-06 13:31:34 -05:00
Kevin O'Connor c24b7a7ef9 toolhead: Introduce "smoothed" acceleration during lookahead
Update the lookahead code to track both normal toolhead acceleration
as well as a pseudo acceleration to the point of deceleration.  This
reduces the top speed of small zig-zag moves and it reduces printer
vibration during these moves.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-06 12:17:50 -05:00
Kevin O'Connor 074495a13a toolhead: Remove unneeded forward pass in MoveQueue.flush()
Simplify the code now that the extruder lookahead is separate from the
main lookahead code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-06 12:17:50 -05:00
Kevin O'Connor e14d86d8b8 toolhead: Remove the do_calc_junction flag
It is not necessary to track the do_calc_junction flag as it can just
as easily be determined at the top of the calc_junction() method.
This simplifies the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-06 12:17:50 -05:00
Kevin O'Connor 528c29c01c extruder: Do extruder lookahead based on time instead of cornering
When calculating the extruder lookahead, determine how far to
lookahead by the amount of elapsed time each move takes.  This makes
the extruder lookahead code more flexible as it is no longer limited
to the next immediate cornering moves.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-06 12:17:50 -05:00
Kevin O'Connor 1bb7a22115 extruder: Move extruder specific lookahead into extruder class
Instead of calculating min/max_corner_v in the toolhead class,
calculate it in the extruder class.  This keeps the extruder specific
code together.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-06 12:17:50 -05:00
Kevin O'Connor 19ed67331d stepcompress: Propagate errors back to python code
Propagate error codes back to the python code and raise an exception
on an error.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-06 12:17:50 -05:00
Kevin O'Connor 667b72870f gcode: Exit on an unhandled exception when reading from a file
When testing via a gcode input file, it's easier to debug problems if
the program exits upon the first exception.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-06 12:17:50 -05:00
Kevin O'Connor 9c1bf1387c toolhead: Make sure max_corner_v2 is fully calculated on a lazy flush
Make sure max_corner_v2 is fully calculated before proactively
flushing moves from the lookahead queue.  Without this, some moves
would do unnecessary pressure advance during cornering.

Also, handle the min/max_corner_v2 calculations correctly in the rare
case where a move that does only acceleration is immediately followed
by a move that does only deceleration.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-16 15:32:35 -05:00
Kevin O'Connor fc6a31eac8 toolhead: Change variables to use suffix "_v2" instead of prefix "junction_"
The junction speeds are tracked in velocity squared - introduce the
common suffix "_v2" to track that instead of using a prefix of
"junction_".

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-16 15:32:35 -05:00
Kevin O'Connor 064e8bdd84 toolhead: Clear do_calc_junction if using non-default accel
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-14 12:48:16 -05:00
Kevin O'Connor f335045273 heater: Resend PWM values even if last value was zero
Continue to resend the pwm value even if the last value was zero -
this extends the debugging info.

Also, add the target temperature to the pwm debugging.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-12 15:13:41 -05:00