simplefoc / Arduino-FOC

Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
https://docs.simplefoc.com
MIT License
2.03k stars 521 forks source link

[FEATURE] Check if current_sense linked to the driver #298

Closed Candas1 closed 1 year ago

Candas1 commented 1 year ago

Is your feature request related to a problem? Please describe. If you forget to link the driver to current sense (what I just did ah ah ) current_sense.linkDriver(&driver); This takes you to the default handler infinite loop.

Describe the solution you'd like Could be worth checking if the driver is linked, drop a debug message and return.

Additional context Simplefoc is very well documented but this kind of things happens, and can generate unnecessary discussions in the forum.

Candas1 commented 1 year ago

Probably adding this in LowsideCurrentSense.cpp should be good enough:

#include "./communication/SimpleFOCDebug.h

.......

if (!driver){
     SIMPLEFOC_DEBUG("MOT: Align current sense not possible, driver not initialized."); 
     return 0;
}

Results:

MOT: Align current sense.
MOT: Align current sense not possible, driver not initialized.
MOT: Align error!
MOT: Init FOC failed.

I can create a pull request if you are ok.

Candas1 commented 1 year ago

Forget it, with STM32 the current sense init fails so it's ok current_sense.init() failed.

So probably something missing in my GD32 implementation.

Candas1 commented 1 year ago

@runger1101001 it seems this could be useful afterall.

Candas1 commented 1 year ago

The failure now seems to depend on how the driver was implemented. Maybe the check has to happen even here