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

rostopic pub python syntax error

asked 2014-06-29 00:26:47 -0500

Robert1 gravatar image

Hi All, I need to use the rostopic pub command in phyton shell script: In c++ the command is: rostopic pub -r 5 /uav1/sug_cmd_vel geometry_msgs/Twist -- '[0.0, 0.2, 0.0]' '[0.0, 0.0, 0.0]'

In python I entered like this: ['rostopic', 'pub', '-r 5', '/uav1/sug_cmd_vel', 'geometry_msgs/Twist', '--','['0.0, 0.2,0.0', '0.0,0.0,0.0']' Also, I tried several other combinations but still getting syntax error. Can anyone help with this issue?. Thanks a lot

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-07-02 21:38:44 -0500

Mehdi. gravatar image

If you are using python why do you want to use the following command?

rostopic pub -r 5 /uav1/sug_cmd_vel geometry_msgs/Twist -- '[0.0, 0.2, 0.0]' '[0.0, 0.0, 0.0]'

This command is meant to be used directly from the command line

You could just use rospy directly

import rospy
import roslib
roslib.load_manifest('your_package')
from geometry_msgs.msg import Twist
rospy.init_node('dummy')
# publish to cmd_vel
p = rospy.Publisher('/uav1/sug_cmd_vel', Twist)
# create a twist message, fill in the details
twist = Twist()
twist.linear.x =0.0;                 
twist.linear.y = 0.2; 
twist.linear.z = 0.0;   
twist.angular.x = 0; 
twist.angular.y = 0;  
twist.angular.z = 0; 
p.publish(twist)

don't forget to add geometry_msgs as dependency to your package in the manifest.xml.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-06-29 00:26:47 -0500

Seen: 1,604 times

Last updated: Jul 02 '14