Ask Your Question

float64 and eigen

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

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.
edit retag flag offensive close merge delete



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

dornhege gravatar image dornhege  ( 2012-11-27 05:23:08 -0600 )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 image schizzz8  ( 2012-11-28 01:24:32 -0600 )edit

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:

dornhege gravatar image dornhege  ( 2012-11-28 04:25:38 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

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

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(0) = 1.0;

   return 0;

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

edit flag offensive delete link more


thanks, it worked

schizzz8 gravatar image schizzz8  ( 2012-11-28 19:16:20 -0600 )edit

Hi I have a similar problem but I can't understand why imy code is not working. I think the problem is in this chunck of code. what do you think?

Eigen::VectorXd x_hat(n);

double attitude = x_hat(4); t += dt; F << 1,0, dtcos(attitude), dt(-sin(attitude)), 0, 1, dt*sin(attitude),dt *cos(attitude), 0, 0, 1, 0, 0,0,0,1; L<< 0,0, 0,0, dt,0, 0,dt;

v.leto gravatar image v.leto  ( 2020-01-15 11:18:01 -0600 )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


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

Seen: 1,311 times

Last updated: Nov 28 '12