Hi I have got a problem with publish data. I want to publish msg.linear.x and msg.linear.y to V-REP via ROS.
When I write in terminal
rostopic pub -1 /cmd_vel geometry_msgs/Twist '{linear: {x: -3.0, y: -3.0}}'
Everything is ok, but I want to publish this from PYTHON.
My actually code is:
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
#added
from geometry_msgs.msg import Twist
def callback(data):
global msg
if data.data=="Unknown":
pub = rospy.Publisher('cmd_vel', Twist)
rospy.loginfo("Classifiers output: %s in unknown" % data.data)
msg.linear.x = 2
msg.linear.y = 2
msg.angular.z = 0
speed = 0.4
rospy.loginfo("checking for cmd" + str(msg.linear))
pub.publish(msg)
elif data.data=="Check":
rospy.loginfo("Classifiers output: %s in check" % data.data)
else:
rospy.loginfo("Classifiers output: %s and not unknown or check" % data.data)
def listener():
global msg
rospy.init_node('listener', anonymous=True)
msg = Twist()
rospy.Subscriber("ccc", String, callback)
rospy.spin()
if __name__ == '__main__':
listener()
I am newbie in Python. Above code, I found on the Internet, and I try to translate into my case. What I want to do? I want to have control model in V-REP, by ROS. I can control by terminal thanks for egzample:
rostopic pub -1 /cmd_vel geometry_msgs/Twist '{linear: {x: -3.0, y: -3.0}}'
but I want control this model via Python, but I dont know how to do this :/
Thanks for suggestion
Originally posted by aefka on ROS Answers with karma: 15 on 2018-01-05
Post score: 0
Original comments
Comment by jayess on 2018-01-05:
What is your question/problem? Is your code not working as expected?
Comment by aefka on 2018-01-05:
Yes :/
I want to publish msg.linear.x = 2 msg.linear.y = 2 from python. I am newbie in this language :/