Skip to content

Commit

Permalink
Kinematic Features
Browse files Browse the repository at this point in the history
Signed-off-by: Lobotuerk <[email protected]>
  • Loading branch information
Lobotuerk committed Nov 24, 2020
1 parent 810f9d9 commit b71e7c5
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
98 changes: 98 additions & 0 deletions bullet/src/KinematicsFeatures.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#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();
const auto &linkInfo = this->links.at(linkID);
const auto modelIdentity = linkInfo->model;
// auto linkIndex = linkInfo->linkIndex;
const auto &modelInfo = this->models.at(modelIdentity);
const auto &model = modelInfo->model;

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;

// Get frame velocities
// Note: only support revolute/fixed joints
// btVector3 vel = btVector3(0, 0, 0);
// btVector3 omega = btVector3(0, 0, 0);
// btMatrix3x3 matChildToThis = btMatrix3x3().getIdentity();
// btVector3 rThisToChild = btVector3(0, 0, 0);

// TODO(lobotuerk) uncomment once we support joints
// while (linkIndex != -1)
// {
// const auto &link = model->getLink(linkIndex);
// btScalar jointVel;
// if (link.m_jointType == btMultibodyLink::eFixed)
// jointVel = 0;
// else if (link.m_jointType == btMultibodyLink::eRevolute)
// jointVel = model->getJointVel(linkIndex);
// else
// {
// // ignerr << "Unregistered joint type for frame velocity computation.\n";
// return data;
// }
//
// // Get target link's velocities in current link frame
// omega += jointVel * link.getAxisTop(0);
// vel += jointVel * link.getAxisBottom(0) + omega.cross(
// matChildToThis * rThisToChild);
//
// // Express in parent frame
// const auto matThisToParent = btMatrix3x3(
// link.m_cachedRotParentToThis).inverse();
// omega = matThisToParent * omega;
// vel = matThisToParent * vel;
//
// // Info for next computation
// matChildToThis = matThisToParent;
// rThisToChild = link.m_cachedRVector;
//
// // Move on to parent
// linkIndex = link.m_parent;
// }

// 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 @@ -23,20 +23,23 @@
#include "Base.hh"
#include "EntityManagementFeatures.hh"
#include "SimulationFeatures.hh"
#include "KinematicsFeatures.hh"

namespace ignition {
namespace physics {
namespace bullet {

struct BulletFeatures : FeatureList <
EntityManagementFeatureList,
KinematicsFeatureList,
SimulationFeatureList
> { };

class Plugin :
public virtual Implements3d<BulletFeatures>,
public virtual Base,
public virtual EntityManagementFeatures,
public virtual KinematicsFeatures,
public virtual SimulationFeatures {};

IGN_PHYSICS_ADD_PLUGIN(Plugin, FeaturePolicy3d, BulletFeatures)
Expand Down

0 comments on commit b71e7c5

Please sign in to comment.