ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to use eigen::matrix3f as additional argument in callback functions?

asked 2014-01-25 14:43:06 -0500

ZiyangLI gravatar image

updated 2014-01-25 15:05:11 -0500

Dear all,

I would like to use eigen::matrix3f as additional argument in callback functions.

I define the matrix

    Eigen::Matrix3f R_bc;
R_bc << 0, -1,  0,
        1,  0,  0,
        0,  0,  1;

and the subsriber

ros::Subscriber sub = nh.subscribe<nav_msgs::Odometry>( "c_pose", 10, boost::bind(poseCallback, _1, &R_bc) );

and the callback function

void poseCallback(const nav_msgs::Odometry::ConstPtr& msg, const Eigen::Matrix3f* R_bc)

Is it correct? And how can I refer to the elements of R_bc in the callback function? Like print them with ROS_INFO?

What is if define a matrix array like R_bc[10], then how can I pass it to the callback function?

edit retag flag offensive close merge delete

Comments

I gave up feeding R_bc to boost in the end. I define it as a global variable. It is not as good but it works.

ZiyangLI gravatar image ZiyangLI  ( 2014-01-28 19:44:32 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-01-27 00:57:40 -0500

Wolf gravatar image

Your code seems correct, as long as the life time of your R_bc Matrix is longer than the life time of your node.

To clarify this: if your create the R_bc as local object in a small function and take the take its ref and than leave the function your R_bc will get destructed as you leave the function. If your subscriber later on calls the function with the pointer pointing the destructed object, this will cause segfault. But if you create your R_bc as global object or in your main any its life time is longer than ros::ok() this should work.

However, you might also consider putting your R_bc in a class along with your subscriber, see [http://answers.ros.org/question/121831/boostbind-errors-in-subscriber-callback-functions/]

edit flag offensive delete link more

Comments

Hi Wolf, thank you for your reply. I would also like to know how to print a matrix in ROS. Should we access the elements one by one?

ZiyangLI gravatar image ZiyangLI  ( 2014-01-28 19:39:28 -0500 )edit

I am not sure (not so familiar with eigen) but looking at your code, it looks like Eigen matrices implement << operators. If so you should just be able to use ROS_INFO_STREAM. Try: ROS_INFO_STREAM( "R_bc values: " << R_bc );

Wolf gravatar image Wolf  ( 2014-01-28 19:50:04 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-01-25 14:43:06 -0500

Seen: 560 times

Last updated: Jan 27 '14