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>
If a retransmit is triggered by a nak, then it is not necessary to
increase the rto. The next retransmit time should be based on the
expected reception of the first retransmitted message, not the last.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
The existing clock synchronization code has two flaws: intermittent
transmission latency during get_status requests can cause the
estimated clock to be too low, and the estimated clock calculation did
not take into account possible clock drift between samples. The
former could potentially lead to "Timer too close" errors and the
latter could potentially lead to "Move queue empty" errors.
Rework the code to avoid the above problems. It's not necessary to
estimate the micro-controller clock as an excellent estimate is
reported by the micro-controller (via the CLOCK_FREQ constant).
Account for a small drift from the reported value, and check on each
sample if the drift exceeds the expected limits. With a good starting
estimated clock, only the offset needs to be calculated. Use previous
offsets (and the estimated clock) in calculation of new offsets to
avoid intermittent latency from badly skewing the results. Finally,
add an additional time offset of one millisecond to account for any
minor inaccuracies.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Some systems point python to python3 instead of python2 - explicitly
request python2 to avoid conflicts.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Make sure the heater.target_temp is set during the auto-tune test so
that the heater.set_pwm() command will allow the heater to be turned
on.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The endstop_position is intended to support different values for each
stepper so that the individual tower heights can be configured.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
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>
Create add_printer_objects() functions in the fan, heater, extruder,
and toolhead modules. Create the necessary printer component objects
from this call instead of placing the code directly in klippy.py.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The atmega328 is basically the same as the atmega168 - it just adds
some additional memory. Allow the chip to be selected during the
build.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Instead of assuming the maximum PWM value is 255, export a constant
from the firmware to the host with the maximum value.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
On a retract move (which are common during "wipe" operations), treat
the move as if it were an extrude only move. It's valid for a retract
move to reverse more filament then it would be practical to push.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
When the log file does a rollover, start the top of the log with
critical system information (eg, software versions).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
Always call the regular .parse() method for each message type during
dump() - add a new .format_params() method for dumping a verbose
representation of the parsed message. This allows the new
format_params() to also be used with data already parsed.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
Always log the last synchronized clock during a shutdown event, and
use debug level for normal reports.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
Extend the FIRMWARE_RESTART command so that it can use the firmware
"reset" command instead of the "arduino" mechanism.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>