Files
hexapod-robot/2026-current/remote/SmoothedValue.h
T

26 lines
779 B
C
Raw Normal View History

#pragma once
// Rate-limited setpoint smoother - identical to robot/SmoothedValue.h (kept
// as a copy rather than moved to shared/ so the robot sketch stays untouched).
// Used for UI-driven setpoints that would otherwise step: speed scale and
// the remote-tilt fade.
struct SmoothedValue {
float current = 0;
float target = 0;
float max_rate; // units per second
explicit SmoothedValue(float rate = 100.0f) : max_rate(rate) {}
void setTarget(float t) { target = t; }
float update(float dt) {
float delta = target - current;
float max_step = max_rate * dt;
if (delta > max_step) delta = max_step;
else if (delta < -max_step) delta = -max_step;
current += delta;
return current;
}
void reset(float v) { current = target = v; }
};