diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-01-09 23:08:23 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-01-09 23:08:23 -0500 |
commit | 3a7a77d49e620420ee33996eec0a70a7c186f6bb (patch) | |
tree | d540c997551dbbf7f334de15ffb6f5daacb95987 /klippy/mcu.py | |
parent | c87c090264fb9fd91bc87fbc63a05c5e53e3c484 (diff) | |
download | kutter-3a7a77d49e620420ee33996eec0a70a7c186f6bb.tar.gz kutter-3a7a77d49e620420ee33996eec0a70a7c186f6bb.tar.xz kutter-3a7a77d49e620420ee33996eec0a70a7c186f6bb.zip |
basecmd: Improve accuracy of stats "sumsq" variable
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>
Diffstat (limited to 'klippy/mcu.py')
-rw-r--r-- | klippy/mcu.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/klippy/mcu.py b/klippy/mcu.py index 33a70076..5d8fb31f 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -333,6 +333,7 @@ class MCU: self._print_start_time = 0. self._mcu_freq = 0. # Stats + self._stats_sumsq_base = 0. self._mcu_tick_avg = 0. self._mcu_tick_stddev = 0. def handle_mcu_stats(self, params): @@ -341,10 +342,8 @@ class MCU: tick_sum = params['sum'] c = 1.0 / (count * self._mcu_freq) self._mcu_tick_avg = tick_sum * c - tick_sumsq = params['sumsq'] - tick_sumavgsq = ((tick_sum // (256*count)) * count)**2 - self._mcu_tick_stddev = c * 256. * math.sqrt( - count * tick_sumsq - tick_sumavgsq) + tick_sumsq = params['sumsq'] * self._stats_sumsq_base + self._mcu_tick_stddev = c * math.sqrt(count*tick_sumsq - tick_sum**2) def handle_shutdown(self, params): if self.is_shutdown: return @@ -359,6 +358,8 @@ class MCU: self._printer.reactor.update_timer( self._timeout_timer, time.time() + self.COMM_TIMEOUT) self._mcu_freq = float(self.serial.msgparser.config['CLOCK_FREQ']) + self._stats_sumsq_base = float( + self.serial.msgparser.config['STATS_SUMSQ_BASE']) self._emergency_stop_cmd = self.lookup_command("emergency_stop") self._clear_shutdown_cmd = self.lookup_command("clear_shutdown") self.register_msg(self.handle_shutdown, 'shutdown') |