-
Notifications
You must be signed in to change notification settings - Fork 44
bullet-featherstone: Fix bounding box for collisions with pose offset #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,30 +22,40 @@ | |
namespace physics { | ||
namespace bullet_featherstone { | ||
|
||
|
||
FrameData3d getNonBaseLinkFrameData(const ModelInfo *_modelInfo, | ||
const LinkInfo *_linkInfo) | ||
{ | ||
const auto index = _linkInfo->indexInModel.value(); | ||
FrameData3d data; | ||
data.pose = GetWorldTransformOfLink(*_modelInfo, *_linkInfo); | ||
const auto &link = _modelInfo->body->getLink(index); | ||
data.linearVelocity = convert(link.m_absFrameTotVelocity.getLinear()); | ||
data.angularVelocity = convert(link.m_absFrameTotVelocity.getAngular()); | ||
return data; | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
FrameData3d KinematicsFeatures::FrameDataRelativeToWorld( | ||
const FrameID &_id) const | ||
{ | ||
const auto linkIt = this->links.find(_id.ID()); | ||
bool isModel = false; | ||
bool isCollision = false; | ||
const ModelInfo *model = nullptr; | ||
Eigen::Isometry3d collisionPoseOffset = Eigen::Isometry3d(); | ||
|
||
const auto linkIt = this->links.find(_id.ID()); | ||
if (linkIt != this->links.end()) | ||
{ | ||
const auto &linkInfo = linkIt->second; | ||
const auto indexOpt = linkInfo->indexInModel; | ||
model = this->ReferenceInterface<ModelInfo>(linkInfo->model); | ||
|
||
if (indexOpt.has_value()) | ||
if (linkInfo->indexInModel.has_value()) | ||
{ | ||
const auto index = *indexOpt; | ||
FrameData data; | ||
data.pose = GetWorldTransformOfLink(*model, *linkInfo); | ||
const auto &link = model->body->getLink(index); | ||
data.linearVelocity = convert(link.m_absFrameTotVelocity.getLinear()); | ||
data.angularVelocity = convert(link.m_absFrameTotVelocity.getAngular()); | ||
return data; | ||
return getNonBaseLinkFrameData(model, linkInfo.get()); | ||
} | ||
|
||
// If indexOpt is nullopt then the link is the base link which will be | ||
// If indexInModel is nullopt then the link is the base link which will be | ||
// calculated below. | ||
} | ||
else | ||
|
@@ -59,60 +69,55 @@ | |
if (linkIt2 != this->links.end()) | ||
{ | ||
const auto &linkInfo2 = linkIt2->second; | ||
const auto indexOpt2 = linkInfo2->indexInModel; | ||
model = this->ReferenceInterface<ModelInfo>(linkInfo2->model); | ||
|
||
if (indexOpt2.has_value()) | ||
if (linkInfo2->indexInModel.has_value()) | ||
{ | ||
const auto index2 = *indexOpt2; | ||
FrameData data; | ||
data.pose = GetWorldTransformOfLink(*model, *linkInfo2); | ||
const auto &link = model->body->getLink(index2); | ||
data.linearVelocity = convert( | ||
link.m_absFrameTotVelocity.getLinear()); | ||
data.angularVelocity = convert( | ||
link.m_absFrameTotVelocity.getAngular()); | ||
return data; | ||
return getNonBaseLinkFrameData(model, linkInfo2.get()); | ||
} | ||
} | ||
} | ||
|
||
auto collisionIt = this->collisions.find(_id.ID()); | ||
if (collisionIt != this->collisions.end()) | ||
else | ||
{ | ||
const auto &collisionInfo = collisionIt->second; | ||
|
||
const auto linkIt2 = this->links.find(collisionInfo->link); | ||
if (linkIt2 != this->links.end()) | ||
auto collisionIt = this->collisions.find(_id.ID()); | ||
if (collisionIt != this->collisions.end()) | ||
{ | ||
const auto &linkInfo2 = linkIt2->second; | ||
const auto indexOpt2 = linkInfo2->indexInModel; | ||
model = this->ReferenceInterface<ModelInfo>(linkInfo2->model); | ||
isCollision = true; | ||
const auto &collisionInfo = collisionIt->second; | ||
|
||
if (indexOpt2.has_value()) | ||
const auto linkIt2 = this->links.find(collisionInfo->link); | ||
if (linkIt2 != this->links.end()) | ||
{ | ||
const auto index2 = *indexOpt2; | ||
FrameData data; | ||
data.pose = GetWorldTransformOfLink(*model, *linkInfo2); | ||
const auto &link = model->body->getLink(index2); | ||
data.linearVelocity = convert( | ||
link.m_absFrameTotVelocity.getLinear()); | ||
data.angularVelocity = convert( | ||
link.m_absFrameTotVelocity.getAngular()); | ||
return data; | ||
const auto &linkInfo2 = linkIt2->second; | ||
model = this->ReferenceInterface<ModelInfo>(linkInfo2->model); | ||
collisionPoseOffset = collisionInfo->linkToCollision; | ||
if (linkInfo2->indexInModel.has_value()) | ||
{ | ||
auto data = getNonBaseLinkFrameData(model, linkInfo2.get()); | ||
data.pose = data.pose * collisionPoseOffset; | ||
return data; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
auto modelIt = this->models.find(_id.ID()); | ||
if (modelIt != this->models.end()) | ||
{ | ||
model = modelIt->second.get(); | ||
isModel = true; | ||
} | ||
} | ||
} | ||
|
||
if (!model || model->body == nullptr) | ||
model = this->FrameInterface<ModelInfo>(_id); | ||
} | ||
|
||
FrameData data; | ||
if(model && model->body) | ||
if (model && model->body) | ||
{ | ||
data.pose = convert(model->body->getBaseWorldTransform()) | ||
* model->baseInertiaToLinkFrame; | ||
data.pose = convert(model->body->getBaseWorldTransform()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we have to account for
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line computes the pose for the model. The next 2 lines takes into account the pose of the link (and inertia offset if any) which uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expanded test to cover both base and non-base links. 84054fa There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this test is not testing model frame semantics at all. Fortunately, we currently don't use it in gz-sim, but it would be good to fix (not in this PR). I've added a failing test in the |
||
if (!isModel) | ||
data.pose = data.pose * model->baseInertiaToLinkFrame; | ||
if (isCollision) | ||
azeey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data.pose = data.pose * collisionPoseOffset; | ||
data.linearVelocity = convert(model->body->getBaseVel()); | ||
data.angularVelocity = convert(model->body->getBaseOmega()); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.