From 4a439fabdc6299ee0b3a096a79601a9c72654e14 Mon Sep 17 00:00:00 2001 From: Jan Benicek Date: Wed, 15 Jan 2025 08:57:14 +0100 Subject: [PATCH] debug speed control algorithm #3 --- scripts/speed_reader.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/speed_reader.py b/scripts/speed_reader.py index a6f2f65..a981ea7 100644 --- a/scripts/speed_reader.py +++ b/scripts/speed_reader.py @@ -4,11 +4,10 @@ import datetime from scripts.speed_controller import rpm_control -pulses_per_rotation = 1 +pulses_per_rotation = 4 reader = Button(4, pull_up=False, bounce_time=0.0005) set_variable("speed_reader_last_impulse_time", datetime.datetime.now(), False) -rpm_last = 0 def event(): actual = datetime.datetime.now() @@ -18,8 +17,8 @@ def event(): rpm = (60 / difference) / pulses_per_rotation - actual_rpm = (rpm_last + rpm) / 2 - rpm_last = rpm + actual_rpm = (float(get_variable("actual_rpm_unfiltered")) + rpm) / 2 + set_variable("actual_rpm_unfiltered", rpm, False) set_variable("actual_rpm", round(actual_rpm, 1), False) rpm_control()