PID_velocity.limit is always 0.2 at init time

Whatever the value you set for PID_velocity.limit during setup, motor.init() will always change it back to 0.2 (because of this line I guess). Is it the expected behavior?

I confirm I believe there’s a bug with the velocity limit when using current sensing: if you don’t set motor.PID_velocity.limit to somehting after motor.init(), the motor won’t run because the velocity PID limit is set to 0.2 by default:

#include <SimpleFOC.h>

BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);

SPIClass SPI_3(PC12, PC11, PC10);
MagneticSensorSPI sensor(PD2, 14, 0x3FFF);

InlineCurrentSense current_sense(0.01, 50.0, A0, A2);

Commander command = Commander(Serial);
void doMotor(char* cmd){ command.motor(&motor, cmd); }

void setup() {
  sensor.init(&SPI_3);
  motor.linkSensor(&sensor);

  driver.voltage_power_supply = 14.5;
  driver.init();
  motor.linkDriver(&driver);

  motor.controller = MotionControlType::velocity;
  motor.torque_controller = TorqueControlType::voltage;

  motor.velocity_limit = 50;
  motor.voltage_limit = 10.0;
  
  motor.PID_velocity.P = 0.1;
  motor.PID_velocity.I = 8;
  motor.PID_velocity.D = 0;
  motor.PID_velocity.output_ramp = 1000.0;
  motor.LPF_velocity.Tf = 0.005;

  Serial.begin(115200);
  motor.useMonitoring(Serial);
  motor.monitor_downsample = 0;
  motor.monitor_variables = 0xFF;
  
  current_sense.init();
  motor.linkCurrentSense(&current_sense);

  motor.init();
  motor.initFOC(); 

  // THE BUG: here you need to set motor.PID_velocity.limit to something reasonable , otherwise 
  // the motor won't turn
  motor.PID_velocity.limit = 10;

  motor.target = 3;

  command.add('M', doMotor, "motor");
  Serial.println(F("Motor commands sketch | Initial motion control > torque/voltage : target 1V."));  
  _delay(1000);
}


void loop() {
  motor.loopFOC();
  motor.move();
  motor.monitor();
  command.run();  
}

(tested with both SimpleFOC v2.1.1 and v2.2)

Hey @quentin,
You are right. I’ll update this for the next release.
I forgot to deal with it for this one :confused: