forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from mposa/collision-dynamics-integration
Minor bug fixes, worked on fallingBrickLCP example.
- Loading branch information
Showing
5 changed files
with
105 additions
and
106 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
110 changes: 48 additions & 62 deletions
110
systems/plants/@RigidBodyManipulator/contactPositions.m
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 |
---|---|---|
@@ -1,63 +1,49 @@ | ||
function [contact_pos,J,dJ] = contactPositions(obj,kinsol,body_idx,body_contacts) | ||
error('The contactPositions function has been deprecated. See contactConstraints and collisionDetect') | ||
% % @param body_idx is an array of body indexes | ||
% % @param body_contacts is a cell array of vectors containing contact point indices | ||
% % | ||
% % @retval p(:,i)=[px;py;pz] is the position of the ith contact point | ||
% % @retval J is dpdq | ||
% % @retval dJ is ddpdqdq | ||
% % @ingroup Collision | ||
% | ||
% if ~isstruct(kinsol) | ||
% % treat input as contactPositions(obj,q) | ||
% kinsol = doKinematics(obj,kinsol,nargout>2); | ||
% end | ||
function [contact_pos,J,dJ, body_idx] = contactPositions(obj,kinsol,varargin) | ||
% function [contact_pos,J,dJ] = contactPositions(obj,kinsol,allow_multiple_contacts,active_collision_options) | ||
% Compute the contact positions and Jacobians, if interested in the | ||
% inertial frame positions of these points. Most applications should see | ||
% the contactConstraints function instead. | ||
% | ||
% @param obj | ||
% @param kinsol | ||
% @param allow_multiple_contacts Allow multiple contacts per body pair. | ||
% Optional, defaults to false. | ||
% @param active_collision_options A optional struct to determine which | ||
% bodies and collision groups are checked. See collisionDetect. | ||
% | ||
% if nargin<3 | ||
% body_idx = 1:length(obj.body); | ||
% end | ||
% | ||
% if nargin<4 | ||
% n_contact_pts = size([obj.body(body_idx).contact_pts],2); | ||
% body_contacts = []; | ||
% else | ||
% if isa(body_contacts,'cell') | ||
% n_contact_pts = sum(cellfun('length',body_contacts)); | ||
% else | ||
% n_contact_pts = length(body_contacts); | ||
% body_contacts = {body_contacts}; | ||
% end | ||
% end | ||
% | ||
% d=3; %obj.dim; % 2 for planar, 3 for 3D | ||
% contact_pos = zeros(d,n_contact_pts)*kinsol.q(1); | ||
% | ||
% if (nargout>1) | ||
% J = zeros(n_contact_pts*d,obj.num_q)*kinsol.q(1); | ||
% end | ||
% if (nargout>2) | ||
% dJ = sparse(n_contact_pts*d,obj.num_q^2); | ||
% end | ||
% | ||
% count=0; | ||
% for i=1:length(body_idx) | ||
% if isempty(body_contacts) | ||
% nC = size(obj.body(body_idx(i)).contact_pts,2); | ||
% pts_idx = 1:nC; | ||
% else | ||
% pts_idx = body_contacts{i}; | ||
% nC = length(pts_idx); | ||
% end | ||
% if nC>0 | ||
% if (nargout>2) | ||
% [contact_pos(:,count+(1:nC)),J(d*count+(1:d*nC),:),dJ(d*count+(1:d*nC),:)] = forwardKin(obj,kinsol,body_idx(i),obj.body(body_idx(i)).contact_pts(:,pts_idx)); | ||
% elseif (nargout>1) | ||
% [contact_pos(:,count+(1:nC)),J(d*count+(1:d*nC),:)] = forwardKin(obj,kinsol,body_idx(i),obj.body(body_idx(i)).contact_pts(:,pts_idx)); | ||
% else | ||
% contact_pos(:,count+(1:nC)) = forwardKin(obj,kinsol,body_idx(i),obj.body(body_idx(i)).contact_pts(:,pts_idx)); | ||
% end | ||
% count = count + nC; | ||
% end | ||
% end | ||
% | ||
% end | ||
% @retval contact_pos (3 x 2m) is the set of inertial positions of the | ||
% contacts (nearest point on a body to another body) | ||
% @retval J (6m x n) = d/dq contact_pos | ||
% @retval dJ (6m x n^2) = dd/dqdq contact_pos | ||
% @retval body_idx (2m x 1) body indices | ||
|
||
if ~isstruct(kinsol) | ||
% treat input as contactPositions(obj,q) | ||
kinsol = doKinematics(obj,kinsol); | ||
end | ||
|
||
[~,~,xA,xB,idxA,idxB] = obj.collisionDetect(kinsol,varargin{:}); | ||
|
||
nq = obj.getNumPositions; | ||
nC = length(idxA); | ||
body_idx = [idxA;idxB]; | ||
x_body = [xA xB]; | ||
contact_pos = zeros(3,2*nC); | ||
|
||
if nargout > 1, | ||
J = zeros(6*nC,nq); | ||
end | ||
if nargout > 2, | ||
dJ = zeros(6*nC,nq^2); | ||
end | ||
|
||
for i=1:2*nC, | ||
if (nargout>2) | ||
[contact_pos(:,i),J((1:3) + 3*(i-1),:),dJ((1:3) + 3*(i-1),:)] = obj.forwardKin(kinsol,body_idx(i),x_body(:,i)); | ||
elseif (nargout>1) | ||
[contact_pos(:,i),J((1:3) + 3*(i-1),:)] = obj.forwardKin(kinsol,body_idx(i),x_body(:,i)); | ||
else | ||
contact_pos(:,i) = obj.forwardKin(kinsol,body_idx(i),x_body(:,i)); | ||
end | ||
end | ||
end |
80 changes: 39 additions & 41 deletions
80
systems/plants/@RigidBodyManipulator/contactPositionsJdot.m
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 |
---|---|---|
@@ -1,52 +1,50 @@ | ||
function [contact_pos,J,Jdot] = contactPositionsJdot(obj,kinsol,body_idx,body_contacts) | ||
% @retval p(:,i)=[px;py;pz] is the position of the ith contact point | ||
% @retval J is dpdq | ||
% @retval Jdot is d(dpdq)dt | ||
% @ingroup Collision | ||
|
||
typecheck(kinsol,'struct'); | ||
function [contact_pos,J,Jdot] = contactPositionsJdot(obj,kinsol,varargin) | ||
% function [contact_pos,J,dJ] = contactPositionsJdot(obj,kinsol,body_idx,body_contacts) | ||
% Compute the contact positions and Jacobians, if interested in the | ||
% inertial frame positions of these points. Most applications should see | ||
% the contactConstraints function instead. | ||
% | ||
% @param obj | ||
% @param kinsol | ||
% @param allow_multiple_contacts Allow multiple contacts per body pair. | ||
% Optional, defaults to false. | ||
% @param active_collision_options A optional struct to determine which | ||
% bodies and collision groups are checked. See collisionDetect. | ||
% | ||
% @retval contact_pos (3 x 2m) is the set of inertial positions of the | ||
% contacts (nearest point on a body to another body) | ||
% @retval J (6m x n) = d/dq contact_pos | ||
% @retval dJ (6m x n^2) = dd/dqdq contact_pos | ||
% @retval body_idx (2m x 1) body indices | ||
|
||
if nargin<3 | ||
body_idx = 1:length(obj.body); | ||
if ~isstruct(kinsol) | ||
% treat input as contactPositions(obj,q) | ||
kinsol = doKinematics(obj,kinsol); | ||
end | ||
|
||
if nargin<4 | ||
n_contact_pts = size([obj.body(body_idx).contact_pts],2); | ||
body_contacts = []; | ||
else | ||
n_contact_pts = sum(cellfun('length',body_contacts)); | ||
end | ||
[~,~,xA,xB,idxA,idxB] = obj.collisionDetect(kinsol,varargin{:}); | ||
|
||
d=length(obj.gravity); % 2 for planar, 3 for 3D | ||
contact_pos = zeros(d,n_contact_pts)*kinsol.q(1); | ||
nq = obj.getNumPositions; | ||
nC = length(idxA); | ||
body_idx = [idxA;idxB]; | ||
x_body = [xA xB]; | ||
contact_pos = zeros(3,2*nC); | ||
|
||
if (nargout>1) | ||
J = zeros(n_contact_pts*d,obj.num_q); | ||
if nargout > 1, | ||
J = zeros(6*nC,nq); | ||
end | ||
if (nargout>2) | ||
Jdot = zeros(n_contact_pts*d,obj.num_q); | ||
if nargout > 2, | ||
Jdot = zeros(6*nC,nq); | ||
end | ||
|
||
count=0; | ||
for i=1:length(body_idx) | ||
if isempty(body_contacts) | ||
nC = size(obj.body(body_idx(i)).contact_pts,2); | ||
pts_idx = 1:nC; | ||
for i=1:2*nC, | ||
if (nargout>2) | ||
[contact_pos(:,i),J((1:3) + 3*(i-1),:)] = obj.forwardKin(kinsol,body_idx(i),x_body(:,i)); | ||
Jdot((1:3) + 3*(i-1),:) = forwardJacDot(obj,kinsol,body_idx(i),x_body(:,i)); | ||
elseif (nargout>1) | ||
[contact_pos(:,i),J((1:3) + 3*(i-1),:)] = obj.forwardKin(kinsol,body_idx(i),x_body(:,i)); | ||
else | ||
pts_idx = body_contacts{i}; | ||
nC = length(pts_idx); | ||
end | ||
if nC>0 | ||
if (nargout>2) | ||
[contact_pos(:,count+(1:nC)),J(d*count+(1:d*nC),:)] = forwardKin(obj,kinsol,body_idx(i),obj.body(body_idx(i)).contact_pts(:,pts_idx)); | ||
Jdot(d*count+(1:d*nC),:) = forwardJacDot(obj,kinsol,body_idx(i),obj.body(body_idx(i)).contact_pts(:,pts_idx)); | ||
elseif (nargout>1) | ||
[contact_pos(:,count+(1:nC)),J(d*count+(1:d*nC),:)] = forwardKin(obj,kinsol,body_idx(i),obj.body(body_idx(i)).contact_pts(:,pts_idx)); | ||
else | ||
contact_pos(:,count+(1:nC)) = forwardKin(obj,kinsol,body_idx(i),obj.body(body_idx(i)).contact_pts(:,pts_idx)); | ||
end | ||
count = count + nC; | ||
contact_pos(:,i) = obj.forwardKin(kinsol,body_idx(i),x_body(:,i)); | ||
end | ||
end | ||
|
||
end | ||
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