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

[BUG] Cannot disable Debug print #279

Closed robcazzaro closed 1 year ago

robcazzaro commented 1 year ago

I'm using Platformio, and I'm trying to reduce the size of a SimpleFOC project running on a GD32F130C8 processor with only 32K FLASH.

One obvious way is to reduce the size of the debug messages. I looked at the various messages, and in the file SimpleFOCDebug.h I found this

 * Add -DSIMPLEFOC_DISABLE_DEBUG to your compiler flags to disable debug in
 * this way.

When I set that build flag, though, it fails in FOCMotor.cpp in line 85, trying to enable a non-existing class

void FOCMotor::useMonitoring(Print &print){
  monitor_port = &print; //operate on the address of print
  SimpleFOCDebug::enable(&print);
  SIMPLEFOC_DEBUG("MOT: Monitor enabled!");
}
RoboDurden commented 1 year ago

Don't know if this will help the simpleFOC code but i always use debug macros that either map to serial ouput code or nothing:

#ifdef SERIALDEBUG
    #define DEBUG(code) {code}
    #define OUT(s)  {SERIALDEBUG.print(s);}
    #define OUT2(s,i)   {SERIALDEBUG.print(s);SERIALDEBUG.print(": ");SERIALDEBUG.print(i);}
    #define OUT2T(s,i)  {SERIALDEBUG.print(s);SERIALDEBUG.print(": ");SERIALDEBUG.print(i);SERIALDEBUG.print("\t");}
    #define OUTN(s) {SERIALDEBUG.println(s);}
#else
    #define DEBUG(code)
    #define OUT(s)
    #define OUT2(s)
    #define OUT2T(s)
    #define OUTN(s)
#endif

usage:

  DEBUG( 
    OUT2T("GD32",iNow) 
    for (int i=0; i<HALL_Count; i++)  OUT2T(i,aoHall[i].Get())
    OUT2T("angle",sensor.getAngle()) 
    OUT2T("speed",sensor.getVelocity())
    OUT2T("iI2cReq",iI2cReq);
    OUT2("iI2cRec",iI2cRec);
    OUTLN()
  )
runger1101001 commented 1 year ago

Fixed this on the dev branch @robcazzaro , thanks for reporting it!