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

Getting joint state value given joint name in C++

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

aecins gravatar image

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

ngrennan gravatar image

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

header: 
  seq: 2855
  stamp: 
    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
2

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

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

Comments

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

Question Tools

Stats

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

Seen: 2,076 times

Last updated: Sep 16 '12