0
$\begingroup$

Rosanswers logo

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


Originally posted by Robert1 on ROS Answers with karma: 63 on 2014-06-29

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Mehdi. with karma: 3339 on 2014-07-02

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.