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

sensor_msgs/JointState in cpp

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

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;
joint_msg.name[0] = "coxa_joint_r1";
joint_msg.position[0] = q_out(0);
joint_msg_pub.publish(joint_msg);

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
1

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

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

Comments

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 -0500 )edit

could you post the corrected code. please

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

Question Tools

1 follower

Stats

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

Seen: 4,472 times

Last updated: Jan 31 '14