Robotics StackExchange | Archived questions

no response when roslaunch with python package

Hi I am running Kinetic in Ubuntu 16.04LTS.

In terminal, I run rostopic, the robot response.

rostopic pub /movej_cmd std_msgs/Float32MultiArray "layout:

dim:

- label: ''
size: 0
stride: 0
data_offset: 0
data: [0.402883, 0.001026, 0.00034, 0.000103, 0.00051, 0.001082]" 

But when I run roslaunch with the launch file below, robot does not response.

<launch>
    <node name="talker" pkg="test" type="write_joint.py" output="screen" />
</launch> 

This is my python file.

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

def talker():
    move = Float32MultiArray()
    move.layout.dim.append(MultiArrayDimension())
    move.layout.dim[0].label = ''
    move.layout.dim[0].size = 0
    move.layout.dim[0].stride = 0
    move.layout.data_offset = 0
    move.data = [0.402883,0.001026,0.000340,0.000103,0.000510,0.001082]
    pub = rospy.Publisher('talker', Float32MultiArray, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(1) # 1hz
    while not rospy.is_shutdown():
        #hello_str = "Write to robot\n%s\n" % move
        #rospy.loginfo(hello_str)
    print move
        pub.publish(move)
        rate.sleep()

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass

Can anyone advise why I can run rostopic but it does not work with roslaunch?

Gary

Asked by gary on 2017-09-19 01:29:40 UTC

Comments

Answers