1

I want to implement the flux observer from matlab ( https://de.mathworks.com/help/mcb/ref/fluxobserver.html ) in c code (for an stm32). In order to do so, I need to calculate the integral for flux calculation. However, since Im a hobbyist, i dont know how to implement this in source code (neither how to calculate it by hand).

ψα= ∫​(Vα−IαR)dt− (Ls⋅Iα)

This is the term I am talking about. Any help about this topic is highly recommended.

Thanks

EDIT: Thats what i tried:

    if(TimerFlag)
    {
        TimerFlag = 0;

        ClarkTransformation(&ialpha, &ibeta, cur_c, cur_b);
        ClarkTransformation(&valpha, &vbeta, vol_c, vol_b);

        dt = TimeElapsedS - TimeElapsedSOld;
        TimeElapsedSOld = TimeElapsedS;

        fluxalpha += ((valpha-ialpha*R)*dt - (Ls*ialpha));
        fluxbeta += ((vbeta-ibeta*R)*dt - (Ls*ibeta));

        fluxrotor = sqrtf((fluxalpha*fluxalpha) + (fluxbeta*fluxbeta));
        torquemotor = (3.0f / 2.0f) * PoleNumber * (fluxalpha*ibeta - fluxbeta*ialpha);
        anglemotor = arctan(fluxbeta/fluxalpha);
    }
6
  • 2
    what did you try? Commented Sep 30, 2022 at 10:50
  • I'm afraid this is too broad. Do you know how to calculate I(t) and V(t)? Do you know what an integral is and how to calculate it numerically? Commented Sep 30, 2022 at 10:52
  • i tried summing it up in every loop (10kHz). But this made my flux variable just go off in negative direction... what do you mean by I(t) and V(t)? If you mean voltage and current at given times, yes I do have these variables correctly in my code. Commented Sep 30, 2022 at 10:58
  • Can you please add a minimal reproducible example of your attempt? Commented Sep 30, 2022 at 11:00
  • Find a basic textbook on Numerical Analysis. Commented Sep 30, 2022 at 11:02

1 Answer 1

1

discrete integral is just summation (rectangular rule) so you just add up the stuff for each sample like you did however You have also constant term which must not be added more than once... I see it like this:

// some globals and or init
float fluxalpha= -Ls*ialpha;
float fluxbeta = -Ls*ibeta;

// this is in your timer ISR or whatever
void some_timer_event()
 {
 float dt = elapsed_time();
 fluxalpha += (valpha-ialpha*R)*dt; 
 fluxbeta  += (vbeta-ibeta*R)*dt;
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.