Instead of using the toolhead class to determine if stats should be
reported, allow every printer object with a stats() callback to
determine if stats are needed.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Average clock sync times over approximately 30 seconds instead of 120
seconds so that the clock prediction responds to changes faster.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use both load_config() and load_config_prefix() functions when
dynamically loading a module from the extras directory - if the config
section name has parameters in it then use load_config_prefix().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
OctoPrint (and other software) will sometimes send additional commands
even if the previous command has not yet responded with an "ok".
Change the g-code input reading code to keep reading input so that an
M112 can be detected (and processed out-of-order). To avoid the
extreme case where one writes an entire g-code file to the input
without any pacing, disable the input reading if more than 20 commands
are pending.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If the script being run raises an error, then stop running that script
and return the error to the caller.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Specify hardware pwm cycle times using the same method as software pwm
(in seconds, not clock ticks). Allow the fan code to be configured
with an explicit cycle time even when using software pwm.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If the mcu supports command restarts and it does not appear to use a
real serial port, then default the restart method to 'command'. This
is a better default on boards with native USB support.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Report the current temperature, current pwm setting, and target
temperature as statistics in the log.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add support for disabling homing checks via the homing_override
mechanism. This may be useful to move an axis prior to homing it.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Create a virtual pin that may be used as the z endstop pin on
cartesian printers that use the probe in place of a z endstop.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Allow a set of g-code scripts to be run on each probe invocation.
This may be useful for probes that need to be setup before they are
useful (eg, with servo actuated probes).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Allow users to override the behavior of G28 using a new
"homing_override" config section. This may be used on printers that
require specific steps during the homing process.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The print cooling fan and printer heater_fan are independent modules
that can reside in the extras directory.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Check if a config section matches a python filename in the
klippy/extras/ directory. If it does, load that python code to handle
the config section.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Instead of hardcoding which objects are called on state transitions,
allow any "printer object" to be invoked if it has a printer_state()
method. Convert connect, ready, shutdown, and disconnect callbacks to
this mechanism.
Similarly, allow all printer objects to provide a stats() callback.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add get_reactor(), lookup_object(), lookup_module_objects(), and
set_rollover_info() to the main Printer class so that callers do not
need to peek into the class' members. Similarly, add get_printer()
and get_name() methods to the ConfigWrapper class.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If register_command() is passed None as the function to call, then
treat it as an unregister command request.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use the existing reset_last_position() code in cmd_G28() instead of
manually implementing the logic.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The previous code increases print_stall if a move is proactively
flushed due to buffer_time_low and a follow up move is ready to send
before the existing moves are fully retired. However, this would not
track the case where a move is proactively flushed and it takes an
extended amount of time to get sufficient moves to refill the queue.
Change the code so that print_stall increases anytime a new move is
queued after a proactive flush and there are existing moves not yet
fully retired.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Determine the median period from the pin tuning tests and use that to
recommend a set of PID parameters. Report the results over the g-code
terminal.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Enable all the steppers via the shift registers when the first stepper
is enabled, and disable all the steppers once all steppers are
disabled. This avoids having to enable all the steppers all of the
time. Note that, this support is independent from the current control
for each stepper, which is still done individually.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The enable lines are not one per stepper - instead there are 5
distinct enable settings. Handle them properly.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Change the update_command() call to use a new PinResolver class. In
that new class, verify that the same pin isn't referenced in two
different parts of the config using different aliases for the pin.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It's common for multiple steppers to use the same stepper enable
line. Detect this and only create a single digital_out oid on the
micro-controller.
Also, prohibit any other pin from being used multiple times in the
config file.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Always set the pin_params['type'] field on a pin lookup. Rename
parse_pin_desc() to lookup_pin() to make the change more clear.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The extruder check_move() code will permit moves with huge extrusion
ratios if the amount extruded is tiny. (Some slicers emit these silly
moves - they are allowed because they are harmless.) Unfortunately,
the pressure advance code did not handle the huge extrusion ratios -
it would result in a massive, near instantaneous, extruder move in an
attempt to build pressure in the extruder. Catch this case and limit
the impact to the pressure advance code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Added the pwm_cycle_time option for heater config sections. Defaults
to previous value of 0.100 seconds, but may be reduced to shorter times
at the expense of MCU workload and possible MOSFET heating, depending on
controller design. Some printers that need bed PID to be enabled,
notably the Felixprinters series, are known to benefit from shorter
cycle times, as the default 10hz rate results in excessive voltage
supply droop.
While this option can be used on extruder heaters as well, there
is not expected to be any particular benefit from doing so unless
the extruder heater presents a particularly large load.
Signed-off-by: Andy Silverman <andrewsi@outlook.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add PID_SETTLE_DELTA and PID_SETTLE_SLOPE constants to the code to try
and make it a little more clear how the wait for temperature code
works.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
Store the gcc and binutils versions used in the compilation of the
firmware in the firmware data dictionary. Forward that information to
the log so it is available during debugging.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit 002dc0df added rounding to the homing speed, but it did not
work if the configured homing speed was less than the printer's
maximum velocity. Move the speed rounding from stepper.py to
homing.py and make sure the rounded speed is less than the maximum
speed.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add the ability to alias multiple output pins from a single pin alias.
This makes it possible to support some cases where a single logical
output is driven by multiple output pins.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add the ability to define output pins that may be set at runtime with
a new SET_PIN extended g-code command.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The atmega168 and atmega328 need to define PE0 and PE1 in order to
support the 2 extra analog pins.
Also, support the arduino mappings for the atmega328.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Change the config file so that the delta arm length is specified
per-tower. This makes it possible to support advanced calibration.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use the formulas for trilateration (instead of the circumcenter
formulas) when calculating the position of the nozzle from the
position of the carriages. The trilateration formula is more general
and it allows each tower to have a different arm length.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It's valid to consider the stepper at a position that is not on a step
interval - only the "mcu position" needs to be an integer.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add a new config option 'homing_endstop_align_zero' to enable the
alignment of the endstop to a stepper full step. It's possible one
may wish to specify a homing_endstop_phase while not aligning the
endstop.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
Reset the last step clock during the init phase and after each home -
this simplifies the runtime code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Make sure to always call MCU_endstop.home_wait() if
MCU_endstop.home_start() is invoked. Rename
MCU_stepper.note_homing_triggered() to note_homing_end() and make sure
it is always called if MCU_stepper.note_homing_start() is invoked.
With these changes, MCU_endstop.home_finalize() is no longer needed.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The homing code wants the list of endstops to enable during a homing
operation - it's confusing to pass the steppers.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
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>
Commit e05c6354 changed the internal step compress queue from 64bit
integers to 32bit integers. However, that commit broke the proactive
flushing of moves that could produce more than 64K steps. This could
lead to large memory allocations and cpu slow downs on printers that
had a very large Z axis - possibly leading to a "Timer too close" mcu
shutdown. Correct the code so that it properly generates a 64bit
flush clock.
Also, be sure to only expand / memmove the queue when there is no room
for a new element at the end.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Instead of adding 250ms to each homing operation add a time relative
to the number of estimated steps that are to be generated. This
scales the delay to really large axes without adding a delay for
normal users.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Allow multiple steppers to be defined for a single cartesian axis.
This adds support for dual-z setups.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add wrappers around mcu_endstop and mcu_stepper so that the kinematic
classes do not need to directly access these low-level classes.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
Allow the start value to be different from the default/shutdown value
for the pin. This will be useful for "heater fans" that should
startup in the off state, and transition to full on in a shutdown
state.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
Pass the sample_ticks and sample_count parameters directly in the
end_stop_home command instead. This simplifies the code.
Also, simplify calculation of next wakeup time in
end_stop_oversample_event().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It is possible to have an acceleration greater than max_z_accel on
XY+Z moves. That needs to be taken into account when calculating the
min_stop_interval. This prevents spurious "No next step" MCU errors.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If the stepper phases are known then it is possible to arrange for the
0.0 position to occur at a full step. On cartesian style printer,
this makes it possible for the Z levels to occur at full steps (which
may help reduce "Z ribbing").
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Don't discard samples that are less than 500us from the prediction
regardless of the prediction variance. Also, don't use the prediction
variance in the external time estimate.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Some printers can show occasional noise on the endstop pin. Support
sampling the endstop pin multiple times to attempt to filter out this
noise.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Implement a "moving" linear regression between the reported mcu clock
and the sent_time of the get_status message that generated that
report. Use this linear regression to make predictions on the
relationship between the system time and the mcu clock.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
On a retransmit, the sent_time of the command associated with the
given response message isn't accurate.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Revert commit f37fc775. It is not valid to pass a conservative
frequency to serialqueue.set_clock_est() as that function may not be
called for extended periods - a too low frequency would eventually
lead to "Timer too close" mcu errors.
Instead, increase the 1ms time offset to 5ms to avoid corner cases
that could lead to a message arriving too soon.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This prevents divide by zero errors during stats output if the stats
are generated before a connection completes.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Update the homing code to pass in the start of the homing operation to
toolhead.reset_print_time(). This prevents an error when batch
processing gcode files that contain multiple homing operations.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The logging module can build strings directly from printf syntax - no
need to build the string first.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
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>
Accuracy is not as important as ensuring a message is never sent
before it can be received in the serialqueue code. So, use the
smallest frequency ever seen and add the minimum rtt time when setting
set_clock_est().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use baud_adjust when determining the receive_time of a message read
from the serial port. This improves the accuracy of the clock
synchronization code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Instead of tracking the minimum frequency ever observed, attempt to
track the actual frequency of the micro-controller (relative to the
host clock). This improves the stability of the secondary mcu clocks
when multiple mcus are configured.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add support for configuring and controlling the hardware specific to
the revision "B3" Replicape board.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add support for reading analog values via the standard Linux IIO
interface. This can be used on Replicape boards to sample analog
input pins.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add support for compiling the Klipper micro-controller code as a
real-time process capable of running on standard Linux systems.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add initial support for controlling multiple independent
micro-controllers from a single Klippy host instance. Add basic
support for synchronizing the clocks of the additional mcus to the
main mcu's clock.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Don't directly access any of the mcu class variables externally from
the class. Add wrapper functions for those external callers that need
access to some internal state.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Implement the conversion from print_time to the local mcu's clock
within the C code. This simplifies the python code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Everywhere the data in get_last_clock() is used can be done just as
easily with estimated_print_time().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Now that the print_time is always synchronized with the mcu_time,
there is no longer a need to track mcu_time as a separate quantity.
Eliminate references to mcu_time from the code and pass print_time
directly in its place.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Instead of starting the print_time at zero, start it at the estimated
time of the main mcu's clock. This simplifies the code and it ensures
that print_time never goes backwards.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Make sure to initialize mcu_enable to None so that it is initialized
if no 'enable_pin' config value is provided.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Return the same information from stepcompress_push() that is returned
from stepcompress_push_const() and stpcompress_push_delta().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
On corexy, the stepper velocity of a diagonal move could be greater
than the maximum printer velocity. Account for that when setting the
maximum xy halt velocity in the mcu stepper config.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit 4655a6bf allowed naks to be honored if receive_seq was greater
than the last retransmitted sequence. However, receive_seq is the
receiver's next sequence number, so a nak should only be processed if
it is one greater than that.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Make sure schedule_digital_out and schedule_pwm_out commands always go
out with a value that is in range for the particular command.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Make sure the ADC range sent to the MCU can be encoded into a 16bit
integer. Otherwise, if the provided min_temp/max_temp was outside the
range of possible values it could result in a spurious mcu shutdown.
In particular, the AD595 could not properly encode a min_temp of zero.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Extend the look-ahead mechanism to work between moves that contain Z
movement. This improves Klipper's handling of g-code produced in
"vase mode".
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Allow the kinematic classes to query the max velocity, max accel, and
max halt velocity from the toolhead class instead of having the
toolhead class call into the kinematic classes with those values.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
Invert the if conditional in queue_append() and change the order of
reads in minmax_point() - gcc on the rpi seems to do generate better
code this way.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The RaspberryPi processor implements 'double to int32' conversions
much faster than 'double to int64' conversions. Rework the code so
that steps stored in the queue are always a small offset from the last
sent step time. (In the unlikely event that a step is far from the
last step time, then the queue is flushed to maintain this invariant.)
This simplifies the step compression code as well - it no longer needs
to check for integer overflows.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Create an insertion "cursor" for adding items to the step compression
queue. This makes the calling code simpler and it makes it easier to
update the queue memory management in the future.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The homing operation can be cpu intensive for the host software. Add
a small (250ms) delay before homing so that the host has additional
time to process the command before it is due on the mcu. This is
intended to work around some reports of "timer too close" errors
during Z homing on RPi2 hosts and printers with high precision Z
positioning.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Adjust the configured homing speed so that it always results in a
speed that is an even number of mcu ticks per step. This ensures that
the code can always get good step compression during homing, which is
important as the entire homing operation must be able to fit within
the mcu's move queue. This fixes some "move queue empty" mcu shutdown
errors that could occur when the Z step distance was an unusual size.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Allow external code to obtain the mcu object that controls a pin setup
with setup_pin(). Also, don't bother defining print_to_mcu_time() and
system_to_mcu_time() on each pin object as they can be obtained via
the new get_mcu() method.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit 9d75c3b0 changed the order of allocation for mcu oid integer
ids. However, the stepper oids must always be allocated before
endstop oids so that corexy can register multiple steppers on a single
endstop.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Preface the internal functions to make it more clear which functions
are interfaces to external code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It's no longer necessary to use the TICKS() hack as the config
commands are now all generated after the mcu speed is known.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Support an "ad5206" config section so that one can configure the
digipots found on Reprap "RAMBo" boards.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Allow digital and PWM output pins to be setup via new config
sections. This makes it easier to setup pin configurations.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The MCU() class needs to track the stepqueues so that it can
initialize the steppersync object. Track the stepqueues directly
instead of via the list of steppers.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Track the oid count separately from the configurable object count -
this way it is possible to have internal objects that don't require an
oid in the mcu.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It's not necessary to register and execute "init callbacks" when
configuring the mcu. Instead, have each mcu object produce its init
messages in the build_config() callback.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Allow multiple chips to provide pin mappings (not just the main mcu
chip). Move the pin parsing from the mcu.py code to pins.py and
support mapping from pin descriptions to their corresponding chips and
parameters.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
Store the underlying temperature and resistance values instead of the
Steinhart-Hart coefficents obtained from them. This makes it easier
to add new thermistors.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Keep the homing code separate from the main stepper class. This makes
it easier to verify the correct config parameters are provided.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Instead of limiting the amount of non-acked messages to 50ms, limit
the amount to one round-trip-time. This should make it less likely
that the mcu will be overloaded and it should make retransmits faster.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The first message always has a sync byte with it, so its size should
be one larger. Also, the idle_time should always be the minimum time
that the message could be received, so it should always be reset to
eventtime on a retransmit.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
If a nak message causes a retransmission then also accept a second nak
message as long as it is for a sequence greater than the first nak.
This should allow faster retransmits when there are multiple
transmission errors in a small time period.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Track the sequence number of the message last retransmitted (not the
sequence number of the next message to be transmitted). This fixes a
small possibility of a valid nak not being honored.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>