Ask Your Question
1

float64 and eigen

asked 2012-11-27 04:58:52 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi, I have a subsriber node that reads IMU measurements. For computational reasons I have to write the geometry_msgs/Vector3 angular_velocity into an eigen-library vector, any suggestions?

this is the code:

VectorXd imuData;
imuData(0) = msg->angular_velocity.x;

this is the error I get:

dede@ubuntu:~$ rosrun labrob_project my_subscriber 

(view:3495): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",

(view:3495): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",

(view:3495): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",

(view:3495): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",
my_subscriber: /usr/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h:407: Eigen::DenseCoeffsBase<Derived, 1>::Scalar& Eigen::DenseCoeffsBase<Derived, 1>::operator()(Eigen::DenseCoeffsBase<Derived, 1>::Index) [with Derived = Eigen::Matrix<double, -0x00000000000000001, 1>, Eigen::DenseCoeffsBase<Derived, 1>::Scalar = double, Eigen::DenseCoeffsBase<Derived, 1>::Index = long int]: Assertion `index >= 0 && index < size()' failed.
Aborted
edit retag flag offensive close merge delete

Comments

1

I don't really see what the problem is with that. Can you say why this should be problematic?

dornhege gravatar imagedornhege ( 2012-11-27 05:23:08 -0500 )edit

VectorXd imuData; imuData(0) = msg->angular_velocity.x; I have no problem in compiling this but at run time there's a typecast problem between float64 and double

schizzz8 gravatar imageschizzz8 ( 2012-11-28 01:24:32 -0500 )edit
1

float64 are doubles in ROS. This should work in principle. Please copy the exact error and the referred code in your post and have a look at the support guidelines: http://ros.org/wiki/Support.

dornhege gravatar imagedornhege ( 2012-11-28 04:25:38 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-11-28 07:59:10 -0500

Eric Perko gravatar image

The relevant bit of the assertion is Assertion index >= 0 && index < size()' failed.

Before you access an element of the VectorXd, you need to resize the VectorXd to be large enough. Another option, since you know the number of elements that you want from the angular velocity, is to use a fixed size vector such as Vector3d . That would not require a .resize() call and may be faster than the dynamically sized VectorXd.

Here's a snippet that reproduces your error:

#include <Eigen/Geometry>

int main(int argc, char** argv)
{

   Eigen::VectorXd vec;
   //vec.resize(1);
   vec(0) = 1.0;

   return 0;
}

Commenting in that vec.resize(1) allows it to compile and run fine.

edit flag offensive delete link more

Comments

thanks, it worked

schizzz8 gravatar imageschizzz8 ( 2012-11-28 19:16:20 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-11-27 04:58:52 -0500

Seen: 1,069 times

Last updated: Nov 28 '12