Commit Graph

210 Commits

Author SHA1 Message Date
Kevin O'Connor 7fc9ba7d3a mcu: Log the mcu clock each time print_time is synchronized
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-30 12:51:10 -04:00
Kevin O'Connor 5ff2d5aee6 mcu: Defer MCU_adc register_msg until ready to receive messages
Register the callback handler only after it's required state is setup.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-16 14:41:26 -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 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 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 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 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 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 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 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 93d3a6e1d1 klippy: Warn the user on common errors due to old firmware
Check for msgproto.error and warn the user about version firmware
version mismatch.  Raise msgproto.error when extracting firmware
constants.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-10 00:13:28 -05:00
Kevin O'Connor 3a7a77d49e basecmd: Improve accuracy of stats "sumsq" variable
Use a base of 256 instead of 65536 when calculating the sum of the
square of the clock differences in the stats.  This makes the
calculation more accurate.  Export the new base via DECL_CONSTANT for
the host to access.  Use DIV_ROUND_UP() when adjusting for the base to
ensure no lost ticks.  Do the division after multiplication in the
common case where the time between stats_task() invocations is less
than 64K ticks.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-09 23:08:23 -05:00
Kevin O'Connor 91056809dd mcu: Change the default baud rate to 250000
Update the default baud rate in mcu.py to 250000 (as that is the
default in all other places).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-02 12:22:43 -05:00
Kevin O'Connor 6bd5f4e44e stepcompress: Using normal message priority system during homing
The endstop homing system requires all queue_step commands be in the
MCU's 'move queue' before endstop checking starts.  Use the normal
message priority system to request that stepper queue_step commands
are received prior to the start of the end_stop_home command.  This
simplifies the code and removes the need for special serial queue
flushing.

This also fixes a bug in homing operations that take longer than 2^31
clock ticks.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-30 20:14:48 -05:00
Kevin O'Connor d028f42e99 mcu: Don't call steppersync_flush if steppersync not created
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-28 22:38:29 -05:00
Kevin O'Connor a9444d3399 mcu: Log the MCU configuration during connect phase
Log the constants reported by the MCU and log the number of move items
allocated after configuration.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-24 12:33:56 -05:00
Kevin O'Connor 872b08601a mcu: Obtain the maximum adc value from the firmware
Don't assume the hardware ADC has 10bit resultion - instead have the
firmware define a constant and read that constant in the host.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-23 17:06:10 -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 9c932ad514 delta: Rework delta math to avoid using inv_movexy_r
Taking the inverse of the XY move distance can lead to extremely large
values when the XY distance is very small.  This can lead to
saturation of the double precision variables and incorrect results.

Rework the delta kinematic math to avoid using this inverse.  Pass the
closestxy_d value directly to the C functions so that the C code can
calculate its intermediate constants.

After this change the move_z special case is no longer necessary as
the regular delta functions now work with movexy_r=0 and movez_r=1.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-05 14:36:02 -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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 1bbcb51066 mcu: Write initial config commands when in file output mode
When doing serial file output debugging, write the config commands as
they are often useful to inspect.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-10 20:26:52 -04:00
Kevin O'Connor c5f50e73c2 mcu: Consistently use mcu_freq variable name (instead of clock_freq)
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-08-25 12:09:37 -04:00
Kevin O'Connor 7276c7085a mcu: Internally store _print_start_time instead of _print_start_clock
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-08-25 12:07:08 -04:00
Kevin O'Connor e52113a319 mcu: convert stepper, endstop, and digital_out to take mcu_time
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-08-24 16:42:25 -04:00
Kevin O'Connor 11ecac626d mcu: Convert PWM and ADC objects to take mcu_time instead of clock
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-08-24 15:16:02 -04:00
Kevin O'Connor 654546e338 stepper: Support stepper phase adjustments when homing
Add support for enhancing the precision of endstop switches by also
inspecting the phase of the stepper motor when the endstop triggers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-28 11:22:28 -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