Skip to content

Commit

Permalink
Experimental, apply Smith Predictor to DTERM
Browse files Browse the repository at this point in the history
  • Loading branch information
DzikuVx committed Jan 13, 2025
1 parent 5bd3fc0 commit 47731c8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/main/flight/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ typedef struct {
pt3Filter_t rateTargetFilter;

smithPredictor_t measurementSmithPredictor;
smithPredictor_t dtermSmithPredictor;

fwPidAttenuation_t attenuation;
} pidState_t;
Expand Down Expand Up @@ -376,6 +377,22 @@ bool pidInitFilters(void)
pidProfile()->measurementSmithPredictorFilterHz,
getLooptime()
);

// Dterm Smith predictor on ROLL and PITCH only
smithPredictorInit(
&pidState[FD_ROLL].dtermSmithPredictor,
pidProfile()->dtermSmithPredictorDelay,
pidProfile()->dtermSmithPredictor,
pidProfile()->dtermSmithPredictorFilterHz,
getLooptime()
);
smithPredictorInit(
&pidState[FD_PITCH].dtermSmithPredictor,
pidProfile()->dtermSmithPredictorDelay,
pidProfile()->dtermSmithPredictor,
pidProfile()->dtermSmithPredictorFilterHz,
getLooptime()
);
#endif

pidFiltersConfigured = true;
Expand Down Expand Up @@ -735,8 +752,13 @@ static float dTermProcess(pidState_t *pidState, float currentRateTarget, float d

// Calculate derivative
newDTerm = delta * (pidState->kD * dT_inv) * applyDBoost(pidState, currentRateTarget, dT, dT_inv);

//Apply D-term smith predictor
#ifdef USE_SMITH_PREDICTOR
newDTerm = smithPredictorApply(&pidState->dtermSmithPredictor, newDTerm);
#endif
}
return(newDTerm);
return newDTerm;
}

static void applyItermLimiting(pidState_t *pidState) {
Expand Down

0 comments on commit 47731c8

Please sign in to comment.