ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
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.
2 | No.2 Revision |
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()