simplefoc / Arduino-FOC

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

[BUG] Monitor downsampling cannot be disabled #377

Closed sylque closed 2 months ago

sylque commented 4 months ago

Describe the bug There seems to be no way to disable monitor downsampling. Setting monitor_downsample to zero disables monitoring altogether.

The reason lies here:

if( !monitor_downsample || monitor_cnt++ < monitor_downsample ) return;

This should be replaced by:

if(monitor_cnt++ < monitor_downsample ) return;

Describe the hardware setup ESP32 + SimpleFOCMini + AS4048A + miniatute gimbal motor

IDE you are using Platformio

askuric commented 2 months ago

This would be a breaking change as down-sampling of 0 is intentionally intended to seamlessly disable monitoring. So many users have used this way in the past. (including me :D). So by making this change we would require people to set large numbers for downsampling rates like >100000. But the good value would depend on the MCU also and its loop speed.

So what I propose is to do this :

  if( !monitor_downsample || monitor_cnt++ < (monitor_downsample-1) ) return;

Now down-sample of 1 actually disables down-sampling. Do you agree with this approach?

sylque commented 2 months ago

Looks great, thanks.