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

sensor_msgs/JointState in cpp

asked 2014-01-31 06:22:17 -0600

tuuzdu gravatar image

When I try set sensor_msgs/JointState and publish it

ros::Publisher joint_msg_pub = node.advertise<sensor_msgs::jointstate>("leg_joints_states", 1);
sensor_msgs::JointState joint_msg;[0] = "coxa_joint_r1";
joint_msg.position[0] = q_out(0);

But when I launch node I get segmentation fault. I incorrectly set the value in the message? </sensor_msgs::jointstate>

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-01-31 06:26:19 -0600

dornhege gravatar image
  1. This code example won't compile.

  2. You are setting the first elements of the vectors, but there are 0 elements in a new message that you create. Use .push_back instead of setting the values to add new values.

edit flag offensive delete link more


1. Yes, I cut a lot of code :) 2. Thank you! .push_back is solution of the problem

tuuzdu gravatar image tuuzdu  ( 2014-01-31 06:59:46 -0600 )edit

could you post the corrected code. please

ghanta1996 gravatar image ghanta1996  ( 2017-04-02 05:27:35 -0600 )edit

Question Tools

1 follower


Asked: 2014-01-31 06:22:17 -0600

Seen: 4,419 times

Last updated: Jan 31 '14