Skip to content

Commit

Permalink
Kinematics features (#169)
Browse files Browse the repository at this point in the history
* Kinematic Features
Signed-off-by: Lobotuerk <jtlorente@ekumenlabs.com>
  • Loading branch information
Lobotuerk authored and Blast545 committed Feb 2, 2021
1 parent ef2812a commit b3f5c04
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
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);
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

0 comments on commit b3f5c04

Please sign in to comment.