Skip to content
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

Kinematics features #169

Merged
merged 2 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions bullet/src/KinematicsFeatures.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <ignition/common/Console.hh>
#include "KinematicsFeatures.hh"

namespace ignition {
namespace physics {
namespace bullet {

/////////////////////////////////////////////////
FrameData3d KinematicsFeatures::FrameDataRelativeToWorld(
const FrameID &_id) const
{
FrameData3d data;

// The feature system should never send us the world ID.
if (_id.IsWorld())
{
ignerr << "Given a FrameID belonging to the world. This should not be "
<< "possible! Please report this bug!\n";
assert(false);
return data;
}

const auto linkID = _id.ID();

if (this->links.find(linkID) == this->links.end())
{
ignerr << "Given a FrameID not belonging to a link.\n";
return data;
}
const auto &linkInfo = this->links.at(linkID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we will the _id, which is a FrameID as a replacement to query the linkIDs I think we should something to exit the function cleanly in the case this function receives a not valid linkID.

I won't block this PR on that, but you can add a comment about it here so we remember later.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added on 25225aa

const auto &model = linkInfo->link;

const btVector3 pos = model->getCenterOfMassTransform().getOrigin();
const btMatrix3x3 mat = model->getCenterOfMassTransform().getBasis();

auto eigenMat = convert(mat);
auto eigenVec = convert(pos);

data.pose.linear() = eigenMat;
data.pose.translation() = eigenVec;

// Add base velocities
btVector3 omega = model->getAngularVelocity();
btVector3 vel = model->getLinearVelocity();
// Transform to world frame
// const auto matBaseToWorld = btMatrix3x3(model->getWorldToBaseRot()).inverse();
// omega = matBaseToWorld * omega;
// vel = matBaseToWorld * vel;

data.linearVelocity = convert(vel);
data.angularVelocity = convert(omega);

// \todo(anyone) compute frame accelerations

return data;
}

}
}
}
28 changes: 28 additions & 0 deletions bullet/src/KinematicsFeatures.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef IGNITION_PHYSICS_BULLET_SRC_KINEMATICSFEATURES_HH_
#define IGNITION_PHYSICS_BULLET_SRC_KINEMATICSFEATURES_HH_

#include <ignition/physics/FrameSemantics.hh>
#include <ignition/physics/FreeGroup.hh>

#include "Base.hh"

namespace ignition {
namespace physics {
namespace bullet {

using KinematicsFeatureList = FeatureList<
LinkFrameSemantics
>;

class KinematicsFeatures :
public virtual Base,
public virtual Implements3d<KinematicsFeatureList>
{
public: FrameData3d FrameDataRelativeToWorld(const FrameID &_id) const;
};

}
}
}

#endif
3 changes: 3 additions & 0 deletions bullet/src/plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "EntityManagementFeatures.hh"
#include "SimulationFeatures.hh"
#include "SDFFeatures.hh"
#include "KinematicsFeatures.hh"

namespace ignition {
namespace physics {
Expand All @@ -32,6 +33,7 @@ namespace bullet {
struct BulletFeatures : FeatureList <
EntityManagementFeatureList,
SimulationFeatureList,
KinematicsFeatureList,
SDFFeatureList
> { };

Expand All @@ -40,6 +42,7 @@ class Plugin :
public virtual Base,
public virtual EntityManagementFeatures,
public virtual SimulationFeatures,
public virtual KinematicsFeatures,
public virtual SDFFeatures
{};

Expand Down