Thanks both of you! Lowering the PID and ramp values did the trick. I now have a reasonably behaved motor controlled with the current sense based FOC.
@ngalin, I’m glad you got it working! Can you share with us your final values?
Hi @David_Gonzalez,
Yup, absolutely. I’ve included here a table of various control loop variables to get sensible (but not perfect) operation of the ODrive motor in the following control configuration:
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
motor.controller = MotionControlType::velocity;
motor.torque_controller = TorqueControlType::foc_current;
The test harness I have setup cycles the target velocity of the motor from: 0 → 6 → 0 (rad/s) every 4 seconds. It’s not perfect, as there are still times when various control loops saturate, but it’s nothing compared to the jerky/non-rotating behavior I was getting before:
| Parameter | Value |
|---|---|
| voltage limit | 4 |
| current limit | 2 |
| velocity limit | 20 |
| PID_current_q: | |
| P | 0.5 |
| I | 0.1 |
| D | 0 |
| output_ramp | 50 |
| limit | 1 |
| PID_current_d: | |
| P | 1 |
| I | 0.5 |
| D | 0.01 |
| output_ramp | 100 |
| limit | 2 |
| PID_velocity: | |
| P | 1 |
| I | 0.2 |
| D | 0.05 |
| output_ramp | 1000 |
| limit | 500 |
| LPF_current_q | 0.1 |
| LPF_current_d | 0 |
| LPF_velocity | 1 |
Can you explain this more? If the rotor permanant magnets are exactly opposite of the virtual magnets, wouldn’t that be 180 degrees out of phase?
Hi @schwghrt , welcome to SimpleFOC!
The 90deg referred to here is 90deg of electrical angle. It’s not the same as the physical angle.
A BLDC motor will have N electrical rotations per full physical turn of the motor, where N is equal to the number of pole pairs of the motor.
When driving the motor with FOC, you keep the force applied by the coils at 90deg electrical to the motors current position. This maximizes torque for the energy put in.
When aligning the motor, we set the coils to -90deg electrical and the motor “snaps to” the closest zero position.
You can read more about it in our documentation, in the “theory corner” section on FOC…
“When aligning the motor, we set the coils to -90deg electrical and the motor “snaps to” the closest zero position.”
Ah, of course. Thank you.
@runger, or anyone else, please check me on this…
We want to put the rotor’s electrical angle to zero. Essentially, we want the rotor’s magnetic field to point in the I_alpha (and the I_a) direction (U_beta = 0, U_alpha > 0). I am assuming this is the 0 degree direction.
We want the stator/coil electrical angle to be 180 degrees out of phase. This way the rotor will ‘snap’ to the right direction. (N to S, and S to N). So, we want the coil’s electric field to point in the (-) I_alpha direction (U_beta = 0, and U_alpha < 0).
Using the Inverse Park transform, we need to choose Uq, Ud and the electrical angle (e_angle) to accomplish this. The code sets Ud to zero, and Uq to an arbitrary positive value.
From the park transform:
U_alpha = -Sin(e_angle) Uq + Cos(e_angle) Ud
U_beta = Cos(e_angle) Uq + Sin(e_angle) Ud
Since Ud = 0, that simplifies to:
U_alpha = -Sin(e_angle) Uq
U_beta = Cos(e_angle) Uq
We want U_beta = 0, so e_angle must be PI/2 or 3PI/2.
And for U_alpha to be negative, e_angle must be PI/2.
But the code sets Uq > 0, and the angle to 3PI/2. Essentially, aligning the stator(coil) electrical field to zero degrees instead of the rotor (motor’s) electrical field to zero.
Is that the convention? It seems backwards to me.
