I read the documentation of GRAMPC and some references using GRAMPC, and some of them mentioned that GRAMPC uses fixed reference trajectories xdes and udes by default. I would like to ask how to implement a reference trajectory that tracks single or multiple states?
Thanks.
Best regards,
Xu.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
the parameters xdes and udes are just offered as convenience for the frequent case of setpoints that are constant over the prediction horizon. With help of userparam, arbitrary complex scenarios can be realized on top of GRAMPC. Actually, this is described quite well in the thread that you have linked. Therefore, I would ask what have you tried and what were the results?
Important to note is that the time argument in the cost functions and constraints is the internal prediction time going from 0 to Thor, whereas it is the global time going from t0 to t0+Thor in the system dynamics functions. This means that for trajectory tracking, you often have to pass t0 as additional userparam to the cost function to determine with t0+t the corresponding time-varying setpoint.
Best regards,
Andreas Völz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your timely reply. I modified lfct and vfct in BALL_ON_PLATE, and changed the involved xdes[0] to the time-varying reference trajectory xref. At the same time, in order to only allow x[0] to achieve reference trajectory tracking, I set the corresponding weight value of x[1] to 0. The modified code is as follows:
Then after I run the code, the data in xvec.txt in res looks a bit incorrect. x[0] does not seem to track the reference trajectory, and x[1] still converges to 0. Is it because of the terminal cost item in the cost function? When I used MPC before, I didn't use this item much.
Best regards,
Xu.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your timely reply. I modified lfct and vfct in BALL_ON_PLATE, and changed the involved xdes[0] to the time-varying reference trajectory xref. At the same time, in order to only allow x[0] to achieve reference trajectory tracking, I set the corresponding weight value of x[1] to 0. The modified code is as follows:
Then after I run the code, the data in xvec.txt in res looks a bit incorrect. x[0] does not seem to track the reference trajectory, and x[1] still converges to 0. Is it because of the terminal cost item in the cost function? When I used MPC before, I didn't use this item much.
Best regards,
Xu.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
looks like it is basically working. The next step would be to check the influence of different parameters (weighting factors, number of iterations, ...) on the tracking performance. Furthermore, I am not sure if your reference trajectory is feasible with respect to the system dynamics, that is, whether perfect tracking would be possible at all.
Best regards,
Andreas Völz
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you very much for your help. This reference track is just to verify how to track the time-varying reference track. I am going to implement a complete MPC these days.
Thank you again! Your response was very timely and resolved my doubts, thank you very much!
Best regards,
Xu.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks for the positive feedback. Some more complex examples (e.g. trajectory tracking, C++ interface, ...) are still on the "to do list" for the next update of GRAMPC.
Best regards,
Andreas Völz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
if you set unext as udes, this is some kind of regularization but not a weighting of the control input rate. The typical approach would be to use the time derivative of your true input as virtual input in GRAMPC and add an integrator to the model to obtain the true input as integral of the virtual input. Then you can use umax and umin to limit the control input rate. Note however, that the constraints on the true input must then be realized as state constraint via hfct.
Best regards,
Andreas Völz
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear Andreas Völz,
Your reply is so fast, thank you very much!
if you set unext as udes, this is some kind of regularization but not a weighting of the control input rate.
In my understanding, shouldn't regularization and penalty terms have the same meaning? My purpose is to add a penalty term to the control input change in the cost function, so that the control variable does not change drastically in a short period of time. According to my understanding it is feasible to set unext to udes. Is not my understanding of the problem?😔
Best regards,
WenChao Xu.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
if you set udes to unext, the result will be a damping of the control updates. The higher the weighting, the closer the next "unext" will be to the previous "unext". However, my point was that this "unext" is the same along the whole prediction horizon, that is, for all t \in [0, Thor], the difference of u(t) to unext is weighted. This is different from weighting \dot u(t) or the discrete approximation u(t) - u(t + \delta t). Both is feasible of course and it depends on what you actually want to achieve.
Best regards,
Andreas Völz
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Andreas Völz. Hahaha, I'm here to ask a question again, and I'm a little embarrassed.😂😂😂
I tried the method you mentioned above, but I ran into some problems. I modified code based on BallOnPlate:
Letu_real = x3; u_virtual=u1; And take the upper and lower limits of the real control as the constraints of the new state, and the upper and lower limits of the virtual control, i.e. , the constraints of the control input rate are: [-0.0524,0.0524]. This range needs to be modified according to requirements, here is an example.
/* reference integration of the system via heun scheme since grampc->sol->xnext is only an interpolated value */ffct(rwsReferenceIntegration,t,grampc->param->x0,grampc->sol->unext,grampc->sol->pnext,grampc->userparam);for(i=0;i<NX;i++){grampc->sol->xnext[i]=grampc->param->x0[i]+dt*rwsReferenceIntegration[i];}ffct(rwsReferenceIntegration+NX,t+dt,grampc->sol->xnext,grampc->sol->unext,grampc->sol->pnext,grampc->userparam);for(i=0;i<NX;i++){grampc->sol->xnext[i]=grampc->param->x0[i]+dt*(rwsReferenceIntegration[i]+rwsReferenceIntegration[i+NX])/2;}
The output result after running feels unreasonable, as shown in the figure below:
thanks for sharing the code and the plots. I guess that you also implemented dhdx_vec and not only hfct although you didn't show it. The problem may be either an implementation error (although I saw no obvious one) or a matter of tuning, which is clearly more difficult with the additional integrator. From the plots it seems that it may be impossible for the system to follow the trajectory with these input rate limits. Since the system is too slow, it lags behind the reference, which then leads to instability of the MPC. Maybe you try it with a slower reference trajectory or larger bounds on the rate?
Otherwise, I could try to implement a minimal working example, but it could take some time, since I have a lot of things to do currently.
Best regards,
Andreas Völz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
another idea would be to test the rate limits first for the simpler task of setpoint stabilization. That is, replace the reference trajectory with constant desired values and see whether you can tune the MPC for exponentially decreasing cost.
Best regards,
Andreas Völz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone!
I read the documentation of GRAMPC and some references using GRAMPC, and some of them mentioned that GRAMPC uses fixed reference trajectories
xdes
andudes
by default. I would like to ask how to implement a reference trajectory that tracks single or multiple states?Thanks.
Best regards,
Xu.
I read this discussion https://sourceforge.net/p/grampc/discussion/general/thread/ab9aafc9a5/ ; But when I try to modify
BallOnPlate
, the result does not seem to be correct.Dear WenChao Xu,
the parameters xdes and udes are just offered as convenience for the frequent case of setpoints that are constant over the prediction horizon. With help of userparam, arbitrary complex scenarios can be realized on top of GRAMPC. Actually, this is described quite well in the thread that you have linked. Therefore, I would ask what have you tried and what were the results?
Important to note is that the time argument in the cost functions and constraints is the internal prediction time going from 0 to Thor, whereas it is the global time going from t0 to t0+Thor in the system dynamics functions. This means that for trajectory tracking, you often have to pass t0 as additional userparam to the cost function to determine with t0+t the corresponding time-varying setpoint.
Best regards,
Andreas Völz
Dear Andreas Völz
Thank you for your timely reply. I modified
lfct
andvfct
inBALL_ON_PLATE
, and changed the involvedxdes[0]
to the time-varying reference trajectoryxref
. At the same time, in order to only allowx[0]
to achieve reference trajectory tracking, I set the corresponding weight value ofx[1]
to0
. The modified code is as follows:Then after I run the code, the data in
xvec.txt
inres
looks a bit incorrect.x[0]
does not seem to track the reference trajectory, andx[1]
still converges to0
. Is it because of the terminal cost item in the cost function? When I usedMPC
before, I didn't use this item much.Best regards,
Xu.
Dear Andreas Völz
Thank you for your timely reply. I modified
lfct
andvfct
inBALL_ON_PLATE
, and changed the involvedxdes[0]
to the time-varying reference trajectoryxref
. At the same time, in order to only allowx[0]
to achieve reference trajectory tracking, I set the corresponding weight value ofx[1]
to0
. The modified code is as follows:Then after I run the code, the data in
xvec.txt
inres
looks a bit incorrect.x[0]
does not seem to track the reference trajectory, andx[1]
still converges to0
. Is it because of the terminal cost item in the cost function? When I usedMPC
before, I didn't use this item much.Best regards,
Xu.
Dear WenChao Xu,
your basic approach seems correct to me. However, I guess that
should be changed into
Furthermore, you need to update the global time in each MPC step, that is, the MPC loop should be modified as
Please try this and report on the results.
Best regards,
Andreas Völz
Dear Andreas Völz
Thank you very much for your reply. I modified it according to your comment. One difference is that,
userparam[9] = t;
---->pcost[9]=t
The result of the operation is shown in
figure
. The generation ofreference x1
involved in it is also in the linked file.Best regards,
Xu.
Dear WenChao Xu,
looks like it is basically working. The next step would be to check the influence of different parameters (weighting factors, number of iterations, ...) on the tracking performance. Furthermore, I am not sure if your reference trajectory is feasible with respect to the system dynamics, that is, whether perfect tracking would be possible at all.
Best regards,
Andreas Völz
Dear Andreas Völz
Thank you very much for your help. This reference track is just to verify how to track the time-varying reference track. I am going to implement a complete MPC these days.
Thank you again! Your response was very timely and resolved my doubts, thank you very much!
Best regards,
Xu.
Dear WenChao Xu,
thanks for the positive feedback. Some more complex examples (e.g. trajectory tracking, C++ interface, ...) are still on the "to do list" for the next update of GRAMPC.
Best regards,
Andreas Völz
Dear Andreas Völz,
Hello! Does it only need to write the following code during the running of MPC to implement the penalty term for the control input signal rate:
the penalty term for the control input signal rate is:
||Δu||
, whereΔu=uk - uk-1
.lfct
function:Best regards,
WenChao Xu.
Dear WenChao Xu,
if you set unext as udes, this is some kind of regularization but not a weighting of the control input rate. The typical approach would be to use the time derivative of your true input as virtual input in GRAMPC and add an integrator to the model to obtain the true input as integral of the virtual input. Then you can use umax and umin to limit the control input rate. Note however, that the constraints on the true input must then be realized as state constraint via hfct.
Best regards,
Andreas Völz
Dear Andreas Völz,
Your reply is so fast, thank you very much!
In my understanding, shouldn't regularization and penalty terms have the same meaning? My purpose is to add a penalty term to the control input change in the cost function, so that the control variable does not change drastically in a short period of time. According to my understanding it is feasible to set
unext
toudes
. Is not my understanding of the problem?😔Best regards,
WenChao Xu.
Dear WenChao Xu,
if you set udes to unext, the result will be a damping of the control updates. The higher the weighting, the closer the next "unext" will be to the previous "unext". However, my point was that this "unext" is the same along the whole prediction horizon, that is, for all t \in [0, Thor], the difference of u(t) to unext is weighted. This is different from weighting \dot u(t) or the discrete approximation u(t) - u(t + \delta t). Both is feasible of course and it depends on what you actually want to achieve.
Best regards,
Andreas Völz
Dear Andreas Völz,
Ok, I tried to implement this, thanks a lot!😊
Best regards,
WenChao Xu.
Dear Andreas Völz,
Hello Andreas Völz. Hahaha, I'm here to ask a question again, and I'm a little embarrassed.😂😂😂
I tried the method you mentioned above, but I ran into some problems. I modified code based on
BallOnPlate
:Let
u_real = x3
;u_virtual=u1
; And take the upper and lower limits of the real control as the constraints of the new state, and the upper and lower limits of the virtual control, i.e. , the constraints of the control input rate are:[-0.0524,0.0524]
. This range needs to be modified according to requirements, here is an example.The output result after running feels unreasonable, as shown in the figure below:
State Trajectory and Reference Trajectory
;Control input rate
;cost curve
.Best regards,
WenChao Xu.
Last edit: WenChao Xu 2023-04-26
Dear WenChao Xu,
thanks for sharing the code and the plots. I guess that you also implemented dhdx_vec and not only hfct although you didn't show it. The problem may be either an implementation error (although I saw no obvious one) or a matter of tuning, which is clearly more difficult with the additional integrator. From the plots it seems that it may be impossible for the system to follow the trajectory with these input rate limits. Since the system is too slow, it lags behind the reference, which then leads to instability of the MPC. Maybe you try it with a slower reference trajectory or larger bounds on the rate?
Otherwise, I could try to implement a minimal working example, but it could take some time, since I have a lot of things to do currently.
Best regards,
Andreas Völz
Dear Andreas Völz,
Thank you for your reply!
Yes, I also implemented
dhdx_vec
.I'm going to modify the code now.It doesn't matter, you just do your own thing, don't spend time writing examples. I hope you will become an academic leader soon, thank you 💖
Best regards,
WenChao Xu.
Last edit: WenChao Xu 2023-04-26
Dear WenChao Xu,
another idea would be to test the rate limits first for the simpler task of setpoint stabilization. That is, replace the reference trajectory with constant desired values and see whether you can tune the MPC for exponentially decreasing cost.
Best regards,
Andreas Völz
Dear Andreas Völz,
I tested it, and did the same test with another model, and it seems the result is still not good. I'm checking to see if there are any errors.
Best regards
WenChao Xu.
Last edit: WenChao Xu 2023-04-26