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

Getting joint state value given joint name in C++

asked 2012-09-16 09:08:58 -0600

aecins gravatar image

updated 2014-01-28 17:13:40 -0600

ngrennan gravatar image

Let's say the /joint_states topic published by joint_state_publisher has several joint states:

  seq: 2855
    secs: 1347822047
    nsecs: 978094100
  frame_id: ''
name: ['ptu_pan_joint', 'ptu_tilt_joint']
position: [-0.4972690939903259, -0.20195947587490082]
velocity: []
effort: []

I just want to know the position of 'ptu_pan_joint'. How can I get it in C++ code? For now I am using the following:

vector<string> joint_names = joint_state->name;
pan_position_ = joint_state->position[find (joint_names.begin(),joint_names.end(), string(PAN_JOINT)) - joint_names.begin()];

Is there a cleaner solution?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-09-16 21:45:34 -0600

Lorenz gravatar image

I don't think there is any cleaner solution for that. I would just not copy joint_state->name to a separate variable but would directly reference it or use a reference to avoid copying it. But that's really just a minor thing.

edit flag offensive delete link more


I see. Yes, copying to a variable is not necessary at all. Thanks for the info.

aecins gravatar image aecins  ( 2012-09-18 10:16:42 -0600 )edit

Question Tools


Asked: 2012-09-16 09:08:58 -0600

Seen: 2,017 times

Last updated: Sep 16 '12