MatthewPeterKelly / OptimTraj

A trajectory optimization library for Matlab
MIT License
598 stars 207 forks source link

How to visualize path costs? #32

Closed MatthewPeterKelly closed 6 years ago

MatthewPeterKelly commented 6 years ago

1) I want to display the bound and path cost for a solution. The closest thing that I found was soln.info.objVal.

2) I noticed that @(t0,x0,tF,xF) bndCst(soln.time(1), soln.time(end)) + sum(@(t,z,u) pathCst(soln.control)) is not equal to soln.info.objVal. What is going on here?

MatthewPeterKelly commented 6 years ago

1) You can compute the bound objective for the optimal solution using: problem.func.bndObj(t0,x0,tF,xF) where t0, x0, tF, xF are computed using the data from soln.interp or soln.grid. You can compute the path objective for the optimal solution using: problem.func.pathObj(t,x,u) where t, x, u is computed using data from soln.interp or soln.grid.

2) OptimTraj is minimizing the integral of the path objective, which in general is not equal to the sum of the objective function's value at the knot points. Take a look inside of `hermiteSimpson.m' and you will see that the quadrature weights are non-uniform:

problem.func.weights = (2/3)*ones(nGrid,1);
problem.func.weights(2:2:end) = 4/3;
problem.func.weights([1,end]) = 1/3;

Note that these weights will be scaled by time in directCollocation.m.