Getting joint state value given joint name in C++
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?