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 method to environment to get relative link transform #721

Merged
merged 1 commit into from
Mar 3, 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
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@ class Environment
*/
Eigen::Isometry3d getLinkTransform(const std::string& link_name) const;

/**
* @brief Get transform between two links using the current state
* @param from_link_name The link name the transform should be relative to
* @param to_link_name The link name to get transform
* @return The relative transform = inv(Transform(from_link_name)) * Transform(to_link_name)
*/
Eigen::Isometry3d getRelativeLinkTransform(const std::string& from_link_name, const std::string& to_link_name) const;

/**
* @brief Returns a clone of the environments state solver
*
Expand Down
7 changes: 7 additions & 0 deletions tesseract_environment/src/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,13 @@ Eigen::Isometry3d Environment::getLinkTransform(const std::string& link_name) co
return current_state_.link_transforms.at(link_name);
}

Eigen::Isometry3d Environment::getRelativeLinkTransform(const std::string& from_link_name,
const std::string& to_link_name) const
{
std::shared_lock<std::shared_mutex> lock(mutex_);
return current_state_.link_transforms.at(from_link_name).inverse() * current_state_.link_transforms.at(to_link_name);
}

tesseract_scene_graph::StateSolver::UPtr Environment::getStateSolver() const
{
std::shared_lock<std::shared_mutex> lock(mutex_);
Expand Down
13 changes: 13 additions & 0 deletions tesseract_environment/test/tesseract_environment_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ void runGetLinkTransformsTest(Environment& env)
env_state.link_transforms.at(link_names.at(i)).isApprox(env.getLinkTransform(link_names.at(i)), 1e-6));
}
}

// Check relative link transform
std::vector<std::string> link_names = env.getLinkNames();
SceneState env_state = env.getState();
for (const auto& link1 : link_names)
{
for (const auto& link2 : link_names)
{
Eigen::Isometry3d t1 = env_state.link_transforms.at(link1).inverse() * env_state.link_transforms.at(link2);
Eigen::Isometry3d t2 = env.getRelativeLinkTransform(link1, link2);
EXPECT_TRUE(t1.isApprox(t2, 1e-6));
}
}
}

enum class EnvironmentInitType
Expand Down