ros2 / ros2/geometry2

[tf_eigen] Usage of MatrixBase in functions to allow block operations

Open
#716 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
153
Forks
256
Avg merge
3d 23h
Merged PRs (30d)
14

Description

Feature request

Feature description

When trying to pass blocks of vectors to functions converting from message to Eigen I got an error:

error: cannot bind non-const lvalue reference of type

Following snippet reproduces this case.

geometry_msgs::msg::Wrench wrench_msg;
Eigen::Matrix<double, 6, 1> wrench_vect;

tf2::fromMsg(wrench_msg.force, wrench_vect.template head<3>());
tf2::fromMsg(wrench_msg.torque, wrench_vect.template tail<3>());
Implementation considerations

I am wondering if using templates to allow such operations makes any sense. Especially, that for function converting from geometry_msgs/Vector3 to Eigen::Vector3d implementing it, changes it from a simple function like this:

inline
void fromMsg(const geometry_msgs::msg::Vector3 & msg, Eigen::Vector3d & out)
{
  out.x() = msg.x;
  out.y() = msg.y;
  out.z() = msg.z;
}

to that monstrosity:

template <typename Derived> inline
void fromMsg(const geometry_msgs::msg::Vector3 & msg, Eigen::MatrixBase<Derived> const & out)
{
  assert(out.size() == 3 && "Passed Vector is not size of 3.");
  const_cast< Eigen::MatrixBase<Derived>& >(out)(0) = msg.x;
  const_cast< Eigen::MatrixBase<Derived>& >(out)(1) = msg.y;
  const_cast< Eigen::MatrixBase<Derived>& >(out)(2) = msg.z;
}

To my knowledge, this should be the way to baypass that issue. At least, the way I understood Eigen documentation.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing tf2::fromMsg overloads for geometry_msgs::msg::Vector3 and Eigen destinations. Reproduce the reported case with Matrix::head<3>() and Matrix::tail<3>(), then determine an API approach that supports these block expressions without breaking direct Eigen::Vector3d conversion. Done means the example compiles and coverage verifies both conversion forms.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.