Adding current sensing to existing open loop speed control

I’m using this dual FOC v3.2 circuit to control two small pumps. The manufacturer provides an example open loop speed control, but they didn’t do anything with the current sensor that the hardware includes.

Looking at some code examples, it seems like adding current sensing lets you set the current limit to avoid things like damaging the motor? Am I right in thinking that by saving the current at different commanded velocities, I’d also be able to graph over time when the pump needs cleaning? Like over time as the pump clogs more, the same velocity command will result in needing higher current?

Other than sensing current and setting current limit, does instantiating the current_sense do more for speed control? Like does it make speed control more efficient or better controlled? Looking at the code, it looks like it’s only setting the current limit and reading back the current? It’s not using the current parameters in any kind of control loop?

// Initialize Motor and Driver
BLDCMotor motor = BLDCMotor(pole_pairs);
BLDCDriver3PWM driver = BLDCDriver3PWM(pwm1, pwm2, pwm3, enable);
// ... driver/motor init ...

// Initialize Current Sensing
InlineCurrentSense current_sense = InlineCurrentSense(R_shunt, gain, pinA, pinB);
// ... current sense init ...

void setup() {
  // ... driver/motor setup ...
  
  // Choose Open Loop Velocity
  motor.controller = MotionControlType::velocity_openloop;
  
  // Set Current Sensing
  motor.torque_controller = TorqueControlType::foc_current;
  
  // Set Voltage and Current limits
  motor.voltage_limit = 10;   // Volts
  motor.current_limit = 2;    // Amps
  
  // Velocity limit (rad/s)
  motor.velocity_limit = 100;
  
  motor.init();
  current_sense.init();
  motor.linkCurrentSense(&current_sense);
  motor.initFOC();
}

void loop() {
  motor.move(target_velocity);
  motor.loopFOC(); // Runs current control
}

Hi there,

Current sense base openloop is a new feature from the last release (2.4). That is probably why you don’t find many example of it.

In terms of efficiency there is a short page with the trade-offs in the docs Open-Loop Efficiency Considerations | Arduino-FOC

So you can use it and it will let you reach higher velocities than in the openloop with only voltage. Another good thing is that you don’t need to manually set the voltage limit, the current control loop will determine it on its own given the current limit and the speed. And if course you can limit the current to reduce the heat.

But this code will still push the current_limit value of current through your motor. And it is still much less efficient than a closed loop control mode of any kind.

So looking at the current it will be hard to determine the efficiency issues, because the code will always try to set the current_limit amps to your motor. What will happen is that at some point due to the loss of efficiency you will need a higher current_limit to turn your motor, but I’m not sure how would I termine “the right” amount automatically.

The motor parameters can be used to tune the current control loop gains. If you use the tunecurrentcontroller functions.

What I’d suggest you to do is to use the sensorless control rather than openloop. It estimates the motor position and velocity and effectively closes the position loop with current sensing. It works very well, it requires some tuning but it might be exactly what you’re looking for.
It would allow you to set a speed for your motor and it would basically work like if you’d have a position sensor, adapting the current value based on the load. In that case you could actually see that for the same speed your current had gone up.

There is a short example here: