Motor.monitor() returning "nan" and "inf"

Hello everyone.
I’m running Simple FOC using the STM32Duino. It works fine with my NUCLEO-F411. But when I move to the F103C8 in order to make some custom design, it went wrong.
The PID seens not working and motor.monitor() returning like “nan 20 inf”. Any help?
If detailed information is needed, please tell me. Thanks in advance! :smiley:

I am not sure, this is an interesting issue!
Is this the same chip as bluepill?

I did not have any problems like this one so far, have you tried using motor commands and trying to read the motor values!

What does it mean that PID does not work?

Cheers,
Antun

Yes, same chip. Im using blackpill, quite simillar to bluepill.
PID does not work means at the beginning there’s some output voltage and spinning, and the reported speed is unnormally very high.
After a few seconds the motor stopped and printting “nan 20 inf”.
I havent try serial control yet.

image
image

Hey @hbozyq,
Did you try to use voltage control loop, does it work?

Maybe it is the issue related to the function micros(). We had some questions already about it.

motor.controller = ControlType::voltage;

The motor spins steadly and the angle output seems ok, but the velocity is still mad.

image

Its interesting!
The voltage and the angle seem ok, but the velocity seems completely off.

So its is definitely a problem of derivation. What kind of sensor are you using?

Can you please leave our the motor.monitor() and add the function printVel(). Something like this one. So we can see the micros and the simple derivation of angle. To see if there is really a problem of derivation or is it a _micros() issue.

And plot this


void printVel(){
    static float angle_old;
    static long tmp_old;
    long  now = _micros();

    Serial.print(_micros());
    Serial.print("\t");
    Serial.print(motor.shaft_velocity); 
    Serial.print("\t");
    Serial.println((motor.shaft_angle - angle_old)/(now - tmp_old));

   tmp_old = now;
   angle_old = motor.shaft_angle ;
}

Replaced motor.monitor() with printVel(). And this is the code and output.

void printVel(){
    static float angle_old;
    static long tmp_old;
    long  now = _micros();

    Serial.print(_micros());
    Serial.print("\t");
    Serial.print(motor.shaft_velocity); 
    Serial.print("\t");
    Serial.print((motor.shaft_angle - angle_old),6); 
    Serial.print("\t");
    Serial.println((motor.shaft_angle - angle_old)/(now - tmp_old),6);

   tmp_old = now;
   angle_old = motor.shaft_angle ;
}

image

What sensor type is this? What value do you have set for Tf on low pass filter?

Hall sensor, Tf =0.05

There are some hall fixes on dev which you may want to try.

What speed was your motor turning for those printout values above?

Hall’s can need more Tf than other sensors. e.g. 0.1 or more. That said it does seem something weird is going on. Possible interrupts/pullup issue?

Does the velocity look better when you are testing just the sensor e.g.


This would require you to manually spin the motor.

Dev branch should fix this.
I’ve seen it with a STM32 BluePill and my hoverboard motor which also uses hall sensors. Fixed it by changing the library to dev.

I am having a simialar problem using Hall sensors with the ESP32.

How and where can I find the dev version of the library? what are the fixes?

hi @Rollmop ,

I believe the fixes mentioned here have long been released to the main branch of the library.

So unless there is some regression and the problem was re-introduced, this is probably not exactly your problem.

hi @runger

Sorry, as soon as I pressed the reply button I realised this was an old post so all the updates had been released.