There are 2 ways to reproduce this problem (the second is a bit more scientific):
1) If the vehicle is stationary, and I apply a small amount of throttle, the car doesn't move. However, if the car is rolling backwards and I apply the same minimal amount of throttle, there is a *violent* forward torque, but only until the car is stationary again.
2) If i set regentravel=0, and ampmin=30, so that the inverter is consistently at ampnom=30 without having to touch anything, there is positive torque, but not enough to move the car forwards on the flat. However, if I apply this on an uphill, something odd happens, the car starts to roll backwards, then stops. Then starts to roll backwards again, then stops.
Instinctively, felt to me as if negative movement of the encoder is being treated as positive when calculating the output frequency and amplitude. I'm now attempting to look at the code, and it seems the reality is a little more complicated.
Code: Select all
void PwmGeneration::CalcNextAngleAsync(int dir)
{
static uint16_t slipAngle = 0;
uint16_t rotorAngle = Encoder::GetRotorAngle();
frq = polePairRatio * Encoder::GetRotorFrequency() + fslip;
slipAngle += dir * slipIncr;
if (frq < 0) frq = 0;
angle = polePairRatio * rotorAngle + slipAngle;
}
HOWEVER... frq is calculated using Encoder::GetRotorFrequency() which is unsigned.
frq is then used here to calculate amplitude:
Code: Select all
uint32_t amp = MotorVoltage::GetAmpPerc(frq, ampNomLimited);
In my opinion, Encoder::GetRotorFrequency() should return a signed value, and voltage should be calculated more like this:
Code: Select all
frq = ABS(dir * polePairRatio * Encoder::GetRotorFrequency() + fslip);