Publish on different topics using the same

asked 2018-02-07 15:33:03 -0500

gcastillo gravatar image

updated 2018-02-07 17:14:17 -0500

jayess gravatar image

Hello, I have 12 different topics, which correspond to the state position of 12 different joints. I am trying to publish on the 12 different topics using only one publisher node. However, I can not find a way to do it using only one python file. I tried to initialize different nodes on the same python file and then publish the message after each node's initialization, but it did not work. Is there any way to do it?

This is the code I tried for two different topics.

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

rospy.init_node('joint_angle') 

pub = rospy.Publisher('/rrbot/joint1_position_controller/command', Float64, queue_size=10)

rate = rospy.Rate(0.5)        
rate.sleep()            

move = Float64()            
move.data = 0.5
pub.publish(move)

pub = rospy.Publisher('/rrbot/joint2_position_controller/command', Float64, queue_size=10)
rate.sleep()
pub.publish(move)

Thanks for your help.

edit retag flag offensive close merge delete

Comments

What does

did not work

mean? In reference to you trying to using the same node 12 different times.

jayess gravatar image jayess  ( 2018-02-07 17:25:19 -0500 )edit
1

I am trying to publish on the 12 different topics using only one publisher node.

why?

gvdhoorn gravatar image gvdhoorn  ( 2018-02-08 01:11:11 -0500 )edit