-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcol_constraint_fun.m
23 lines (19 loc) · 1.06 KB
/
col_constraint_fun.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function [f,df] = col_constraint_fun(plant,h,x0,x1,u0,u1,xdot0,dxdot0,xdot1,dxdot1)
% this function is adapted from drake.
nX = plant.getNumStates();
nU = plant.getNumInputs();
% cubic interpolation to get xcol and xdotcol, as well as
% derivatives
xcol = .5*(x0+x1) + h/8*(xdot0-xdot1);
dxcol = [1/8*(xdot0-xdot1) (.5*eye(nX) + h/8*dxdot0(:,2:1+nX)) ...
(.5*eye(nX) - h/8*dxdot1(:,2:1+nX)) h/8*dxdot0(:,nX+2:1+nX+nU) -h/8*dxdot1(:,nX+2:1+nX+nU)];
xdotcol = -1.5*(x0-x1)/h - .25*(xdot0+xdot1);
dxdotcol = [1.5*(x0-x1)/h^2 (-1.5*eye(nX)/h - .25*dxdot0(:,2:1+nX)) ...
(1.5*eye(nX)/h - .25*dxdot1(:,2:1+nX)) -.25*dxdot0(:,nX+2:1+nX+nU) -.25*dxdot1(:,nX+2:1+nX+nU)];
% evaluate xdot at xcol, using foh on control input
[g,dgdxcol] = plant.dynamics(0,xcol,.5*(u0+u1));
dg = dgdxcol(:,2:1+nX)*dxcol + [zeros(nX,1+2*nX) .5*dgdxcol(:,2+nX:1+nX+nU) .5*dgdxcol(:,2+nX:1+nX+nU)];
% constrait is the difference between the two
f = xdotcol - g;
df = dxdotcol - dg;
end