Certainly. But do include a note that it has had minimal testing. And you might change SmoothingSensor::getFullRotations() to just call wrappedSensor->getFullRotations() like I had it before. Technically getFullRotations()*_2PI+getMechanicalAngle() should give the same value as getAngle(), so I had to calculate it by the inverse of that incase the smoothing offset crosses the wraparound point. But I doubt anyone is actually using it in a way that it matters, and as it is I think it may be off by 1 sometimes due to the float to int conversion truncating rather than rounding.
And to update on the field weakening effect mentioned in my previous post, I think it’s specific to hall sensors. Each hall state change jumps 60 electrical degrees instantaneously, but the smoothed value will have gradually advanced through those degrees during the same time, meaning that on average it’s 30 electrical degrees ahead of where it should be.
EDIT: Also, SmoothingSensor won’t work with HallSensor at all as is. HallSensor needs to be edited to use angle_prev_ts instead of pulse_timestamp. Give me a bit more time before you integrate it. I’ll see if I can come up with an elegant way to eliminate the field weakening effect…
EDIT2: I remembered we live in the future and the standard library has rounding functions now. So this should give fully correct results:
int32_t getFullRotations() {
float angle = getAngle();
return lroundf((angle - _normalizeAngle(angle)) / _2PI);
}
As for the other issue, one potential approach would be to add a phase advance setting in FOCMotor:
float FOCMotor::electricalAngle(){
// if no sensor linked return previous value ( for open loop )
if(!sensor) return electrical_angle;
return _normalizeAngle( (float)(sensor_direction * pole_pairs) * sensor->getMechanicalAngle() +
phase_advance * _sign(shaft_velocity) - zero_electric_angle );
}
That will give user control of field weakening with any kind of sensor, as well as the ability to correct this particular problem. It’s fun to play with. 0.5 (~30 degrees) gives around 145rad/s with un-smoothed halls, so it looks like my theory was correct. 0.8 (~45 degrees) almost makes it to 160 rad/s