Different encoders for commutation and position loop

Hey @Roiki,

You are absolutely right. Simplefoc main goal is not really the motion control but the FOC.

But almost 100% of the applications will have some kind of motion control in it and therefore we will support the most standard ones, and the advanced ones that are relatively easy to implement. And multi position sensor is one of them. It requires a minimal change and will introduce an interesting advantage for some users.

There are few applications where this is interesting. Some of them are in the domain of robotics. But one would be also for very smooth rotation of camera gimbals to couple IMU and encoder for example. We currently do not support IMU as position sensor but we intend to, at least as velocity sensor.

So there are some convenient features when using the BLDCMotor class for motion control as velocity and voltage limits and similar. But of course you can implement these yourself and probably even better then we do in our very general implementation.

The one thing I wanted to add is just that the simplefoc library already provides the pid and low pas filter class so build your own control loops without external libraries. Make sure to use your BLDCMotor in voltage mode and define your PID controller and LPF of you need one:

PIDController pid{.P=0.01,.I=0.05,.D=0,.ramp=10000,.limit = 10};
LowPassFilter lpf{.Tf=0.02};

And in the Arduino loop just do something like:

void loop(){
 // calculate the voltage value to be set to the motor
 // this line can be downsampled (called less frequently) if needed
 motor.voltage_q = pid(target_velocity - lpf(other_sensor.getVelocity()));
 // place voltage to the motor phases
 motor.loopFOC();
}