Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 99

PYTHON + ROS + V-REP

$
0
0
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

Viewing all articles
Browse latest Browse all 99

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>