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

Seeing this:

rospy.init_node('ArmMovement')
pub1=rospy.Publisher("/rrbot/joint1_position_controller/command",Float64,,queue_size=10 )
rate = rospy.Rate(50)
ArmCor1= Float64()
ArmCor1.data=0
pub1.publish(ArmCor1)
rate.sleep()

It's likely that there simply isn't any chance for the Subscriber (on Gazebo's / ros_control's side) to actually receive the message. rate.sleep() is single-shot. There is no periodicity here, so after 1/50 seconds (ie: 20 milliseconds), your program terminates and the Publisher is destroyed with it.

In those 20 milliseconds, the Subscriber needs to become aware of your Publisher, register interest with the ROS master, request a subscription, set up the actual network connection, negotiate with the Publisher to see whether it can actually exchange messages, complete negotiation and only then can it receive the message.

Seeing this:

rospy.init_node('ArmMovement')
pub1=rospy.Publisher("/rrbot/joint1_position_controller/command",Float64,,queue_size=10 )
rate = rospy.Rate(50)
ArmCor1= Float64()
ArmCor1.data=0
pub1.publish(ArmCor1)
rate.sleep()

It's likely that there simply isn't any chance for the Subscriber (on Gazebo's / ros_control's side) to actually receive the message. rate.sleep() is single-shot. There is no periodicity here, so after 1/50 seconds (ie: 20 milliseconds), your program terminates and the Publisher is destroyed with it.

In those 20 milliseconds, the Subscriber needs to to:

  1. become aware of your Publisher,
  2. register interest with the ROS master, master
  3. request a subscription, subscription
  4. set up the actual network connection, connection
  5. negotiate with the Publisher to see whether it can actually exchange messages, messages
  6. complete negotiation negotiation, and only then
  7. can it receive the message.

    message

Just to see whether this is indeed the problem, at a rospy.sleep(5) after the pub1=rospy.Publisher(..) line.

If things start working, you'll want to either make your script periodic, or use a state-based approach (ie: check there are subscribers) with rospy.Publisher.get_num_connections().