no response when roslaunch with python package

asked 2017-09-19 01:33:19 -0500

gary gravatar image

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

edit retag flag offensive close merge delete

Comments

Topic is incorrect, replace with below:

pub = rospy.Publisher('movej_cmd', Float32MultiArray, queue_size=10)
gary gravatar image gary  ( 2017-09-21 11:31:38 -0500 )edit

@gary: you can edit your original question, no need to post again. Just click the edit link/button below the question text.

gvdhoorn gravatar image gvdhoorn  ( 2017-09-23 16:19:15 -0500 )edit

Check if your robot is listening (subscribed) to the topic movej_cmd with rostopic info /movej_cmd

Also, try to add / when instantiating the publisher, using /movej_cmd instead of movej_cmd.

Ruben Alves gravatar image Ruben Alves  ( 2017-09-29 15:42:17 -0500 )edit