Commit Graph

133 Commits

Author SHA1 Message Date
Kevin O'Connor 3ab9a8d26c gcode: Add support for M221 (set extrude factor) g-code command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-03 17:12:31 -05:00
Kevin O'Connor 5db4886c9c gcode: Add support for M220 (set speed factor) g-code command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-03 17:12:26 -05:00
Kevin O'Connor a0b4cdb5c4 gcode: Don't wait for temperature if the temperature is disabled
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-03 10:33:10 -05:00
Kevin O'Connor 1d276d160f gcode: Dump internal g-code state in dump_debug()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-21 22:27:49 -05:00
Kevin O'Connor 9313e58123 gcode: Group similar G-Code commands together
Group commands by category instead of listing them in numerical
order.  This is just code movement; no code changes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-21 20:58:25 -05:00
Kevin O'Connor f6d4284d5c homing: Directly interact with the kinematic class on query_endstops()
Move the query_endstop logic out of toolhead.py and into homing.py.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 19:13:54 -05:00
Kevin O'Connor 8d9ca6f2dd homing: Directly interact with the kinematic class when homing
Move the homing logic out of toolhead.py and into homing.py.  This
simplifies the toolhead logic and centralizes the homing code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 19:13:54 -05:00
Kevin O'Connor bc9cbc8133 gcode: Move SET_SERVO command from gcode.py to chipmisc.py
Now that commands can be registered dynamically, move the code for
SET_SERVO from gcode.py to the PrinterServo() class in chipmisc.py.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:51 -05:00
Kevin O'Connor b5a41d0dd1 gcode: Rework gcode handler setup to allow dynamic command registration
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:51 -05:00
Kevin O'Connor 64a091fb98 gcode: Add a get_str() method
Add a get_str() method that can extract a required parameter from a
g-code command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:51 -05:00
Kevin O'Connor 80f23441dd gcode: Simplify exception handling
Translate caught exceptions into a gcode.error() exception.  This way
there is one standard place to invoke respond_error().  Also, always
reset the last_position on a handled error.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:51 -05:00
Kevin O'Connor 3a2d16abb3 gcode: Always allow M112 command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-06 18:35:49 -05:00
Kevin O'Connor f8750b142f klippy: Rework shutdown handling
If an MCU signals a shutdown from the background thread, notify the
main thread and handle the shutdown there.  Dispatch shutdown handling
from the main Printer() class instead of from the Toolhead class.
This simplifies the shutdown logic.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 16:28:53 -04:00
Kevin O'Connor d03cf2b83f adccmds: Continue to query analog inputs after a shutdown
Continue to sample the ADC input pins even if the MCU goes into a
shutdown state.  This enables the printer to continue reporting
temperatures even on an mcu error.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor ecf2596469 gcode: Don't warn on fan not present if input is from a file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-11 14:28:19 -04:00
Kevin O'Connor ce9523fb90 gcode: Report the raw MCU position from the M114 command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-03 22:03:52 -04:00
Kevin O'Connor 06420b0ddf gcode: Carry over #original and #command in get_extended_params()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-02 22:06:43 -04:00
Kevin O'Connor 6e5bcc69bc gcode: Make dump_debug() output atomic
Build a single (very large) logging message with the debug state.
This prevents the output from being fragmented.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 11:58:21 -04:00
Kevin O'Connor 8d04d3d8fd gcode: Exit if a shutdown occurs while running in batch mode
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 10:05:11 -04:00
Kevin O'Connor 6dcc44ce2d chipmisc: Add initial support for servos
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 14:21:36 -04:00
Kevin O'Connor 0d13834293 gcode: Fix error that could cause commands to be processed out of order
Commit d0932009 changed the way command handling was performed, and
commit 95950949 fixed a defect in that commit.  Unfortunately, the fix
was incomplete.

If multiple commands were sent to Klippy without waiting for an "ok"
response from Klippy, then it was possible for those additional
commands to be queued and processed after subsequent commands.  This
would result in commands being processed out of order.

Fix this by only reregistering the input fd in the greenlet that
performs the unregistration of the fd.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-02 12:05:51 -04:00
Kevin O'Connor ac53806e04 gcode: Add an ECHO command for debugging purposes
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-02 12:05:51 -04:00
Kevin O'Connor 0c2919b534 klippy: Move restart logic into Printer() class
Move the restart logic out of main() and into Printer.run().  This
simplifies the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-26 18:27:21 -04:00
Kevin O'Connor a42cb4fecf toolhead: Avoid directly accessing the printer.mcu field
Lookup the mcu object from the printer objects and store it locally in
the toolhead class.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-26 18:27:21 -04:00
Kevin O'Connor 268834e4ae klippy: Store printer startup parameters in new "start_args" dictionary
Store pertinent information from the software startup in a dictionary
that the various printer components can access instead of in
individual variables in the Printer() class.  This makes it easier to
add future command-line options.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-25 19:27:05 -04:00
Kevin O'Connor 7bf0ec2fe7 gcode: Don't wait for moves to finish if both debug input and output
Don't wait for moves to finish if the output is going to a debug file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-23 21:32:26 -04:00
Kevin O'Connor 7faa5fe233 gcode: Improve end-of-file handling when input is a debug file
Wait for any pending moves to be fully handled before exiting.  Make
sure the wait is done inside the "self.is_processing_data" check to
avoid infinite recursion.  Don't keep reading from the file while
waiting to exit.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-21 21:22:12 -04:00
Kevin O'Connor 12ca45a264 gcode: Log g-code error responses
Be sure to log g-code errors even if debug logging is not enabled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-17 11:24:15 -04:00
Kevin O'Connor 959509496a gcode: Fix regression causing lost asynchronous commands
Commit d0932009 introduced an error that could cause lost input in
cases where the sender did not wait for an "ok" message before sending
the next command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-11 12:42:11 -04:00
Kevin O'Connor 8419e152bb klippy: Remove some obscure python2 dependencies
Don't modify dictionaries while iterating them and be careful to use
// when doing an integer divide.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-10 00:12:14 -04:00
Kevin O'Connor 1bc3e0a678 klippy: Use newer "except XYZError as e" python syntax
Use the newer syntax for python exceptions.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-10 00:08:06 -04:00
Kevin O'Connor d093200966 gcode: Support running arbitrary gcode on extruder change
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-09 18:55:33 -04:00
Kevin O'Connor 72dc21fb1a gcode: Support for querying and setting multiple extruder heaters
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-09 18:55:30 -04:00
Kevin O'Connor 24b8f4ebc1 extruder: Add initial support for multi-extruders
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-09 18:54:38 -04:00
Kevin O'Connor 01ee9e16c5 klippy: Prefer python dictionary comprehension to dict() call
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-06 12:35:13 -04:00
Kevin O'Connor c9d21574d8 gcode: Check for invalid speeds
Raise an error if the move speed is set to a zero or negative value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-02 07:54:48 -04:00
Kevin O'Connor fc9fb7473c gcode: Don't report an error if turning off an unknown fan or heater
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-01 15:02:27 -04:00
Kevin O'Connor 35a6d9ba87 gcode: Sort the order of commands in HELP
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-26 10:44:22 -04:00
Kevin O'Connor c63754fc32 gcode: Limit build_handlers() method to just building available commands
The set_printer_ready() can be called from a background thread on a
shutdown event, so don't try to lookup the printer components in that
case.  Simplify build_handlers() so that it no longer tests for
components being available - test for component availability in the
command handlers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-26 10:31:58 -04:00
Kevin O'Connor 167b18b58f gcode: Ignore M21 command
No need to recommend users disable "SD card support" in octoprint -
instead, just ignore the M21 command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-20 10:11:10 -04:00
Kevin O'Connor 8920479f85 klippy: Remove CLEAR_SHUTDOWN command
Advice users to issue a FIRMWARE_RESTART command on a printer shutdown
event, and remove support for CLEAR_SHUTDOWN.  A full mcu reset is
preferable and it simplifies the interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-13 14:53:41 -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 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 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 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 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 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 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 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 860fc3e91d gcode: Add support for M115 command
Support querying the firmware type and version.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-28 22:38:29 -05:00
Kevin O'Connor 2e03d84755 gcode: Add support for M400 command
Add ability to fully stall the input until all moves are complete.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-28 22:38:28 -05:00
Kevin O'Connor 219796ef4e gcode: Add a "STATUS" command
Add a status command that will report the current printer status.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-21 11:35:00 -05:00
Kevin O'Connor b099851a8b gcode: Increase initial speed
If a speed is never specified then default to 25mm/s (up from 1 mm/s).
If a user accidentally issues a move without setting the speed, the
default speed shouldn't be so slow that it takes minutes to finish the
move.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-09 17:28:09 -05:00
Kevin O'Connor f25ead109c gcode: Handle M112 emergency stop command
Also try to support the command if it is sent out of order.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-09 17:09:51 -05:00
Kevin O'Connor edd7dfe1c8 gcode: Rework toolhead stalling to use greenlets
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-09 17:09:51 -05:00
Kevin O'Connor 89f5452ddb gcode: Rework homing to use greenlets
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-09 17:09:51 -05:00
Kevin O'Connor a6de1db94d gcode: Rework endstop query to use greenlets
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-09 17:09:51 -05:00
Kevin O'Connor ed9d7e4fae gcode: Convert wait for temp to use greenlets
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-08 18:15:11 -05:00
Kevin O'Connor e169f70bfb gcode: Convert busy handler from timer to greenlet
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-08 18:15:11 -05:00
Kevin O'Connor d2ecc9d80c gcode: Add support for CLEAR_SHUTDOWN command
Add ability to clear the MCU shutdown flag from the console.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-01 00:21:20 -05:00
Kevin O'Connor fbd7cc243b klippy: Add ability to restart the host software
Add a "restart" gcode command that will cause the host "klippy"
software to reload its config and restart.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 23:53:03 -05:00
Kevin O'Connor a6055ce069 gcode: Support parsing of "extended" gcode commands
Support human readable commands (eg, "help").  Add a "help" command to
list these extended commands.

Also, add support for declaring command aliases, command help, and
command availability next to the handlers themselves.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 23:00:29 -05:00
Kevin O'Connor bc80ed4e88 mcu: Detect if the communication channel to the firmware is lost
Detect a comms loss and report it to the user.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-30 21:20:09 -05:00
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 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 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 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 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 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 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 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 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 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 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 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 92f81d51f4 homing: Move low-level coordinate manipulation to kinematic class
Rework the code so that the kinematic class (currently just
cartesian.py) has more control over the homing process.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-25 23:47:30 -04:00
Kevin O'Connor e9c03f2e4a gcode: Error on G20 (set units to inches) command
Respond with an error to a G20 command (instead of effectively
ignoring the command).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-25 22:46:11 -04:00
Kevin O'Connor af99ab1645 extruder: Create a new class and python file to track the printer extruder
Create a new python file (extruder.py) to control the extruder heater
and stepper motors.  This separates the extruder control logic from
the cartesian robot code - making it easier to customize both the
kinematic control of the robot as well as the extruder.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 22:49:02 -04:00
Kevin O'Connor 20ae4e5d98 cartesian: Rename CartKinematics class to ToolHead
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 22:47:13 -04:00
Kevin O'Connor f582a36e4d Initial commit of source code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-05-25 11:37:40 -04:00