Menu

Time Delay System - Passing grampc.rws.u

2025-07-01
2025-07-06
  • Krysten Lambeth

    Krysten Lambeth - 2025-07-01

    Hello again,

    I read an existing post on how to model a time delay system by passing grampc.rws.u via userparam. Specifically, the recommendation was, "The trick could be to pass the grampc-pointer via userparam to the problem functions, then you can interpolate arbitrary states using grampc->rws->x and grampc->rws->u."

    Per my previous post, I understand how to store grampc.rws.u after the optimization problem is solved. This works no problem! What I don't know is how to access grampc.rws.u within probfct.c while the optimization problem is being solved. Adding constants to userparam in Simulink is simple, but grampc.rws.u is a pointer.

    For example, if the time delay is 4 and the MPC is looking at step 5, the dynamics need to be driven by grampc.rws.u(1), which isn't known a priori. Any help you can provide would be greatly appreciated!

     
  • Andreas Völz

    Andreas Völz - 2025-07-01

    Dear Krysten,

    our preferred approach to handling a time delay is described in Section 4.2 of the paper https://www.sciencedirect.com/science/article/pii/S0957415824000552#sec4. The strategy is to set all gradients to zero for times below the delay. We have tested this experimentally with multiple systems and it generally works quite well. The post on the time delay system may be older, I think we never tried to implement this approach.

    Best regards,
    Andreas Völz

     
  • Krysten Lambeth

    Krysten Lambeth - 2025-07-05

    Dear Andreas,

    Thank you for pointing me to this paper. If I understand correctly, this method would only enforce the input delay for the first N steps (if N is the number of time steps in the delay); however, this should still be a close enough approximation for my purposes.

    A follow-up question: is there a way to update the initial guess at each optimization step? I saw on a previous post that this could be done in mdlOutputs (in grampc_run_Sfct) after reading userparams (~line 339) and before calling grampc_run (line ~348). Would it be something like the following:

    for (i = 0; i < size_userpram; i++) {
            loc_userparam[i] = (typeRNum)d_userparam[i];
    }
    
    /* pull initial guess */
    ut0 = loc_userparam[17];
    
    /* assign initial guess to grampc */
    grampc_setparam_real_vector(grampc,"u0",ut0);
    
    /* run mpc */
    grampc_run(grampc)
    
     
  • Andreas Völz

    Andreas Völz - 2025-07-05

    Dear Krysten,

    I would not say that the input delay is only enforced for the first N steps. If you have a time delay, then your current input does not influence the current state but instead a future state. The forward integration in GRAMPC automatically predicts what the future state after the time delay will be. However, the respective part of the control trajectory is already in the process of execution and can therefore no longer be changed. This is achieved by setting all gradients to zero in this time interval. The optimal input that is applied to the system is then also not the first one, but the one after the predicted time delay. Probably this sounds complex, but I would need to create a sketch in order to explain it better.

    Regarding updating the initial guess. First note that GRAMPC automatically performs a warmstart where the previous control trajectory is used as initial guess for the next run. Furthermore, if the option ControlShift is activated, the input trajectory is shifted by the sampling time each time grampc_run is called. Then note that the parameter u0 sets all inputs along the horizon to the same constant value. For setting a time-varying initial guess you would need to directly set grampc->rws->u in the same way as we previously tried to read its value.

    If you describe your problem and what you want to achieve in more detail, I can probably help you better. We can also schedule an online meeting if you don't want to share such details in a public discussion board.

    Best regards,
    Andreas Völz

     
  • Krysten Lambeth

    Krysten Lambeth - 2025-07-06

    Dear Andreas,

    Thank you for the explanation about the time delay. I'm relieved to hear that it applies the delay for the entire prediction horizon.

    A meeting would be very helpful! I can give more details about the particular constraints I'm working with. Thank you kindly for offering. My email is kflambet@ncsu.edu if you want to let me know what times work for you.

    Sincerely,
    Krysten

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.