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

[bullet]: Fix how changed link poses are computed #460

Merged
merged 1 commit into from
Dec 8, 2022
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
3 changes: 3 additions & 0 deletions bullet-featherstone/src/SimulationFeatures.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <unordered_map>
#include <vector>

#include <gz/physics/CanWriteData.hh>
#include <gz/physics/ForwardStep.hh>
#include <gz/physics/GetContacts.hh>

Expand All @@ -36,6 +37,8 @@ struct SimulationFeatureList : gz::physics::FeatureList<
> { };

class SimulationFeatures :
public CanWriteExpectedData<SimulationFeatures,
Copy link
Contributor

@ahcorde ahcorde Dec 6, 2022

Choose a reason for hiding this comment

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

is this happenning in featherstone too ? I can reproduce the issue only with bullet, featherstone should be fine without this changes, is there any other reason to add this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is not happening on featherstone, but inheriting from CanWriteExpectedData adds a compile-time check that the class implements Write for the expected data type. It's not strictly necessary.

ExpectData<ChangedWorldPoses>>,
public virtual Base,
public virtual Implements3d<SimulationFeatureList>
{
Expand Down
20 changes: 20 additions & 0 deletions bullet/src/Base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ inline Eigen::Vector3d convert(btVector3 vec)
return val;
}

inline math::Vector3d convertToGz(const btVector3 &_vec)
{
return math::Vector3d(_vec[0], _vec[1], _vec[2]);
}

inline math::Quaterniond convertToGz(const btMatrix3x3 &_mat)
{
return math::Quaterniond(math::Matrix3d(_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]));
}

inline math::Pose3d convertToGz(const btTransform &_pose)
{
return math::Pose3d(convertToGz(_pose.getOrigin()),
convertToGz(_pose.getBasis()));
}


class Base : public Implements3d<FeatureList<Feature>>
{
public: std::size_t entityCount = 0;
Expand All @@ -156,6 +175,7 @@ class Base : public Implements3d<FeatureList<Feature>>
{
const auto id = this->GetNextEntity();
assert(id == 0);
(void)id;

return this->GenerateIdentity(0);
}
Expand Down
3 changes: 2 additions & 1 deletion bullet/src/SimulationFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ void SimulationFeatures::Write(ChangedWorldPoses &_changedPoses) const
if (info)
{
WorldPose wp;
wp.pose = info->pose;
wp.pose = convertToGz(info->link->getCenterOfMassTransform()) *
info->inertialPose.Inverse();
wp.body = id;

auto iter = this->prevLinkPoses.find(id);
Expand Down
3 changes: 3 additions & 0 deletions bullet/src/SimulationFeatures.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <unordered_map>
#include <vector>

#include <gz/physics/CanWriteData.hh>
#include <gz/physics/ForwardStep.hh>

#include "Base.hh"
Expand All @@ -34,6 +35,8 @@ struct SimulationFeatureList : gz::physics::FeatureList<
> { };

class SimulationFeatures :
public CanWriteExpectedData<SimulationFeatures,
ExpectData<ChangedWorldPoses>>,
public virtual Base,
public virtual Implements3d<SimulationFeatureList>
{
Expand Down