I am using acados in Matlab. I wonder how to get the objective function value from ocp in Matlab. I tried to directly call “ocp.get_cost” to get the cost value. But I compared the value with the cost I computed by myself and they are totally different. Is the function “ocp.get_cost” exactly output the cost value or is there something I missed?

Yes, it should evaluate and output the cost function at the current iterate.
Note that the stage cost terms are weighted with the time step that is covored by the subsequent shooting interval.

Could you give more details about this? I tried to compare the cost provided by acados with the one computed as (25) and (26) here, starting from the output trajectories, but I get different results.

More in detail, in minimal_example_ocp.m (Matlab interface), I compared: