feat: error wrap callback

This commit is contained in:
2025-06-12 16:07:33 +09:00
parent f5e35b606f
commit ba1b18febe
2 changed files with 7 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ export interface PIDParameters {
kP: number;
kI: number;
kD: number;
errorWrap?: (error: number) => number;
}
export type PIDReport = {
@@ -44,7 +45,11 @@ export class PID {
public update(measuredValue: number): number {
const currentTime = os.epoch("utc");
const error = this.setpoint - measuredValue;
const rawError = this.setpoint - measuredValue;
const error = this.params.errorWrap
? this.params.errorWrap(rawError)
: rawError;
let deltaTime = 0;
if (this.lastTime !== null) {