Reputation: 69
I ran the below code using rosrun command as a node but not running in a circle anymore. But there's no error in this function. How to solve this and ran in a circle and stop in initial position?
ROS : Melodic Ubuntu 18.04
#!/usr/bin/env python
import rospy
import rospkg
from geometry_msgs.msg import Twist
from turtlesim.msg import Pose
#defining variables
x = 0
y = 0
theta = 0.0
#main function
def pose_callback(msg):
global x, y, psi
x = msg.x
y = msg.y
psi = msg.theta
print(msg.theta)
if __name__=="__main__":
rospy.init_node('node_turtle_revolve', anonymous = True)
r = rospy.Rate(10)
velocity_publisher = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)
while not rospy.is_shutdown():
sub = rospy.Subscriber('/turtle1/pose', Pose, pose_callback)
vel_msg = Twist()
vel_msg.linear.x = 0.2
vel_msg.linear.x = 0.0
vel_msg.linear.x = 0.0
vel_msg.angular.x= 0.0
vel_msg.angular.y= 0.0
vel_msg.angular.z= 0.1
velocity_publisher.publish(vel_msg)
r.sleep
Upvotes: 0
Views: 2483
Reputation: 26
You should change msg as pose
def pose_callback(pose): global x, y, psi x = pose.x y = pose.y psi = msg.theta print(msg.theta) And you should write a if statement
Upvotes: 1