forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ported over some of the analytic gradients from posadev (just for man…
…ipulatorDynamics, not the contacts, constraints, or implicit cases… yet). git-svn-id: https://svn.csail.mit.edu/locomotion/robotlib/trunk@3502 c9849af7-e679-4ec6-a44e-fc146a885bd3
- Loading branch information
russt
committed
Aug 13, 2012
1 parent
e1a12fd
commit 12786ab
Showing
9 changed files
with
273 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function testGradients | ||
|
||
p = PlanarRigidBodyManipulator('../../../examples/Acrobot/Acrobot.urdf'); | ||
options.grad_method = {'user','taylorvar'}; | ||
|
||
for i=1:100 | ||
t = rand; | ||
x = randn(4,1); | ||
u = randn; | ||
|
||
[xdot,dxdot] = geval(@p.dynamics,t,x,u,options); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function dX = dXpln( theta, r, varIndex) | ||
|
||
% dXpln coordinate transform derivative wrt theta for planar vectors. | ||
% dXpln(theta,r) calculates the derivative of the coordinate transform | ||
% matrix from A to B coordinates for planar motion vectors, where | ||
% coordinate frame B is located at point r (2D vector expressed in A | ||
% coords) relative to frame A, and is rotated by an angle theta (radians) | ||
% relative to A. | ||
|
||
c = cos(theta); | ||
s = sin(theta); | ||
if varIndex == 1 | ||
dX = [0 0 0; c*r(1)+s*r(2) -s c; -s*r(1)+c*r(2) -c -s]; | ||
elseif varIndex == 2 | ||
dX = [0 0 0; s 0 0; c 0 0]; | ||
elseif varIndex == 3 | ||
dX = [0 0 0; -c 0 0; s 0 0]; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function dvcross = dcrfp( v ,x, dv, dx) | ||
% @return d/dy crfp(v)*x | ||
% @param v | ||
% @param x | ||
% @param dv = dv/dy | ||
% @param dx = dx/dy | ||
dvcross = [-dv(3,:)*x(2) - v(3)*dx(2,:) + dv(2,:)*x(3) + v(2)*dx(3,:);... | ||
-dv(1,:)*x(3) - v(1)*dx(3,:); dv(1,:)*x(2) + v(1)*dx(2,:)]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function dvcross = dcrmp( v ,x, dv, dx) | ||
% @return d/dy crmp(v)*x | ||
% @param v | ||
% @param x | ||
% @param dv = dv/dy | ||
% @param dx = dx/dy | ||
n = size(dv,2); | ||
dvcross = [zeros(1,n); dv(3,:)*x(1) + v(3)*dx(1,:) - dv(1,:)*x(3) - v(1)*dx(3,:);... | ||
-dv(2,:)*x(1) - v(2)*dx(1,:) + dv(1,:)*x(2) + v(1)*dx(2,:)]; | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function dXj = djcalcp( code, q ) | ||
|
||
% jcalcp Calculate derivative of joint transform | ||
% [dXj]=djcalcp(code,q) calculates the joint transform derivative | ||
% matrix for revolute (code==1), x-axis prismatic (code==2) and y-axis | ||
% prismatic (code==3) joints. | ||
|
||
if code == 1 % revolute joint | ||
dXj = dXpln( q, [0 0] ,1); | ||
elseif code == 2 % x-axis prismatic joint | ||
dXj = dXpln( 0, [q 0] ,2); | ||
elseif code == 3 % y-axis prismatic joint | ||
dXj = dXpln( 0, [0 q] ,3); | ||
else | ||
error( 'unrecognised joint code' ); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
function [y] = matGradMult(A,b,transposeA) | ||
% [y] = matGradMult(A,b) | ||
% If A is the result of dB/dX for matrix B and vector X, as output by | ||
% geval, then return A*b (a matrix). | ||
% @param vector b | ||
% @param gradient of A wrt. a vector, written as a matrix | ||
% geval) | ||
% @return A*b | ||
|
||
if exist('transposeA','var') | ||
if transposeA | ||
n = length(b); | ||
m = size(A,2); | ||
k = size(A,1)/n; | ||
y = zeros(m,n); | ||
for i=1:m, | ||
y(:,i) = reshape(A(:,i),n,k)'*b; | ||
end | ||
return; | ||
end | ||
end | ||
n = length(b); | ||
m = size(A,2); | ||
k = size(A,1)/n; | ||
|
||
B = sparse(repmat((1:k)',n,1),1:k*n,reshape(repmat(b',k,1),k*n,1),k,k*n); | ||
y = B*A; | ||
% B_row=repmat(reshape(diag([b;zeros(k-n-1,1)]),1,(k-1)^2),1,k); | ||
% B = reshape(B_row(1:k*k*n),k*n,k)'; | ||
% y = B*A; | ||
% return | ||
|
||
% tensor = reshape(A,k,n,m); tensor method was actually a little slower | ||
% % (<10% difference) | ||
% y = zeros(k,m); %was mxn-->changed to nxm then changed again | ||
% for i=1:m, %was n | ||
% y(:,i) = reshape(A(:,i),k,n)*b; | ||
% % y(:,i) = tensor(:,:,i)*b; | ||
% end | ||
end |