Commit Graph

3317 Commits

Author SHA1 Message Date
Kevin O'Connor 5ebe8ce025 gcode: Don't dump the message log directly from set_printer_ready()
The set_printer_ready() method can be called from a background thread.
Have the main Printer class call a new dump_debug() method in the main
thread on a shutdown event.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:20:09 -05:00
Kevin O'Connor 17dcb42752 klippy: Validate that options in the config file exist
Check that all options specified in the config file are valid.  This
catches possible typos and spelling errors in variable names that have
a default.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:20:09 -05:00
Kevin O'Connor 2f97b2d7c2 klippy: Add ConfigWrapper.getchoice method
Add helper function that ensures a config option is one of several
choices.  This helps ensure that a proper error is raised if an
invalid choice is made.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:19:44 -05:00
Kevin O'Connor 57244de37d klippy: Throw an exception if any required config parameter is missing
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:19:44 -05:00
Kevin O'Connor 3806ed882a mcu: Raise a config error on an invalid pin name in the config file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:19:44 -05:00
Kevin O'Connor ce7e7c4048 klippy: Report an error if the config file does not exist
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:19:44 -05:00
Kevin O'Connor 524e0290bc klippy: Improve error reporting during connect
Catch exceptions during the connect phase and report them via the
gcode interface to the user.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:19:44 -05:00
Kevin O'Connor dbdf1e137e gcode: Support reading from gcode input before mcu is ready
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:19:43 -05:00
Kevin O'Connor 6ebb1a68cb klippy: separate initial config file load into load_config() method
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:19:43 -05:00
Kevin O'Connor 7e7e607e3f klippy: Create the /tmp/printer pseudo tty before opening config file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:19:43 -05:00
Kevin O'Connor 4eb21a71ae klippy: Defer calling mcu.connect_file() to connect() method
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:19:43 -05:00
Kevin O'Connor 4f07ee4d92 pyhelper: Add ability to route error messages to python logging
Instead of writing error messages to stderr, route them into the
python code and use the standard python logging system.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:19:43 -05:00
Kevin O'Connor b14db404b5 pyhelper: Move helper functions from serialqueue.c to new file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 13:33:16 -05:00
Kevin O'Connor 7cb71df02c mcu: Be careful to free memory allocated in C code
Free steppersync, stepcompress, and commandqueue objects.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 13:33:16 -05:00
Kevin O'Connor 55fc11ff02 serialhdl: Retry opening of serial port
Continually retry to open the serial port.  This helps with connecting
to some micro-controllers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 21:58:48 -05:00
Kevin O'Connor 0d43d269ed serialhdl: Fully deallocate serialqueue on disconnect
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 21:58:48 -05:00
Kevin O'Connor a0829c63de serialhdl: Make SerialReader.send_with_response() blocking
Use the greenlet mechanism to wait for the response directly in the
send_with_response() method.  This simplifies the calling code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 21:58:45 -05:00
Kevin O'Connor 535c7b99b4 serialhdl: Make SerialReader.connect() blocking
Use the greenlet mechanism to wait for the connection to come up in
the serial connect() method.  This simplifies the calling code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 21:57:49 -05:00
Kevin O'Connor 5d805ba550 klippy: Run the MCU connect code within the reactor
Setup the reactor and run the MCU connection code as a timer within
the reactor.  The connection code will make use of reactor greenlets
so that it can wait for events during the connection phase.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 21:54:45 -05:00
Kevin O'Connor bafe796eeb reactor: Add support for greenlets
Add support for greenlets - a mechanism for tasks that can pause while
still allowing regular reactor events to occur.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 21:54:45 -05:00
Kevin O'Connor ceb60ffcc6 mcu: Rename output_file_mode variable to is_fileoutput
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 21:54:40 -05:00
Kevin O'Connor 72c4f353e6 serialqueue: Kick the background thread from serialqueue_exit
Wake the background thread up when exiting - as this makes the exit
complete faster (and have more predictable timing).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 18:49:12 -05:00
Kevin O'Connor 4d6830a373 serialqueue: Fix possible memory leak in serialqueue_extract_old()
Make sure to free all messages even if the requested size is smaller
than the number of messages.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 18:49:12 -05:00
Kevin O'Connor f547cab710 klippy: No need to define __str__ and __init__ methods on exception classes
The base Exception class already defines these methods.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 18:49:12 -05:00
Kevin O'Connor 7835f50722 klippy: Eliminate write_dictionary command line option
The feature is not necessary and it will be difficult to maintain
in the future.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 18:21:57 -05:00
Kevin O'Connor d161d66741 mcu: Handle adc initialization entirely in mcu code
Don't expose the ADC initialization to the gcode and heater code -
instead, register a callback within the MCU_adc class and call it
directly from the MCU class after configuration completes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-29 18:21:56 -05:00
Kevin O'Connor 9755182adf homing: Check homing distance to verify endstop trigger after retract
Instead of checking the endstop trigger directly after a retract move,
verify some distance is traveled during the following homing
operation.  This reduces the amount of synchronization between mcu and
host during homing.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-28 11:23:26 -05:00
Kevin O'Connor a5637bb9d4 mcu: Track the stepper position in the MCU in the MCU_stepper class
Support tracking of both the commanded_position and the mcu_position
in the MCU_stepper class.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-28 11:22:01 -05:00
Kevin O'Connor 1e1364c3d4 mcu: Store the stepper position in the mcu_stepper class
Move the storage of the stepper location from the kinematic classes to
the low-level mcu_stepper class.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-19 11:34:42 -05:00
Kevin O'Connor 7cf914537b stepper: Raise an EndstopError if invalid phase found during homing
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-18 14:39:48 -05:00
Kevin O'Connor ab1972d1cf homing: Verify the endstops are no longer triggered after retract move
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-18 14:17:53 -05:00
Kevin O'Connor e0aa067cc9 homing: Check for timeout during homing operation
Should a homing move complete without hitting the endstop, then
disable motors, disable the endstop checking, and report the error to
the user.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-18 14:17:53 -05:00
Kevin O'Connor 4f30dce64f homing: Add EndstopMoveError wrapper around EndstopError
Allow an EndstopError to be raised without a destination position.
Introduce EndstopMoveError wrapper so that current callers can
continue to pass in a move destination.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-18 14:17:53 -05:00
Kevin O'Connor 2b5b899d35 homing: Direct stepper phase detection from kinematic classes
Change the scheduling of the final homed position (which takes into
account the stepper phases) so that it is scheduled from the kinematic
classes instead of from the toolhead class.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-18 14:04:10 -05:00
Kevin O'Connor 781cf608d7 homing: Create Homing class from gcode
Create the Homing class in the gcode handler instead of in the
kinematic classes.  This will make it easier to pass error messages
back to the user.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-18 14:04:09 -05:00
Kevin O'Connor 9e1059afb4 homing: Create QueryEndstops class from gcode
Create the QueryEndstops in the gcode handler instead of in the
kinematic classes.  This simplifies the gcode handler as it can
directly register its response callback.

Also, store the stepper name in the stepper class.  Also, propagate
the print_time of the query request to the mcu_endstop class.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-18 14:04:09 -05:00
Kevin O'Connor 7ef8c0442a mcu: Remove support for DummyMCU class
It's easier to test with the file output mechanism and the DummyMCU
code has grown stale.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-16 12:09:26 -05:00
Kevin O'Connor 6ab269ceb7 stepcompress: Don't bother loop unrolling in push_sqrt()
It's not necessary to have two loops - checking if factor is greater
than zero in the loop is fine.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-14 15:36:11 -05:00
Kevin O'Connor fd7cb99f47 stepcompress: Optimize safe_sqrt() code
Optimize the code by putting the uncommon case out-of-line.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-14 15:12:53 -05:00
Kevin O'Connor 5a1ec817d4 stepper: Check if the motor needs to be enabled in the kinematic classes
Check for motor enable in the kinematic classes so it doesn't need to
be checked on every move.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-14 13:40:35 -05:00
Kevin O'Connor 9ad8153d33 stepper: Reset the next step time on a stepper stop
Automatically reset the next step time to zero on a stepper_stop()
call.  This makes the host code simpler as it no longer needs to
schedule an explicit reset_step_clock command on the step after a
homing operation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-14 13:10:14 -05:00
Kevin O'Connor 941427554a delta: Initial support for linear delta kinematics
This adds support for delta based robots.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-14 12:35:36 -05:00
Kevin O'Connor 7554c7f694 stepcompress: Do all step rounding in C code
Commits f0cefebf and 8f331f08 changed the way the code determined what
steps to take on fractional steps.  Unfortunately, it was possible in
some situations for the C code to round differently from the python
code which could result in warnings and lost steps.

Change the code so that all fractional step handling is done in the C
code.  Implementing the step rounding logic in one location avoids any
conflicts.

In order to efficiently handle the step rounding in the C code, the C
code has also been extended to directly send the "set_next_step_dir"
command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-13 18:29:45 -05:00
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