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

Fix bullet double to float conversion compiler warnings #503

Merged
merged 14 commits into from
Apr 12, 2023
Merged
39 changes: 25 additions & 14 deletions bullet-featherstone/src/Base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ struct WorldInfo
std::unique_ptr<btMultiBodyConstraintSolver> solver;
std::unique_ptr<btMultiBodyDynamicsWorld> world;

std::unordered_map<std::size_t, std::size_t> modelIndexToEntityId;
std::unordered_map<int, std::size_t> modelIndexToEntityId;
std::unordered_map<std::string, std::size_t> modelNameToEntityId;
std::size_t nextModelIndex = 0;
int nextModelIndex = 0;

explicit WorldInfo(std::string name);
};
Expand All @@ -80,7 +80,7 @@ struct ModelInfo
{
std::string name;
Identity world;
std::size_t indexInWorld;
int indexInWorld;
Eigen::Isometry3d baseInertiaToLinkFrame;
std::unique_ptr<btMultiBody> body;

Expand Down Expand Up @@ -112,7 +112,7 @@ struct ModelInfo
struct LinkInfo
{
std::string name;
std::optional<std::size_t> indexInModel;
std::optional<int> indexInModel;
Identity model;
Eigen::Isometry3d inertiaToLinkFrame;
std::unique_ptr<btMultiBodyLinkCollider> collider = nullptr;
Expand All @@ -127,12 +127,12 @@ struct CollisionInfo
std::unique_ptr<btCollisionShape> collider;
Identity link;
Eigen::Isometry3d linkToCollision;
std::size_t indexInLink = 0;
int indexInLink = 0;
};

struct InternalJoint
{
std::size_t indexInBtModel;
int indexInBtModel;
};

struct RootJoint {};
Expand Down Expand Up @@ -165,21 +165,31 @@ struct JointInfo
// This field gets set by AddJoint
std::size_t indexInGzModel = 0;
btMultiBodyJointMotor* motor = nullptr;
double effort = 0;
btScalar effort = 0;

std::shared_ptr<btMultiBodyFixedConstraint> fixedContraint = nullptr;
};

inline btMatrix3x3 convertMat(const Eigen::Matrix3d& mat)
{
return btMatrix3x3(mat(0, 0), mat(0, 1), mat(0, 2),
mat(1, 0), mat(1, 1), mat(1, 2),
mat(2, 0), mat(2, 1), mat(2, 2));
return btMatrix3x3(
static_cast<btScalar>(mat(0, 0)), static_cast<btScalar>(mat(0, 1)),
static_cast<btScalar>(mat(0, 2)), static_cast<btScalar>(mat(1, 0)),
static_cast<btScalar>(mat(1, 1)), static_cast<btScalar>(mat(1, 2)),
static_cast<btScalar>(mat(2, 0)), static_cast<btScalar>(mat(2, 1)),
static_cast<btScalar>(mat(2, 2)));
}

inline btVector3 convertVec(const Eigen::Vector3d& vec)
{
return btVector3(vec(0), vec(1), vec(2));
return btVector3(static_cast<btScalar>(vec(0)), static_cast<btScalar>(vec(1)),
static_cast<btScalar>(vec(2)));
}

inline btVector3 convertVec(const math::Vector3d& vec)
{
return btVector3(static_cast<btScalar>(vec[0]), static_cast<btScalar>(vec[1]),
static_cast<btScalar>(vec[2]));
}

inline btTransform convertTf(const Eigen::Isometry3d& tf)
Expand Down Expand Up @@ -215,7 +225,7 @@ inline Eigen::Isometry3d convert(const btTransform& tf)

inline btTransform GetWorldTransformOfLinkInertiaFrame(
const btMultiBody &body,
const std::size_t linkIndexInModel)
const int linkIndexInModel)
{
const auto p = body.localPosToWorld(
linkIndexInModel, btVector3(0, 0, 0));
Expand Down Expand Up @@ -292,7 +302,8 @@ class Base : public Implements3d<FeatureList<Feature>>
if (link->indexInModel.has_value())
{
// We expect the links to be added in order
assert(*link->indexInModel+1 == model->linkEntityIds.size());
assert(static_cast<std::size_t>(*link->indexInModel + 1) ==
model->linkEntityIds.size());
}
else
{
Expand All @@ -312,7 +323,7 @@ class Base : public Implements3d<FeatureList<Feature>>
auto collision = std::make_shared<CollisionInfo>(std::move(_collisionInfo));
this->collisions[id] = collision;
auto *link = this->ReferenceInterface<LinkInfo>(_collisionInfo.link);
collision->indexInLink = link->collisionEntityIds.size();
collision->indexInLink = static_cast<int>(link->collisionEntityIds.size());
link->collisionEntityIds.push_back(id);
link->collisionNameToEntityId[collision->name] = id;

Expand Down
13 changes: 8 additions & 5 deletions bullet-featherstone/src/EntityManagementFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ std::size_t EntityManagementFeatures::GetLinkIndex(
// the rest up by one when providing an index to gazebo
const auto index = this->ReferenceInterface<LinkInfo>(_linkID)->indexInModel;
if (index.has_value())
return *index+1;
return static_cast<std::size_t>(*index+1);

return 0;
}
Expand Down Expand Up @@ -183,7 +183,8 @@ const std::string &EntityManagementFeatures::GetShapeName(
std::size_t EntityManagementFeatures::GetShapeIndex(
const Identity &_shapeID) const
{
return this->ReferenceInterface<CollisionInfo>(_shapeID)->indexInLink;
return static_cast<std::size_t>(
this->ReferenceInterface<CollisionInfo>(_shapeID)->indexInLink);
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -259,7 +260,8 @@ bool EntityManagementFeatures::RemoveModelByIndex(
const Identity & _worldID, std::size_t _modelIndex)
{
auto *world = this->ReferenceInterface<WorldInfo>(_worldID);
const auto it = world->modelIndexToEntityId.find(_modelIndex);
const auto it =
world->modelIndexToEntityId.find(static_cast<int>(_modelIndex));
if (it == world->modelIndexToEntityId.end())
return false;

Expand Down Expand Up @@ -367,7 +369,8 @@ Identity EntityManagementFeatures::GetModel(
const Identity &_worldID, std::size_t _modelIndex) const
{
const auto *world = this->ReferenceInterface<WorldInfo>(_worldID);
const auto it = world->modelIndexToEntityId.find(_modelIndex);
const auto it =
world->modelIndexToEntityId.find(static_cast<int>(_modelIndex));
if (it == world->modelIndexToEntityId.end())
return this->GenerateInvalidId();

Expand Down Expand Up @@ -401,7 +404,7 @@ std::size_t EntityManagementFeatures::GetModelIndex(
// the rest up by one when providing an index to gazebo
const auto index = this->ReferenceInterface<ModelInfo>(
_modelID)->indexInWorld;
return index+1;
return static_cast<std::size_t>(index + 1);
}

/////////////////////////////////////////////////
Expand Down
5 changes: 4 additions & 1 deletion bullet-featherstone/src/FreeGroupFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ void FreeGroupFeatures::SetFreeGroupWorldAngularVelocity(
}

if (jointInfo->motor)
jointInfo->motor->setVelocityTarget(_angularVelocity[2]);
{
jointInfo->motor->setVelocityTarget(
static_cast<btScalar>(_angularVelocity[2]));
}
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions bullet-featherstone/src/JointFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void JointFeatures::SetJointPosition(
return;

const auto *model = this->ReferenceInterface<ModelInfo>(joint->model);
model->body->getJointPosMultiDof(identifier->indexInBtModel)[_dof] = _value;
model->body->getJointPosMultiDof(identifier->indexInBtModel)[_dof] =
static_cast<btScalar>(_value);
}

/////////////////////////////////////////////////
Expand All @@ -122,7 +123,8 @@ void JointFeatures::SetJointVelocity(
return;

const auto *model = this->ReferenceInterface<ModelInfo>(joint->model);
model->body->getJointVelMultiDof(identifier->indexInBtModel)[_dof] = _value;
model->body->getJointVelMultiDof(identifier->indexInBtModel)[_dof] =
static_cast<btScalar>(_value);
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -152,7 +154,7 @@ void JointFeatures::SetJointForce(

const auto *model = this->ReferenceInterface<ModelInfo>(joint->model);
model->body->getJointTorqueMultiDof(
identifier->indexInBtModel)[_dof] = _value;
identifier->indexInBtModel)[_dof] = static_cast<btScalar>(_value);
}

/////////////////////////////////////////////////
Expand All @@ -168,7 +170,8 @@ std::size_t JointFeatures::GetJointDegreesOfFreedom(const Identity &_id) const
}

const auto *model = this->ReferenceInterface<ModelInfo>(joint->model);
return model->body->getLink(identifier->indexInBtModel).m_dofCount;
return static_cast<std::size_t>(
model->body->getLink(identifier->indexInBtModel).m_dofCount);
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -291,7 +294,7 @@ void JointFeatures::SetJointVelocityCommand(
world->world->addMultiBodyConstraint(jointInfo->motor);
}

jointInfo->motor->setVelocityTarget(_value);
jointInfo->motor->setVelocityTarget(static_cast<btScalar>(_value));
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -363,10 +366,7 @@ void JointFeatures::SetJointTransformFromParent(
if (jointInfo->fixedContraint)
{
jointInfo->fixedContraint->setPivotInA(
btVector3(
_pose.translation()[0],
_pose.translation()[1],
_pose.translation()[2]));
convertVec(_pose.translation()));
}
}
} // namespace bullet_featherstone
Expand Down
2 changes: 1 addition & 1 deletion bullet-featherstone/src/LinkFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void LinkFeatures::AddLinkExternalTorqueInWorld(
auto *link = this->ReferenceInterface<LinkInfo>(_id);
auto *model = this->ReferenceInterface<ModelInfo>(link->model);

auto T = btVector3(_torque[0], _torque[1], _torque[2]);
const btVector3 T = convertVec(_torque);

if (link->indexInModel.has_value())
{
Expand Down
Loading