将乌龟绕圈移动并作为ros节点将其停在初始位置?

moving a turtle in a circle and stop it in the initial position as a ros node?

我 运行 下面的代码使用 rosrun 命令作为节点,但不再 运行 在一个圆圈中。但是这个函数没有错误。 如何解决这个和运行绕一圈停在初始位置?

ROS:旋律 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

你应该把 msg 改成 pose

def pose_callback(姿势): 全局 x、y、psi x = pose.x y = pose.y psi = msg.theta 打印(msg.theta) 你应该写一个if语句