Hi ![]()
I am trying to implement an NMPC simulation in acados.
My cost function differs slightly from the conventional one, so I would like to use the "EXTERNAL" cost type; however, I am unsure how to implement it.
The NMPC cost I want to realize is as follows (ref: https://onlinelibrary.wiley.com/doi/10.1002/rnc.70083):

where \ell(x,u) and \varphi(x) denote the stage cost and terminal cost, respectively, both defined in quadratic form.

In particular, the stage cost contains an integral over the sampling period.
Assuming a zero-order hold (ZOH) on the control input during each interval, I would like to approximate this integral more accurately using Simpson’s rule. This requires subdividing the sampling interval into smaller segments and applying the Simpson approximation, which typically involves a for-loop style computation.
From what I have seen, most example codes do not use such integral-type costs.
Could you give me some advice on how to implement this kind of integral cost in acados? Also, if there are more common or recommended ways to handle such integral costs, I would be very interested to learn about them.
I really appreciate any help you can provide.