Arduino-FOC icon indicating copy to clipboard operation
Arduino-FOC copied to clipboard

[BUG] feed_forward_voltage/current can contain random stack/heap garbage

Open StijnWoestenborghs opened this issue 7 months ago • 2 comments

Describe the bug FOCMotor.h defines

    DQCurrent_s feed_forward_current;//!< current d and q current measured
    DQVoltage_s feed_forward_voltage;//!< current d and q voltage set to the motor

These variables are never actively set somewhere when not initialized properly to zero.

proposal; initialize to zero

    DQCurrent_s feed_forward_current{0.0f, 0.0f};//!< current d and q current measured
    DQVoltage_s feed_forward_voltage{0.0f, 0.0f};//!< current d and q voltage set to the motor

Describe the hardware setup For us it is very important to know what is the hardware setup you're using in order to be able to help more directly

  • Which motor: https://www.sparkfun.com/three-phase-brushless-gimbal-stabilizer-motor.html
  • Which driver: TMC6300
  • Which microcontroller: ESP32S3
  • Which position sensor: MT6701
  • Current sensing used? No

IDE you are using

  • Something else: raw ESP_IDF with platformio

StijnWoestenborghs avatar Apr 07 '26 14:04 StijnWoestenborghs

Yes this bug just wasted so much of my time! Please initialize these values. I'm on platformio + rp2040, using C++, i.e. motor = new BLDCMotor(11); which allocates it dynamically instead of in BSS (zeroed out memory), so my d-axis feedforward was some gigantic number and took a while to hunt down.

travisjayday avatar Apr 16 '26 19:04 travisjayday

I can confirm I also ran into this issue a few months ago, only now got to investigating why it happened. Glad to see it has a fix.

SabrCat avatar Jul 23 '26 01:07 SabrCat