Weird encoder/motor behaviour

Hi all, can anyone with more experience help me diagnose a weird issue I am having?

I have a GM3506 BLDC gimbal motor connected to a B-G431B-ESC1 (ST Drone Discovery kit motor controller) running Arduino and SimpleFOC. The motor also has an AMT102v encoder (set to 512 PPR) mounted to it and connected to the B-G431B-ESC1 via the ABZ encoder input. The motor has 22 poles so I have put in 11 PP for the motor constructor.

// init BLDC motor
BLDCMotor motor = BLDCMotor(MOTOR_POLE_PAIRS); // 11 pole pairs
// init driver

//  init encoder
Encoder sensor = Encoder(ENCODER_A, ENCODER_B, 512, ENCODER_Z);
void doA() { sensor.handleA(); }
void doB() { sensor.handleB(); }
void doIndex() { sensor.handleIndex(); }

In velocity_openloop mode the motor turns correctly at slow speeds. It starts vibrating then stops at high velocities as is expected with openloop.

However in sensored velocity mode it doesn’t turn at all most of the time. I send it the same velocity commands and it just sits there, locked solid.

When debugging the encoder I noticed that although the angles look right (360 per rotation when quadrature mode is OFF, 4x that when on) the velocity from the encoder is massive even when rotating my wheel slowly.

V 0.00 A -312.19
V -115.21 A -360.35
V -203049.23 A -506.95
V -150857.05 A -784.16
V -150857.05 A -855.35
V -3026.33 A -907.73

Above are the kind of values I get when rotating the wheel slowly. V is velocity in deg/s and A is angle in degs.

The correct angle leads me to believe the sensor is installed correctly and the working openloop shows the driver runs correctly.

Does anyone have any ideas of what could be causing it to just lock solid and/or why the velocity results look so weird ?


Ok, I get better velocity results if I call getVelocity every loop. Should this be the case? I would have thought it would take delta time into account.

I have now disabled getVelocity and getAngle entirely and re-enabled sensored FOC mode but it is still acting weird.

Now the motor does the init process according to the logs and seems to correctly find the zero index at the right speed (slowly). But then the motor just takes off and runs at full speed or something around there. It also doesn’t change speed when I send it new values from the serial console even though I can see it changing the targetVelocity in the logs.

Any ideas of how I could go about debugging this? Could it maybe be a weird PID issue?

Ok so technically it was a weird PID issue but with a stupid hardware source :upside_down_face:. My motor was connected to the encoder with a pressure-fit, 3d-printed hub. I think the hub must have slipped due to excessive acceleration which caused the PID controller to get confused and accelerate the motor which made the problem worse. Adding to that, the core of the gimbal motors I am using get really hot when they are driven incorrectly which probably deformed the pressure-fit and caused even more incorrect encoder readings.

I redesigned the hub to actually mount to the wheel and everything seems to be working. Anyway hope this helps someone else.