这次吧draw a square直接贴过来改,看到里面好多Tab和空格混用,照着它的格式又写一遍TAT,这次干脆什么都没有出来……这个应该不是缩进的问题吧?draw a square我是能运行的,下面是我的代码:
# -*- coding: UTF-8 -*-
#!/usr/bin/env python
#前进1m,画边长( 0.5 )m的五边形
import rospy
from geometry_msgs.msg import Twist
from math import radians
class ROUTE():
def __init__(self):
# 初始化节点
rospy.init_node('route', anonymous=False)
# ctrl + c退出
rospy.on_shutdown(self.shutdown)
self.cmd_vel = rospy.Publisher('cmd_vel_mux/input/navi', Twist, queue_size=10)
# 5 HZ更新频率
r = rospy.Rate(5);
# 两个不同的Twist,转,直走
# 0.5 m/s 前进
move_cmd = Twist()
move_cmd.linear.x = 0.5
#旋转18 deg/s
turn_cmd = Twist()
turn_cmd.linear.x = 0
turn_cmd.angular.z = radians(18);
count = 0
# 前进1M
rospy.loginfo("前进ing")
for x in range(0,10):
self.cmd_vel.publish(move_cmd)
r.sleep()
while not rospy.is_shutdown():
#转54度
rospy.loginfo("转圈ing")
for x in range(0,15):
self.cmd_vel.publish(turn_cmd)
r.sleep()
# 前进0.5M
rospy.loginfo("前进ing")
for x in range(0,5):
self.cmd_vel.publish(move_cmd)
r.sleep()
# 转234度
rospy.loginfo("准备拍照ing")
for x in range(0,65):
self.cmd_vel.publish(turn_cmd)
r.sleep()
count = count + 1
if(count == 5):
count = 0
if(count == 0):
rospy.loginfo("是不是结束了?")
def shutdown(self):
# 停啦
rospy.loginfo("停啦~")
self.cmd_vel.publish(Twist())
rospy.sleep(1)
if __name__ == '__main__':
try:
DrawASquare()
except:
rospy.loginfo("Bye~~")
结果不报错也没有提示语
快疯了!!!这要还是没有加其他功能,光走一走怎么老是卡!!能不能跟我仔细讲讲到底哪里的问题!谢谢!!!