You are here

Are the FOC PID values for discrete or continuous time controllers?

5 posts / 0 new
Last post
ward
Offline
Last seen: 2 years 1 month ago
Joined: 2021-09-21 17:52
Posts: 3
Are the FOC PID values for discrete or continuous time controllers?

Hi,

I am creating a (FOC-)model of my VESC6 driven RC-car in simulink. My simulated responses are not yet the same as the physical responses of the car (the simulation reacts slower). And now I am wondering wether the the PID gain values as displayed in the VESC-Tool are for a continuous-time or discrete-time controller. And if they are for a discrete-time controller, which sample frequency is the VESC6 using?

Currently I have copied the PID gain values from the VESC-Tool to continuous-time PID blocks in simulink.

And I used this image from wikipedia as a reference on the design of an FOC controller. The reference for I_d is zero.

All help is appreciated!

Kind regards!

ward
Offline
Last seen: 2 years 1 month ago
Joined: 2021-09-21 17:52
Posts: 3

I just looked into it a bit more, and I found that there is a switching frequency in the VESC-Tool. Am I correct in thinking that I can combine this value with the PID gains for a discrete-time controller?

Elwin
Offline
Last seen: 2 months 1 day ago
VESC Free
Joined: 2021-09-30 16:41
Posts: 76

The current controllers are discrete and pretty simple. Both D and Q axis controllers have this structure:

Iq_error = Iq_sp - Iq_meas

Vq = Vq_int + Iq_error * Kp

vq_int += Iq_error * (Ki * Ts)

Where Ts is the sample time. Normally Ts = 1 / switching_freq, but when you enable sample v0v7 option it becomes Ts = 0.5 / switching_freq. The switching frequency is half of the Zero Vector Frequency setting in the Vesc Tool.

For more detail check the source code: https://github.com/vedderb/bldc/blob/2d28ccbb05b442fbd4306cca6fcb5de1925...

Note: The vq_int is incremented after the calculation of Vq. This causes a 1 sample delay for the integrator. This is not very nice but the impact is small.

 

Are you also trying to model the PID position control or just the current control?

ward
Offline
Last seen: 2 years 1 month ago
Joined: 2021-09-21 17:52
Posts: 3

Thanks for your help!

I think that I have implemented the current control correctly now.

I am also modeling PID speed control, and the 'plant' exists of the surface mount PMSM block from simulink connected to a vehicle dynamics model which represents the RC car. When the VESC and PMSM are modeled properly, my next step will be to identify friction constants on the car in which can be used in the simulink model. But as long as the model (with the friction constants set to zero) reacts slower than the actual car, there is probably something wrong with my model of the VESC and or the motor.

About the speed PID controller: I have been looking into the source code that you linked, and I am wondering where this (1/20) factor is coming from in the p- i- and d-terms of the speed PID controller? If I leave this factor out, the step response of my model is starting to look similar to the physical step response of the car.

For now I am going to do a few more tests and see if I can verify if there are any differences between the source code that you linked, and the firmware I have used which includes steering servo control.

Thanks again!

 

Elwin
Offline
Last seen: 2 months 1 day ago
VESC Free
Joined: 2021-09-30 16:41
Posts: 76

Good to hear. I am not a fan of the speed pid implementation in vesc.

You need to take into account the factor 1/20 which seems like a pretty random factor. But also there is a scaling on the output with the max current, see 

https://github.com/vedderb/bldc/blob/2d28ccbb05b442fbd4306cca6fcb5de1925...

So you also need to take that into account. Apart from that it should be spot on.

PS. No need to use D action on a PID velocity loop. I don't know why that is even there.