ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Your publisher isn't waiting long enough for the topic to be connected before it sends a message; and if the subscriber isn't connected when you publish, it won't receive the message. This is a common mistake and there are many questions and answers about it; this one explains it in more detail: https://answers.ros.org/question/107521/when-is-it-safe-to-publish-after-declaring-a-rospypublisher/

In addition to the answers proposed on that question, you could call get_num_connections on your publisher until at least one subscriber is connected, before you publish:

pub = rospy.Publisher('/torso_arduino/motor_rotate', Int16, queue_size=1)
while pub.get_num_connections() == 0:
    rospy.loginfo("Waiting for subscriber to connect")
    rospy.sleep(1)
pub.publish(Int16(-45))

The rostopic command-line tool is also written using rospy, and is has a similar startup delay between the creation of the publisher and the first call to publish()