[Controller.cpp question]: are the velocity loop and the position loop running at the same frequency?

I am reading the source code of the axis, controller and encoder.

I am wondering if the encoder loop, velocity controller loop and the position controller loop are all updated at the same time?

If so, the frequency of velocity controller and the position controller are running at the same frequency?

Sorry if I asked the wrong question…

Yes they run at the same speed, about 8kHz today (we are looking to increase this in the future).

Note that while they are all updated at the same frequency, they may not have the same control bandwidth.

1 Like

Good to know~ I am wondering how will the frequency be increased? By code optimization or change a new processor?

Hi, this is a very interesting topic an I actually stumbled upon the same part of the code a few days ago. Is there any specific reason you chose the same update frequency for the 3 control loops? Correct me, but I thought a common practice is to have a cascade control scheme with the inner loop(s) always being faster than the outer one(s).

We could split it up to have say the current controller run much faster update rate than the position loop. The reason people usually do this is because it can be wasteful of the CPU resources to update the position loop much faster than the bandwidth. The reason we haven’t done this is because we have enough CPU resources even though we run the position loop so fast.

Though in the future we wish to run the PWM switching frequency faster, then we might split up the frequency of the current controller to run faster.

Are you planning to use semaphores in FreeRTOS to synchronize the frequency of the three loops?

For example, the velocity loop gives a semaphore to the position loop after running for ten laps,

so that the velocity loop will run ten times faster than the position loop?

Something like that. Though I think we will keep the pos and vel loop together. But the same concept between the current loop and the pos/vel loops yes.