-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bullet] Bullet classic, Add sdf entities (#167)
* Add SDF features to build models * Fix class inheritance problem * Comment unused variables in this commit * Add vector with ids of links added in a model Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
- Loading branch information
Showing
5 changed files
with
149 additions
and
17 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "SDFFeatures.hh" | ||
#include <ignition/math/eigen3/Conversions.hh> | ||
|
||
namespace ignition { | ||
namespace physics { | ||
namespace bullet { | ||
|
||
///////////////////////////////////////////////// | ||
Identity SDFFeatures::ConstructSdfWorld( | ||
const Identity &_engine, | ||
const ::sdf::World &_sdfWorld) | ||
{ | ||
const Identity worldID = this->ConstructEmptyWorld(_engine, _sdfWorld.Name()); | ||
|
||
const WorldInfoPtr &worldInfo = this->worlds.at(worldID); | ||
|
||
auto gravity = _sdfWorld.Gravity(); | ||
worldInfo->world->setGravity(btVector3(gravity[0], gravity[1], gravity[2])); | ||
return worldID; | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
Identity SDFFeatures::ConstructSdfModel( | ||
const Identity &_worldID, | ||
const ::sdf::Model &_sdfModel) | ||
{ | ||
// Read sdf params | ||
const std::string name = _sdfModel.Name(); | ||
const auto pose = _sdfModel.RawPose(); | ||
// const bool isStatic = _sdfModel.Static(); | ||
// const bool selfCollide = _sdfModel.SelfCollide(); | ||
|
||
// const auto &world = this->worlds.at(_worldID)->world; | ||
const auto modelIdentity = this->AddModel({name, _worldID}); | ||
|
||
// Build links | ||
for (std::size_t i = 0; i < _sdfModel.LinkCount(); ++i) | ||
{ | ||
this->ConstructSdfLink(modelIdentity, *_sdfModel.LinkByIndex(i)); | ||
} | ||
|
||
return modelIdentity; | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
Identity SDFFeatures::ConstructSdfLink( | ||
const Identity &_modelID, | ||
const ::sdf::Link &_sdfLink) | ||
{ | ||
// Read sdf params | ||
const std::string name = _sdfLink.Name(); | ||
const auto pose = _sdfLink.RawPose(); | ||
const auto inertial = _sdfLink.Inertial(); | ||
const auto mass = inertial.MassMatrix().Mass(); | ||
const auto diagonalMoments = inertial.MassMatrix().DiagonalMoments(); | ||
|
||
// Get link properties | ||
// const btScalar linkMass = mass; | ||
const btVector3 linkInertiaDiag = | ||
convertVec(ignition::math::eigen3::convert(diagonalMoments)); | ||
|
||
// (TO-DO: do those calculation need to take into account in some way the base model?) | ||
const auto poseIsometry = ignition::math::eigen3::convert(pose); | ||
const auto poseTranslation = poseIsometry.translation(); | ||
const auto poseLinear = poseIsometry.linear(); | ||
btTransform baseTransform; | ||
baseTransform.setOrigin(convertVec(poseTranslation)); | ||
baseTransform.setBasis(convertMat(poseLinear)); | ||
|
||
// Create link | ||
// (TO-DO: do we want to use MotionState?) | ||
// First zero is motionState, the second one is the colision shape | ||
btRigidBody* body = new btRigidBody(mass, 0, 0, linkInertiaDiag); | ||
body->setWorldTransform(baseTransform); | ||
|
||
// Add it to the internal world: | ||
const auto _worldID = this->models.at(_modelID)->world; | ||
const auto &world = this->worlds.at(_worldID)->world; | ||
world->addRigidBody(body); | ||
|
||
// Generate an identity for it | ||
const auto linkIdentity = this->AddLink({name, body, _modelID}); | ||
|
||
return linkIdentity; | ||
} | ||
|
||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
#ifndef IGNITION_PHYSICS_BULLET_SRC_SDFFEATURES_HH_ | ||
#define IGNITION_PHYSICS_BULLET_SRC_SDFFEATURES_HH_ | ||
|
||
#include <ignition/physics/sdf/ConstructLink.hh> | ||
#include <ignition/physics/sdf/ConstructModel.hh> | ||
#include <ignition/physics/sdf/ConstructWorld.hh> | ||
|
||
#include <ignition/physics/Implements.hh> | ||
|
||
#include "EntityManagementFeatures.hh" | ||
|
||
namespace ignition { | ||
namespace physics { | ||
namespace bullet { | ||
|
||
using SDFFeatureList = FeatureList< | ||
sdf::ConstructSdfLink, | ||
sdf::ConstructSdfModel, | ||
sdf::ConstructSdfWorld | ||
>; | ||
|
||
class SDFFeatures : | ||
public virtual EntityManagementFeatures, | ||
public virtual Implements3d<SDFFeatureList> | ||
{ | ||
public: Identity ConstructSdfWorld( | ||
const Identity &/*_engine*/, | ||
const ::sdf::World &_sdfWorld) override; | ||
|
||
public: Identity ConstructSdfModel( | ||
const Identity &_worldID, | ||
const ::sdf::Model &_sdfModel) override; | ||
|
||
private: Identity ConstructSdfLink( | ||
const Identity &_modelID, | ||
const ::sdf::Link &_sdfLink) override; | ||
}; | ||
|
||
} | ||
} | ||
} | ||
|
||
#endif |
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