Ask Your Question
0

how can i write a node to subscribe to the “joint 0”?

asked 2017-04-27 07:28:26 -0500

buaawanggg gravatar image

I used a 6-DOF Arms of a Mobile Robot
in the topic "joint_state" three are messages of joint0 joint1 joint2.。。。joint6 how can I write a node subscribe to joint 0; only “ joint 0”

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-04-27 09:44:43 -0500

updated 2017-04-27 11:06:59 -0500

You have a single topic called /joint_states that has, presumbably, sensor_msgs/JointState messages being published on it. I'm unsure if you are trying to say that a single message published on the topic contains information on all 6 joints (i.e. the name field would have 6 entries in it, which is pretty common), or if you are saying that every 6th message published on the topic is for joint0. Either way, as far as I know, it is not possible to filter topics at the subscriber level like you are interested in doing. I can think of two easy ways of working around this: (i) pulling out just the information for joint0 in your callback (if there is no joint0 info, just exit the callback), or (ii) writing an intermediate node that subscribes to /joint_states, filters out the joint0 information, and then publishes just that info on a separate topic.

EDIT

Here's a simple example in Python to illustrate the concept:

#!/usr/bin/env python
import rospy
from sensor_msgs.msg import JointState
from std_msgs.msg import Float64

def joint_states_callback(message):
    # filter out joint0 position:
    for i,name in enumerate(message.name):
        if name == "joint0":
            pos = message.position[i]
            pub.publish(pos)
    return

if __name__ == '__main__':
    rospy.init_node("example_repub")
    pub = rospy.Publisher("joint0_topic", Float64, queue_size=1)
    rospy.Subscriber("joint_states", JointState, joint_states_callback, queue_size=1)
    rospy.spin()
edit flag offensive delete link more

Comments

sorry i am not quite understand what “every 6th message published on the topic is for joint0” mean but i think what i want to express one message contains information all 6 joints

buaawanggg gravatar imagebuaawanggg ( 2017-04-27 10:05:33 -0500 )edit

how i can write in a node to filters out the joint0 information ? only joint0,i want to only publish the position message of joint0 to another topic thx!

buaawanggg gravatar imagebuaawanggg ( 2017-04-27 10:06:06 -0500 )edit

I added a simple example. Hopefully that helps.

jarvisschultz gravatar imagejarvisschultz ( 2017-04-27 11:07:58 -0500 )edit

thx!!!!!!!

buaawanggg gravatar imagebuaawanggg ( 2017-04-27 11:13:06 -0500 )edit

thank you for your help! i try to write this with C++ but there are some questions ,can you give me some advice in my latest question,thx a lot!

buaawanggg gravatar imagebuaawanggg ( 2017-05-03 20:21:56 -0500 )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

2 followers

Stats

Asked: 2017-04-27 07:28:26 -0500

Seen: 108 times

Last updated: Apr 27 '17