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

Add offset to link and collision pose #79

Merged
merged 6 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions tpe/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ target_link_libraries(${tpelib_target}
PUBLIC
PRIVATE
ignition-common${IGN_COMMON_VER}::requested
ignition-math${IGN_MATH_VER}::eigen3
)
ign_build_tests(
TYPE UNIT_tpelib
Expand Down
24 changes: 24 additions & 0 deletions tpe/lib/src/Collision.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class ignition::physics::tpelib::CollisionPrivate
/// \brief Collision's geometry shape
public: std::shared_ptr<Shape> shape = nullptr;

/// \brief Relative transform to its parent entity
public: Eigen::Isometry3d tf = math::eigen3::convert(
math::Pose3d(0, 0, 0, 0, 0, 0));

/// \brief Collide bitmask
public: uint16_t collideBitmask = 0xFF;
};
Expand Down Expand Up @@ -124,3 +128,23 @@ uint16_t Collision::GetCollideBitmask() const
{
return this->dataPtr->collideBitmask;
}

//////////////////////////////////////////////////
void Collision::UpdatePose(const math::Pose3d _linkPose)
{
math::Pose3d nextPose = math::eigen3::convert(
math::eigen3::convert(_linkPose) * this->dataPtr->tf);
this->SetPose(nextPose);
}

//////////////////////////////////////////////////
const Eigen::Isometry3d Collision::GetTf()
{
return this->dataPtr->tf;
}

//////////////////////////////////////////////////
void Collision::SetTf(const Eigen::Isometry3d _tf)
{
this->dataPtr->tf = _tf;
}
14 changes: 13 additions & 1 deletion tpe/lib/src/Collision.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#ifndef IGNITION_PHYSICS_TPE_LIB_SRC_COLLISION_HH_
#define IGNITION_PHYSICS_TPE_LIB_SRC_COLLISION_HH_

#include <ignition/math/AxisAlignedBox.hh>
#include <ignition/math/eigen3/Conversions.hh>
claireyywang marked this conversation as resolved.
Show resolved Hide resolved

#include "ignition/physics/tpelib/Export.hh"

Expand Down Expand Up @@ -72,6 +72,18 @@ class IGNITION_PHYSICS_TPELIB_VISIBLE Collision : public Entity
// Documentation inherited
public: math::AxisAlignedBox GetBoundingBox(bool _force) override;

/// \brief Update the pose of the entity
/// \param[in] _linkPose parent link pose
public: void UpdatePose(const math::Pose3d _linkPose);

/// \brief Get the relative transform to its parent link
/// \return relative transform
public: const Eigen::Isometry3d GetTf();

/// \brief Set the relative transform to its parent link
/// \param[in] _tf relative transform
public: void SetTf(const Eigen::Isometry3d _tf);

/// \brief Private data pointer class
private: CollisionPrivate *dataPtr = nullptr;
};
Expand Down
9 changes: 9 additions & 0 deletions tpe/lib/src/Collision_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ TEST(Collision, BasicAPI)
collision.SetPose(math::Pose3d(1, 2, 3, 0.1, 0.2, 0.3));
EXPECT_EQ(math::Pose3d(1, 2, 3, 0.1, 0.2, 0.3), collision.GetPose());

collision.SetTf(
math::eigen3::convert(math::Pose3d(0, 1.5, 0, 0, 0, 0)));
EXPECT_EQ(math::Pose3d(0, 1.5, 0, 0, 0, 0),
math::eigen3::convert(collision.GetTf()));

auto linkPose = math::Pose3d(1, 0, 0, 0, 0, 0);
collision.UpdatePose(linkPose);
EXPECT_EQ(math::Pose3d(1, 1.5, 0, 0, 0, 0), collision.GetPose());

EXPECT_EQ(0xFF, collision.GetCollideBitmask());
collision.SetCollideBitmask(0x03);
EXPECT_EQ(0x03, collision.GetCollideBitmask());
Expand Down
20 changes: 20 additions & 0 deletions tpe/lib/src/Link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,23 @@ Entity &Link::AddCollision()
this->ChildrenChanged();
return *it->second.get();
}

//////////////////////////////////////////////////
void Link::UpdatePose(const math::Pose3d _modelPose)
{
math::Pose3d nextPose = math::eigen3::convert(
math::eigen3::convert(_modelPose) * this->tf);
this->SetPose(nextPose);
}

//////////////////////////////////////////////////
const Eigen::Isometry3d Link::GetTf()
{
return this->tf;
}

//////////////////////////////////////////////////
void Link::SetTf(const Eigen::Isometry3d _tf)
{
this->tf = _tf;
}
18 changes: 18 additions & 0 deletions tpe/lib/src/Link.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef IGNITION_PHYSICS_TPE_LIB_SRC_LINK_HH_
#define IGNITION_PHYSICS_TPE_LIB_SRC_LINK_HH_

#include <ignition/math/eigen3/Conversions.hh>
claireyywang marked this conversation as resolved.
Show resolved Hide resolved

#include "ignition/physics/tpelib/Export.hh"

#include "Entity.hh"
Expand All @@ -42,6 +44,22 @@ class IGNITION_PHYSICS_TPELIB_VISIBLE Link : public Entity
/// \brief Add a collision
/// \return Newly created Collision
public: Entity &AddCollision();

/// \brief Update the pose of the entity
/// \param[in] _modelPose parent model pose
public: void UpdatePose(const math::Pose3d _modelPose);

/// \brief Get the relative transform to its parent model
/// \return relative transform
public: const Eigen::Isometry3d GetTf();

/// \brief Set the relative transform to its parent model
/// \param[in] _tf relative transform
public: void SetTf(const Eigen::Isometry3d _tf);

/// \brief Private relative transform to its parent entity
public: Eigen::Isometry3d tf =
claireyywang marked this conversation as resolved.
Show resolved Hide resolved
math::eigen3::convert(math::Pose3d(0, 0, 0, 0, 0, 0));
};

}
Expand Down
10 changes: 10 additions & 0 deletions tpe/lib/src/Link_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ TEST(Link, BasicAPI)
link.SetPose(math::Pose3d(1, 2, 3, 0.1, 0.2, 0.3));
EXPECT_EQ(math::Pose3d(1, 2, 3, 0.1, 0.2, 0.3), link.GetPose());

link.SetTf(math::eigen3::convert(
math::Pose3d(0, 0.2, 0.5, 0, 1, 0)));
EXPECT_EQ(math::Pose3d(0, 0.2, 0.5, 0, 1, 0),
math::eigen3::convert(link.GetTf()));

auto modelPose = math::Pose3d(10, 0, 2, 1, 0, 0);
link.UpdatePose(modelPose);
EXPECT_EQ(math::Pose3d(10, -0.312675, 2.43845, 1.23686, 0.471978, 0.918989),
link.GetPose());

Link link2;
EXPECT_NE(link.GetId(), link2.GetId());
}
Expand Down
9 changes: 9 additions & 0 deletions tpe/lib/src/Model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@ void Model::UpdatePose(
currentPose.Pos() + _linearVelocity * _timeStep,
currentPose.Rot().Integrate(_angularVelocity, _timeStep));
this->SetPose(nextPose);

// update link poses
auto &children = this->GetChildren();
for (auto it = children.begin(); it != children.end(); ++it)
{
std::shared_ptr<Link> link =
std::dynamic_pointer_cast<Link>(it->second);
link->UpdatePose(this->GetPose());
}
}