How to Filter a Commanded Position to have Velocity and Acceleration Limits in Simulink
54 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sonoma Rich
am 5 Okt. 2021
Kommentiert: Sonoma Rich
am 22 Mai 2023
I want to filter a commanded position signal to limit (saturate) its velocity and acceleration. I made the following model, but it has issue with the initial conditions and drift. If the signal is not saturated, I want it to equal the commanded position signal. Any suggestions on how to best model this?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/759126/image.png)
Akzeptierte Antwort
Paul
am 6 Okt. 2021
I'm not sure that it's feasible to meet all of the stated requirements, particularly "If the signal is not saturated, [it should] equal the commanded position signal." One option that may be close to what you want is to drive the input through a high bandwidth, low pass filter, and use the appropriate thresholds on the states in the filter. Like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/760121/image.png)
Set the velocity and the acceleeration limits in the block parameters of the second order integrator. Choose the gains to give a smooth and fast response relative to your input. One option would be:
K1 = w^3; K2 = 3*w/K1; K3 = 3*w^2/K1;
where w is chosen such w/3 is about 10 times larger than the largest frequency in the position command. You might have to play with that parameter for the specific position commands of interest.
This approach should yield position, velocity, and acceleration that are consistent with each other, but the position won't ever be exactly equal to the position command. It will get closer as w increases, which will also decrease the simulation step size, assuming use of a variable step solver.
5 Kommentare
Paul
am 7 Okt. 2021
I do think there will be some sensitivity of this approach to the gains, the thresholds, the input frequency, and the solver settings. If only interested in sine wave inputs, there might be a way to come up with a rule of thumb to set the gains based on the other parameters. For this particular example, I used:
w = 150*3; K1 = w^3; K2 = 3*w/K1; K3 = 3*w^2/K1;
and the result was
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/761131/image.png)
which doesn't look too bad. But the solution never did reach the acceleration saturation threshold. Increasing the gains yields
w = 3*150*3; K1 = w^3; K2 = 3*w/K1; K3 = 3*w^2/K1;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/761136/image.png)
Paul
am 19 Mai 2023
With this approach, start-up transients could be minimized by setting inital conditions on the integrators based on the input signal.
Weitere Antworten (1)
Captain Karnage
am 19 Mai 2023
Bearbeitet: Captain Karnage
am 19 Mai 2023
I believe I have a much simpler solution if you'd like to see it.
First of all, for your velocity limit, use the built-in rate limiter block instead of derivative + saturation. That will take care of your velocity without the issue of initial conditions when you re-integrate it, and it's only one block.
Since you also want acceleration, you will need to do a derivate (to get velocity after the rate limit) + rate limiter (to limit the acceleration) then integral (to get position back).
Then what you can do for the integral step for your initial conditions is as follows: go to the "block parameters" and for "Initial condition source" select "external". This will add a port to your integrator to feed your initial conditions to so you don't lose them. See my example here:
![Acceleration Limiter Diagram](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1388409/Acceleration%20Limiter%20Diagram.png)
Here is the integrator block setting:
![Integrator Block Parameters](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1387679/Integrator%20Block%20Parameters.png)
Like Paul's answer, it's still a little off on the final position, but it's really close.
3 Kommentare
Captain Karnage
am 19 Mai 2023
Thank you for the analysis, Paul, I appreciate the comparison that I didn't have time for myself. I should have mentioned my default is ode45. I do find the auto selected solver is often not the best and I often use ode45 as the baseline to compare. Of course, I occaisionally run into a model that doesn't run well on it and have to pick something else.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!