How to reset shaft_angle when switching from velocity to angle control?

Hi everyone,as title suggests,I was first in velocity mode, command the motor to spin for some turns.Then I switch the motor to angle mode, target at 0,expected the motor to stay upright,but the motor keeps rotate back until all the previous accumated turns unwind.

Is it possible to reset the shaft_angle or somekind of variable so the motor forgets the accumated turns and go to zero angle immdiately?

Looked through source code many times,tried to change motor.shaft_angle = 0 with command interface but no luck.pls help me with it,thanks.

SimpleFOC tracks the total number of rotations as well as the current angle, and the target value is an absolute angle.
So you can set the target to sensor.getAngle() (or motor.shaft_angle). Then it will keep the current position, but that position won’t be 0.

What you’re asking is to make whatever the current position is after running in velocity mode for some time to be the new zero value.
You can in theory use the parameter motor.sensor_offset for this purpose. You can try setting motor.sensor_offset = sensor.getAngle(). Then setting should work as expected, I think.