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

Segfault whilst reading message

asked 2014-04-18 19:41:44 -0600

hjed gravatar image

updated 2016-10-24 09:03:32 -0600

ngrennan gravatar image

Hi we've been writting some code to subscribe to the /joint_states topic produced by the husky simulator. However we found that even though all the arrays in /joint_states should be the same length, we are getting an empty array for velocity at random intervals. Which causes a seg fault as there appears to be no way to detect it. (checking if msg->velocity == NULL won't compile). So two questions, is there a way to stop these invalid messages? And if there isn't what is the best way to detect the empty array (gdb says its a boost shared vector).

Thanks, Harry

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-04-18 21:21:52 -0600

The arrays of Float64 data in sensor_msgs/JointState are represented by a std::vector<double> when using roscpp. You should thus be able to get the length of the vector by calling YOUR_MSG.velocity.size().

The "velocity disappearance" issue sounds like a bug to me, but maybe some other husky user or dev can comment on that one.

edit flag offensive delete link more


Thanks, this is a very good fix for the problem

hjed gravatar image hjed  ( 2014-04-19 02:53:02 -0600 )edit

Question Tools

1 follower


Asked: 2014-04-18 19:41:44 -0600

Seen: 229 times

Last updated: Apr 18 '14