Commit Graph

417 Commits

Author SHA1 Message Date
Kevin O'Connor 77fea562c4 clocksync: Start with adjusted_freq of 1.0
Avoid setting adjusted_freq to 0.0 as that can cause divide by zero
failures at startup.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-13 21:07:32 -04:00
Kevin O'Connor e0f275cddf serialhdl: Don't open port at 1200 baud
The 1200 baud trick on the Arduino Due does both a reset and an
erase.  The erase is not desired.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 21:46:09 -04:00
Kevin O'Connor 07a69df62f mcu: Fix command restart
Fix omission in commit f8750b14 that broke restarts via Klipper
command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 21:43:33 -04:00
Kevin O'Connor f8750b142f klippy: Rework shutdown handling
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>
2017-10-12 16:28:53 -04:00
Kevin O'Connor 3506d1e994 fan: Enable heater_fan objects on an MCU shutdown event
Should the MCU go into an error state, set the heater_fan to
max_power.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor 3c4d14bfa9 pca9685: Support default values
Allow the pwm pin to have a non-zero default value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor db97f36631 gpiocmds: Allow the start value for a pin to differ from the default_value
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>
2017-10-12 11:59:27 -04:00
Kevin O'Connor d03cf2b83f adccmds: Continue to query analog inputs after a shutdown
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>
2017-10-12 11:59:27 -04:00
Kevin O'Connor 3b9b4e4d6f endstop: Eliminate end_stop_set_oversample command
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>
2017-10-12 11:59:27 -04:00
Kevin O'Connor 78ba7064a7 clocksync: Initialize clock_est in connect_file()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor cc7c99a4a4 cartesian: Fix min_stop_interval calculation error
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>
2017-10-12 01:16:11 -04:00
Kevin O'Connor ecf2596469 gcode: Don't warn on fan not present if input is from a file
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-11 14:28:19 -04:00
Kevin O'Connor 0ec7eda11b pins: Add pin mapping for atmega1284p
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-05 16:57:44 -04:00
Kevin O'Connor 381304aa6f stepper: If homing_endstop_phase is configured, make 0.0 be at a full step
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>
2017-10-03 22:06:51 -04:00
Kevin O'Connor ce9523fb90 gcode: Report the raw MCU position from the M114 command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-03 22:03:52 -04:00
Kevin O'Connor 06420b0ddf gcode: Carry over #original and #command in get_extended_params()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-02 22:06:43 -04:00
Kevin O'Connor c2e1c53356 clocksync: Implement a floor on the prediction filter
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>
2017-10-02 11:00:24 -04:00
Kevin O'Connor ece1f71c64 endstop: Support oversampling of the endstop
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>
2017-10-01 19:15:55 -04:00
Kevin O'Connor 776d8f9f79 clocksync: Update clock synchronization code to use a linear regression
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>
2017-09-30 19:37:37 -04:00
Kevin O'Connor 61ee63f358 serialqueue: Don't report sent_time on responses that are retransmitted
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>
2017-09-30 19:37:20 -04:00
Kevin O'Connor 6f65ba9214 clocksync: Don't update prev_est on min rtt updates
Average frequency changes over the longer interval on a sample that
causes a minimum rtt update.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-28 01:09:18 -04:00
Kevin O'Connor ba837c2641 clocksync: Fix serialqueue.set_clock_est() - don't track min_freq
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>
2017-09-28 00:51:48 -04:00
Kevin O'Connor 1518032606 clocksync: Default mcu_freq to 1 instead of 0
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>
2017-09-27 20:07:46 -04:00
Kevin O'Connor 6469cce2bc toolhead: Make sure reset_print_time() doesn't go backwards in time
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>
2017-09-27 19:21:26 -04:00
Kevin O'Connor f658819862 clocksync: Add support for dumping internal state for debugging
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 13:13:38 -04:00
Kevin O'Connor 8d5a9143bb klippy: Avoid using '%' syntax when calling logging module
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>
2017-09-27 12:38:20 -04:00
Kevin O'Connor 8f8951b4c1 serialhdl: Make dump_debug() output atomic
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>
2017-09-27 12:38:20 -04:00
Kevin O'Connor 6e5bcc69bc gcode: Make dump_debug() output atomic
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>
2017-09-27 11:58:21 -04:00
Kevin O'Connor 8d04d3d8fd gcode: Exit if a shutdown occurs while running in batch mode
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-27 10:05:11 -04:00
Kevin O'Connor f37fc775e5 clocksync: Be conservative when setting serialqueue.set_clock_est()
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>
2017-09-27 09:10:41 -04:00
Kevin O'Connor 3982b5030e serialqueue: Take baud_adjust into account when calculating receive_time
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>
2017-09-26 22:27:25 -04:00
Kevin O'Connor d9fe4b6944 clocksync: Rework clock synchronization algorithm
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>
2017-09-26 22:27:25 -04:00
Kevin O'Connor 387cab27bd mcu: Separate restart_microcontroller() into multiple functions
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 16:04:41 -04:00
Kevin O'Connor 6dcc44ce2d chipmisc: Add initial support for servos
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 14:21:36 -04:00
Kevin O'Connor 3b4088c23f chipmisc: Add support for Replicape board
Add support for configuring and controlling the hardware specific to
the revision "B3" Replicape board.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 13:18:07 -04:00
Kevin O'Connor 16d2ec3a90 linux: Add support for analog IIO devices
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>
2017-09-20 12:55:28 -04:00
Kevin O'Connor d851882278 linux: Initial support for running Klipper in a Linux real-time process
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>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 3ccecc568d mcu: Initial support for multiple micro-controllers
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>
2017-09-20 12:45:00 -04:00
Kevin O'Connor cee200e509 mcu: Move code around in MCU class to keep like code together
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:27:18 -04:00
Kevin O'Connor f1b315e04f mcu: Move print_time to clock conversion code to clocksync.py
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:27:18 -04:00
Kevin O'Connor 94bcd9735a mcu: Add mcu wrapper functions and avoid direct acccess to mcu variables
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>
2017-09-19 17:25:43 -04:00
Kevin O'Connor f662445766 stepcompress: Implement print time to clock conversion in C code
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>
2017-09-19 17:25:43 -04:00
Kevin O'Connor 008be18f41 clocksync: Don't export get_last_clock()
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>
2017-09-19 17:25:43 -04:00
Kevin O'Connor 13812aa1c9 clocksync: Move clock synchronization code into new file
Move the low-level clock synchronization code from serialhdl.py to a
new file clocksync.py.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:42 -04:00
Kevin O'Connor 2089f19670 toolhead: Separate is_active() code from stats() code
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:42 -04:00
Kevin O'Connor 593741919f mcu: Update file purpose comment
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:42 -04:00
Kevin O'Connor 9d0fcca8a9 serialhdl: Reduce calculations done while holding the lock
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:42 -04:00
Kevin O'Connor 857eb01bfa homing: Move query_endstop() code from kinematic classes to homing.py
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-19 17:25:42 -04:00
Kevin O'Connor a100f174f9 mcu: Pass print_time directly to MCU calls
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>
2017-09-19 17:25:42 -04:00
Kevin O'Connor 5dfe4e1eb9 toolhead: Synchronize print_time to main mcu's time
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>
2017-09-19 17:25:38 -04:00