Hi,
the cost function is evaluated at the current iterate.
If the solver has previously exited with an error (as in your second screenshot).
It can of course be that evaluating the cost at the current iterate gives NaN or Inf.
Also, your cost function definition is not clear to me.
Defining the cost as norm(u_ref) would make me think that u_ref are parameters that you provide (reference values). Thus the cost would be constant and not dependent on the state and control trajectory within the solver.
Maybe you mean norm(u - u_ref) ?
The way you set the parameters seems correct though.
Note that the cost value is scaled with the time steps, i.e.
c = t_0 c_0(x_0, u_0) + ... + t_{N-1} c_{N-1}(x_{N-1}, u_{N-1}) + c_{N}(x_{N})
where c denotes the total cost, c_i the cost term at shooting node with index i.