I think SimpleFOC has some non-initialized variables that only cause trouble with the
new c++ keyword.
BLDCMotor motor(7); // OK
BLDCMotor* motor = new BLDCMotor(7); // Not OK!
with the latter I have found that I have a bunch of hard to debug issues which I think are down to uninitialized (random initialiazed?) variables within some of the SimpleFOC classes.
I’ve found a couple of them, adding the following fixes things:
driver->pwm_frequency = NOT_SET; // otherwise motor doesn't spin with 6PWM motor->shaft_angle = 0.0; // angle_openloop sometimes has ovf - not entirely sure this is the fix
but I suspect there are more.
I can do a pull request for these two but I’m not a c++ expert and was wondering if someone could shed some light as to why there might be a difference.
The first approach works great in simple arduino ino files or from main.cpp but as my code base is getting more complex.