Ask Your Question
2

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:

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 -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

Comments

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

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

Seen: 1,391 times

Last updated: Sep 16 '12