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

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

Open
Kotochleb opened this issue Oct 16, 2024 · 0 comments
Open

Comments

@Kotochleb
Copy link

Kotochleb commented Oct 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant