Skip to content

[FEATURE] Foc calculation refactoring #311

Closed
@Candas1

Description

@Candas1

Hi,

This is not adding a feature, but could make further changes easier.
There is duplicate code here and here

    float i_alpha, i_beta;
    if(!current.c){
        // if only two measured currents
        i_alpha = current.a;  
        i_beta = _1_SQRT3 * current.a + _2_SQRT3 * current.b;
    }if(!current.a){
        // if only two measured currents
        float a = -current.c - current.b;
        i_alpha = a;  
        i_beta = _1_SQRT3 * a + _2_SQRT3 * current.b;
    }if(!current.b){
        // if only two measured currents
        float b = -current.a - current.c;
        i_alpha = current.a;  
        i_beta = _1_SQRT3 * current.a + _2_SQRT3 * b;
    } else {
        // signal filtering using identity a + b + c = 0. Assumes measurement error is normally distributed.
        float mid = (1.f/3) * (current.a + current.b + current.c);
        float a = current.a - mid;
        float b = current.b - mid;
        i_alpha = a;
        i_beta = _1_SQRT3 * a + _2_SQRT3 * b;
    }

This could be made a function getAlphaBeta or getClarkTransform that uses foc currents as inputs, and returns alpha and beta.
A function getParkTransform could use the electrical angle, alpha and beta and return DQcurrents.
getDCCurrent could use the electrical angle, alpha and beta and return DCcurrent.

Eventually, foc_current torque control type in loopfoc would do:

  • getPhaseCurrents
  • getClarkTransform
  • getParkTransform
  • PI control

And dc_current torque control type in loopfoc would do:

  • getPhaseCurrents
  • getClarkTransform
  • getDCcurrent
  • PI control

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions