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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>