``````# -*- coding: UTF-8 -*-
#!/usr/bin/env python

#前进1m，画边长（ 0.6 ）m的五边形
import rospy
from geometry_msgs.msg import Twist
from math import radians

import trying

class ROUTE():
count = 0
num = 0
def __init__(self):
# 初始化节点
rospy.init_node('route', anonymous=True)

# 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.2

#旋转18 deg/s
turn_cmd = Twist()
turn_cmd.linear.x = 0

# 前进1M
for x in range(0,25):
self.cmd_vel.publish(move_cmd)
r.sleep()
while not rospy.is_shutdown():
#来拍照啊
for x in range(0,15):
trying.TakePhoto( num )
num = num + 1
r.sleep()

#转54度
for x in range(0,15):
self.cmd_vel.publish(turn_cmd)
r.sleep()
# 前进0.5M
for x in range(0,15):
self.cmd_vel.publish(move_cmd)
r.sleep()
# 转234度
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):
if( num > 7):

def shutdown(self):
# 停啦
self.cmd_vel.publish(Twist())
rospy.sleep(1)

if __name__ == '__main__':
try:
ROUTE()

except:

rospy.sleep(1)

``````

``````# -*- coding: UTF-8 -*-
#!/usr/bin/env python

from __future__ import print_function
import sys
import rospy
import cv2
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError

class TakePhoto ( num ):
def __init__(self):

self.bridge = CvBridge()

# Connect image topic
img_topic = "/camera/rgb/image_raw"
self.image_sub = rospy.Subscriber(img_topic, Image, self.callback)

# Allow up to one second to connection
rospy.sleep(1)

def callback(self, data):

# Convert image to OpenCV format
try:
cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
except CvBridgeError as e:
print(e)

self.image = cv_image

def take_picture(self, img_title):
# Save an image
cv2.imwrite(img_title, self.image)
return True
else:
return False

# Initialize
rospy.init_node('take_photo', anonymous=False)
camera = TakePhoto()

# Take a photo

# Use '_image_title' parameter from command line
# Default value is 'photo.jpg'
img_title = rospy.get_param('~image_title', num+'.jpg')

if camera.take_picture(img_title):
rospy.loginfo("保存啦 " + img_title)
else:

# Sleep to give the last log messages time to be sent
rospy.sleep(1)

``````

Traceback (most recent call last):
File "route.py", line 10, in
import trying
File "/home/hazel/helloworld/turtlebot/trying.py", line 13, in
class TakePhoto ( num ):
NameError: name 'num' is not defined

2个回答

class TakePhoto ( num ) 这是便是TakePhoto类继承num累啊，

class TakePhoto ( ）:
def init(self,num):