In some rare circumstances it was possible for the host software to
become so busy that it does not transmit a get_clock request for
several seconds. (In particular, this could occur with some complex
calls to coordinate_descent.) If that happened, it was possible for
the code to incorrectly report a "Timeout with MCU" error. Rework the
is_active() check to prevent that.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Normally, the MCU is restarted on a config change. However, that
should not be done automatically if the MCU is in a shutdown state.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Most callers did a lookup of the pins module via
printer.lookup_object("pins"). Use that as the standard method and
remove these less frequently used methods.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Automatically clear the information printed at the start of each log
file rollover on a klippy internal restart.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Add a lookup_command() method to the SerialReader class that provides
a wrapper that stores the serial and commandqueue references. This
makes it easier to run the send() method.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
The delta code calculates a "virtual tower" along the line of
movement. Rework the variable names and comments to make it clear
that this is occurring.
It is not necessary to pass the start_pos variable to the C code as it
is simple to update the start_pos at the start of each movement.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It's not necessary to have separate C delta kinematic functions for
constant acceleration and constant velocity as constant velocity can
be obtained by using a constant acceleration of zero.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Update the C delta kinematic code to take velocity and acceleration
directly in step distances and clock ticks. This simplifies the
mcu.py python code as it only needs to do unit and axis conversion.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
It's not necessary to have separate C functions for constant
acceleration and constant velocity as constant velocity can be
obtained by using a constant acceleration of zero.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Update the C code to take velocity and acceleration directly in step
distances and clock ticks. This simplifies the mcu.py python code as
it only needs to do unit and axis conversion.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Update the set_position() method to convert from millimeters to
absolute step position.
Also, update PrinterStepper.get_homed_offset() and
mcu_stepper.get_commanded_position() to return millimeters.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Now that the kinematic classes call the mcu_stepper with millimeters
and seconds it is no longer necessary for them to directly access the
stepper's position in absolute steps. Rename
mcu_stepper.commanded_position to mcu_stepper._commanded_pos to make
clear it is not a variable intended to be externally accessed.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Rework the parameters of step_delta_const() and step_delta_accel() so
that they take velocity and acceleration directly in millimeters and
seconds. This simplifies the delta.py kinematic code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Rename step_sqrt/step_factor to step_accel/step_const and have them
directly take the velocity and acceleration in millimeters and
seconds. This simplifies the kinematic classes.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Extend the endstop code so that more than one stepper can be halted
during endstop homing. Some kinematic setups (eg, corexy) require an
endstop to support this.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
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>
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>
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>
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>
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>
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>