I’m using a system with BLDCMotor, BLDCDriver3PWM and MagneticSensor in a system and I’m using MotionControlType::angle to track a target angle.
At startup I want it to target angle 0, and from there on it will receive the target angle via serial. Due to physical restrictions it is important that it will move the shortest path to angle 0 at startup, so it doesn’t do a “full rotation”. My initial idea was to just read the initial sensor angle, and if it’s > pi I would set motor.sensor_offset = 2*pi. This works well if I don’t start with the system too close to angle 0, because if I start up close to angle 0 it will sometimes do a “full rotation” anyway.
I think this is due to angles at angle 0 is sometimes read as 0 and sometimes as ~2pi. And if my initial angle check reads e.g. ~0 and then I don’t set an sensor_offset, the control loop might read ~2pi when it starts and thus it does a full rotation to get to 0. And the same thing can happen if I first read the angle as ~2*pi and then the control loop reads the first value as 0.
I’m very much a SimpleFOC-newbie, so I’d welcome any ideas of where my reasoning might be off, or what I could possible do to avoid this issue?