Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pmattila committed Apr 30, 2024
1 parent b7e3783 commit 5dc8ff2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/main/flight/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ void INIT_CODE pidInitProfile(const pidProfile_t *pidProfile)
pt1FilterInit(&pid.precomp.collFilter, 100.0f / constrainf(pidProfile->yaw_collective_dynamic_decay, 1, 250), pid.freq);

// Yaw precomp lowpass filter
lowpassFilterInit(&pid.precomp.yawFilter, pidProfile->yaw_precomp_filter_type, pidProfile->yaw_precomp_cutoff, pid.freq, 0);
lowpassFilterInit(&pid.precomp.yawCollFilter, pidProfile->yaw_precomp_filter_type, pidProfile->yaw_precomp_cutoff, pid.freq, 0);
lowpassFilterInit(&pid.precomp.yawCyclFilter, pidProfile->yaw_precomp_filter_type, pidProfile->yaw_precomp_cutoff, pid.freq, 0);

// Tail/yaw precomp
pid.precomp.yawCyclicFFGain = pidProfile->yaw_cyclic_ff_gain / 100.0f;
Expand Down Expand Up @@ -399,17 +400,14 @@ static void pidApplyPrecomp(void)
//// Collective-to-Yaw Precomp

// Collective components
const float yawCollectiveFF = fabsf(collectiveDeflection) * pid.precomp.yawCollectiveFFGain;
const float yawCollectiveFF = fabsf(filterApply(&pid.precomp.yawCollFilter, collectiveDeflection)) * pid.precomp.yawCollectiveFFGain;
const float yawCollectiveHF = fabsf(collectiveHF) * pid.precomp.yawCollectiveDynamicGain;

// Cyclic component
float yawCyclicFF = fabsf(cyclicDeflection) * pid.precomp.yawCyclicFFGain;
float yawCyclicFF = fabsf(filterApply(&pid.precomp.yawCyclFilter, cyclicDeflection)) * pid.precomp.yawCyclicFFGain;

// Calculate total precompensation
float yawPrecomp = yawCollectiveFF + yawCollectiveHF + yawCyclicFF;

// Lowpass filter
yawPrecomp = filterApply(&pid.precomp.yawFilter, yawPrecomp) * masterGain;
float yawPrecomp = (yawCollectiveFF + yawCollectiveHF + yawCyclicFF) * masterGain;

// Add to YAW feedforward
pid.data[FD_YAW].F += yawPrecomp;
Expand Down
3 changes: 2 additions & 1 deletion src/main/flight/pid.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ typedef struct {

typedef struct {

filter_t yawFilter;
filter_t yawCollFilter;
filter_t yawCyclFilter;

pt1Filter_t collFilter;

Expand Down

0 comments on commit 5dc8ff2

Please sign in to comment.