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>
Add the new item at the same time as checking if there is space in the
queue.
Also, update the default optimization level of c_helper.so to O2 to
improve the compiled code layout.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Calculate where a tower must reverse direction during a move in the C
code instead of the delta.py kinematic code. This simplifies the
python code.
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>
If the reactor isn't running then implement pause using the system
sleep command. This simplifies the users of pause().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Increase the default motor_off_time from 1 minute to 10 minutes. The
small value is a common source of confusion.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The est_clock calculation code requires timestamps on status messages
to never be prior to the reception of the message. The eventtime of
handle_message() is taken before the read() and there is a small
possibility that it could be inaccurate enough to corrupt the
est_clock calculation. Take a new timestamp when storing receive_time
to prevent this. This fix prevents some firmware "Move queue empty"
shutdowns.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
sqrt() of a negative number in the C code returns NaN. This value
results in behavior that is difficult to debug. Always return 0.0
instead as this results in better behavior that is easier to track
down. Also, on some code paths, safe_sqrt is called on numbers that
are multiplied by very large amounts (eg, 16000000**2) and thus
distinguishing between large and small negative numbers is difficult.
For now, report in the log if the value is below -0.001.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The code disables lookahead between two extruding moves with
significantly different extrude ratios. Unfortunately, it was
possible for very tiny moves to show different extrude ratios just due
to how the slicer implements rounding when it produces the gcode.
Allow lookahead to be enabled between moves with extrude ratios that
are different if they don't noticeably produce more or less extrusion.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Be less likely to raise a "Move exceeds maximum extrusion cross
section" error on very short moves. It's okay to extrude a little
extra plastic on moves shorter than the nozzle diameter.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Catch and ignore any exceptions when trying to shutdown the printer in
toolhead.force_shutdown() - there's a good chance an exception will be
raised as this method is often called after an invalid internal state
is found.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
The previous calculation was only valid if the stepper is always
commanded to a position that is an exact multiple of the
step_distance. The safety check was programmed with a value too large
for other commanded positions, which could result in "No next step"
errors. Fix by changing the calculation to use the worst case
scenario.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
Fix a corner case where a residual in the PID could cause a non-zero
pwm request even when the target_temp is zero. (Which could lead to a
firmware "Missed scheduling of next pwm event" shutdown.)
Simplify the logic for suppressing duplicate pwm updates and make sure
a zero target_temp always results in a zero pwm update on the
following set_pwm calculation.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Rename the thermistor_type and thermistor_pin config variables to
sensor_type and sensor_pin. This is in preparation for support of
sensors beyond thermistors.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
When using a sensor that isn't a thermisistor, the maximum and minimum
adc values may be swapped - handle that case.
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>
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>
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>
Store a full 64bit uptime in the mcu and query it at the start of each
connection. This ensures the host's 64bit clock is always in synch
with the mcu's clock.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
Instead of defaulting the pressure advance lookahead time to be the
same as the pressure_advance variable, allow it to be configured.
Default the new config setting (pressure_advance_lookahead_time) to
10ms.
Also, make the setting more accurate if a future move is accelerating
in the middle of the lookahead window.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Simplify the mechanism for limiting stepper speed (introduced in
commit bdfdf7ef) - split the extreme end of the build envelope into
two zones and use the same speeds for all moves that traverse any part
of one of those zones.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Commit c24b7a7e reworked the way lookahead was done and it introduced
a bug when a full acceleration move is immiedietly followed by a full
deceleration move. In that situation, depending on when the lookahead
queue was flushed, it was possible to call move.move() without calling
move.set_junction(). This resulted in a "Move instance has no
attribute 'accel_t'" internal error.
Simplify and fix the logic for checking full accel moves followed by
full decel moves.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
There's no reason for the user to specify position_max - it can be
inferred on deltas from the endstop positions.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Some XY moves at the extreme end of the build envelope could cause
excessive axis stepper movement. Check for any moves that could
possibly result in a stepper movement of more than 3 times the XY
movement and cap the move's acceleration and speed.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Calculate and store the maximum xy2 value for the given z level each
time the head moves to a new z level. This simplifies the boundary
check for common XY moves.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Report in the log the host CPU type and count. This helps distinguish
between different rpi versions when debugging the log from a problem
report.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
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>
Use a minimum time window as a heuristic for determining when to try
to lazily flush the lookahead buffer. In the common case this will
result in more moves processed for each flush and thus reduce the
overall cost of the lookahead processing.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>