aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/clocksync.py
Commit message (Collapse)AuthorAgeFilesLines
* clocksync: Remove no longer used get_adjusted_freq() functionKevin O'Connor2020-03-061-5/+0
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Fix typo in pause() call at connect timeKevin O'Connor2019-10-311-1/+1
| | | | | | | | The initial clock measurement wasn't properly implementing a small delay between clock queries. Fix the pause() call so there is a small delay between queries. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Support minclock in send_with_response() requestsKevin O'Connor2019-06-211-0/+3
| | | | | | | Enhance send_with_response() so that it supports queries with a minclock. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Introduce SerialReader.send_with_response()Kevin O'Connor2019-06-211-6/+6
| | | | | | | Introduce a main send_with_response() helper function and use it during identify and the setup of clocksync. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Rename register_callback() to register_response()Kevin O'Connor2019-06-211-1/+1
| | | | | | Rename the method and use that name in the mcu class as well. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Wrap code to 80 columnsKevin O'Connor2019-02-271-2/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Simplify is_active() checkKevin O'Connor2018-05-311-7/+7
| | | | | | | | | | | 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>
* basecmd: Rename get_status to get_clockKevin O'Connor2018-05-291-13/+13
| | | | | | | | | | | | Change the get_status command to get_clock. Don't report the shutdown status in the new get_clock command. The primary purpose of this change is to force the host code to report a firmware version mismatch with older firmwares as recent changes (namely the ordering of message block acks) have subtle incompatibilities if different host/mcu code is used. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Change timer frequency to avoid resonating with other timersKevin O'Connor2018-05-051-2/+4
| | | | | | | | | | | If the clock querying messages occur at a similar frequency to other events on the micro-controller or host, then it's possible for the load created by those other events to skew the clock synchronization. In particular, the 500ms lcd screen update could resonate with the 1 second clock query. Use an unusual clock querying frequency to avoid this issue. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Fix multi-mcu frequency adjustments with long movesKevin O'Connor2018-03-031-1/+1
| | | | | | | Commit 02ae2ab9 had a typo causing the new long move handling logic to not take effect. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* serialhdl: Add a wrapper around the results of lookup_command()Kevin O'Connor2018-02-271-7/+6
| | | | | | | | 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>
* clocksync: Rework multi-mcu adjust to better handle long movesKevin O'Connor2018-02-191-11/+19
| | | | | | | | | | | | | | | | | | | The multi-mcu clock syncing code relies on the ability to periodically update the mcu clock adjustments. If a series of very long moves are submitted then it is possible the adjustments could become unstable. For example, if an adjustment is made to reduce a clock error over the next couple of seconds, but it is applied to a longer period because the next move lasts many seconds, then this would result in a bigger adjustment for the following move, which would result in an even bigger error when that move lasts many seconds. This can repeat until the system destabilizes. Check for cases where the print_time is far in the future of the current estimated print time and average over a longer period in that case. That should reduce the possibility of the adjustment code becoming unstable. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Respond faster to clock changesKevin O'Connor2018-02-051-1/+1
| | | | | | | Average clock sync times over approximately 30 seconds instead of 120 seconds so that the clock prediction responds to changes faster. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: The clock estimate should add the rtt time not subtract itKevin O'Connor2017-12-161-1/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Start with adjusted_freq of 1.0Kevin O'Connor2017-10-131-1/+1
| | | | | | | 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>
* clocksync: Initialize clock_est in connect_file()Kevin O'Connor2017-10-121-0/+1
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Implement a floor on the prediction filterKevin O'Connor2017-10-021-3/+4
| | | | | | | | 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>
* clocksync: Update clock synchronization code to use a linear regressionKevin O'Connor2017-09-301-40/+67
| | | | | | | | | 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>
* clocksync: Don't update prev_est on min rtt updatesKevin O'Connor2017-09-281-1/+2
| | | | | | | 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>
* clocksync: Fix serialqueue.set_clock_est() - don't track min_freqKevin O'Connor2017-09-281-5/+3
| | | | | | | | | | | | 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>
* clocksync: Default mcu_freq to 1 instead of 0Kevin O'Connor2017-09-271-1/+1
| | | | | | | 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>
* clocksync: Add support for dumping internal state for debuggingKevin O'Connor2017-09-271-0/+13
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Be conservative when setting serialqueue.set_clock_est()Kevin O'Connor2017-09-271-1/+5
| | | | | | | | | 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>
* clocksync: Rework clock synchronization algorithmKevin O'Connor2017-09-261-97/+94
| | | | | | | | | 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>
* mcu: Initial support for multiple micro-controllersKevin O'Connor2017-09-201-3/+55
| | | | | | | | | 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>
* mcu: Move print_time to clock conversion code to clocksync.pyKevin O'Connor2017-09-191-6/+16
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* clocksync: Don't export get_last_clock()Kevin O'Connor2017-09-191-4/+6
| | | | | | | 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>
* clocksync: Move clock synchronization code into new fileKevin O'Connor2017-09-191-0/+106
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>